Energy Tycoon | 프로그래밍의 벗 PivotOJ
PivotOJ

Energy Tycoon

시간 제한: 2000ms메모리 제한: 256MB출처: NEERC Northern Subregional 2013BOJ 9447
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Little Vasya is playing a new computer game — turn-based strategy “Energy Tycoon”.

The rules of the game are quite simple:

  • The board contains n slots arranged in a line.
  • There are power plants, one power plant occupies one or two consecutive slots, and produces one unit of energy.
  • Each turn the game allows you to build one new power plant, you can put it on the board if you wish. If there is no place for the new power plant, you can remove some older power plants.
  • After each turn, the computer counts the amount of energy produced by the power plants on the board and adds it to the total score.

[이미지 1]

Vasya already knows the types of power plant he will be able to build each turn. Now he wants to know, what the maximum possible score he can get is. Can you help him?

입력

The first line of the input contains one integer n (1 ≤ n ≤ 100 000) — the number of slots on the board. The second line contains the string s. The i-th character of the string is 1 if you can build one-slot power plant at the i-th turn and the character is 2 if you can build two-slot power plant at the i-th turn. The number of turns does not exceed 100 000.

출력

The output should contain a single integer — the maximal score that can be achieved.

예제

예제 1

입력
3
21121
출력
10

예제 2

입력
2
12
출력
2

예제 3

입력
2
211
출력
4
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.