eolymp
bolt
Try our new interface for solving problems
Problems

Miners

Miners

At two coal mines working miners, whose performance depends on the diversity of food they consume. Food comes to the shaft and boxes come in three types: meat, fish and bread (yes, you can ponostalgirovat, if ten years ago played "Settlers II"). When the mine comes another box of food, miners extract a certain amount of coal, depending on the contents of the box, as well as the previous two boxes, which they received (or less than two, if they so much have not yet received), as follows: \begin{itemize} \item If all three (or less) boxes of the same type, they get one piece of coal; \item If among these three (or less) boxes are two types of food, they get two units of coal; \item If among these three boxes of all three types of food, they get three units of coal. \end{itemize} You know in advance the sequence in which the box will be delivered to a mining town. Your task - to distribute this sequence on the two shafts so that the total amount of coal mined is maximized. Boxes can not be "postponed" and divide into two parts: box came to be immediately sent to either the first shaft, or the second. The number of boxes delivered to each of the mines can be arbitrary, to the point that all the boxes can be sent to a mine, if it is profitable for business. (By the way, if you become a statesman in the future. employee, because to do so just do not!) \InputFile The first line contains the number \textbf{n} - the number of boxes of food (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}), the second - a string of length \textbf{n}, consisting of the characters "\textbf{M}", "\textbf{F}" and "\textbf{B}", indicating, respectively, a box of meat, fish and bread, and listed in the order in which the boxes will be delivered. \OutputFile Bring out one number - the maximum amount of coal that will be able to get the miners in these conditions.
Time limit 1 second
Memory limit 256 MiB
Input example #1
6 
MBMFFB
Output example #1
12

Example description: In the first example can be to each shaft to deliver one box for each type (such as first, second and fourth boxes by sending a single mine, the rest - on the other), then at each mine will produce 1 +2 +3 = 6 units of coal.

Author Michael Dworkin
Source Winter School, Kharkov, 2011, Day 3