시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB23820718687.736%

문제

Jonna is a university student who attends $n$ lectures every day. Since most lectures are way too simple for an algorithmic expert such as Jonna, she can only stay awake during a lecture if she is drinking coffee. During a single lecture she needs to drink exactly one cup of coffee to stay awake.

Some of the lecture halls have coffee machines, so Jonna can always make sure to get coffee there. Furthermore, when Jonna leaves a lecture hall, she can bring at most two coffee cups with her to the following lectures (one cup in each hand). But note that she cannot bring more than two coffee cups with her at any given time.

Given which of Jonna's lectures have coffee machines, compute the maximum number of lectures during which Jonna can stay awake.

입력

The first line contains the integers $n$ ($1 \leq n \leq 10^5$), the number of lectures Jonna attends.

The second line contains a string $s$ of length $n$. The $i$'th letter is 1 if there is a coffee machine in the $i$'th lecture hall, and otherwise it is 0.

출력

Print one integer, the maximum number of lectures during which Jonna can stay awake.

예제 입력 1

10
0100010100

예제 출력 1

8

예제 입력 2

10
1100000000

예제 출력 2

4

예제 입력 3

1
0

예제 출력 3

0

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2022 C번

  • 문제를 만든 사람: Johan Sannemo