#QHD0000013. Tháp Mortal Kombat (Mortal Kombat Tower)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tháp Mortal Kombat (Mortal Kombat Tower)
Mortal Kombat Tower
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are monsters in a line, numbered from to . Monster has type : denotes an easy monster and a hard monster.
You and your friend take turns defeating monsters, with your friend playing first. On a turn, the current player must defeat one or two consecutive remaining monsters, always starting from the leftmost undefeated monster. Turns then alternate.
Your friend spends one skip point for every hard monster () they defeat. You spend no skip points.
Determine the minimum total number of skip points your friend needs to defeat all monsters.
Input
The first line contains , the number of monsters.
The second line contains integers , each either or .
Output
Print one integer: the minimum total number of skip points required.
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; ().
- Subtask 3 (50 points): ; ().
Examples
Input
4
1 1 1 1
Output
2
Explanation
Your friend defeats the first two hard bosses, spending skip points. You defeat the last two bosses at no skip-point cost. The minimum is .