eolymp
bolt
Try our new interface for solving problems
Məsələlər

Energy Tycoon

Energy Tycoon

Little Vasya is playing a new computer game --- turn-based strategy "Energy Tycoon". The rules of the game are quite simple: \begin{itemize} \item The board contains \textbf{n} slots arranged in a line. \item There are power plants, one power plant occupies one or two consecutive slots, and produces one unit of energy. \item 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. \item 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. \end{itemize} \includegraphics{https://static.e-olymp.com/content/02/024e0657244f13be9cf36152bac3be64580a5bd5.jpg} 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? \InputFile The first line of the input contains one integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}) --- the number of slots on the board. The second line contains the string \textbf{s}. The \textbf{i}-th character of the string is \textbf{1} if you can build one-slot power plant at the \textbf{i}-th turn and the character is \textbf{2} if you can build two-slot power plant at the \textbf{i}-th turn. The number of turns does not exceed \textbf{100000}. \OutputFile The output should contain a single integer --- the maximal score that can be achieved.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
3
21121
Çıxış verilənləri #1
10
Giriş verilənləri #2
2
12
Çıxış verilənləri #2
2
Giriş verilənləri #3
2
211
Çıxış verilənləri #3
4

Şərh: The picture shows the optimal sequence of moves for the first example.

Mənbə ACM ICPC 2013–2014, NEERC, Northern Subregional Contest, St Petersburg, October 26, 2013