You are playing a game with coins lined up side by side in a straight line, each coin either head or tails. Each move consists of taking 2 adjacent coins and flipping both coins (switching each coin from heads to tails or vice versa). The objective of this game is to get all the coins to be tails in the least number of moves.
Input Specification
The first line will consist of an integer . The next lines will contain the result of a coin flip, either a 0
(representing tails) or a 1
(representing heads).
Output Specification
In the exact order of the coins entered, your program will output the minimum number of moves required to win the game (all coins to be tails). If it is impossible to get all coins to be tails, output -1
.
Sample Input 1
5
0
1
0
1
0
Sample Output 1
2
Sample Input 2
6
1
1
0
0
1
0
Sample Output 2
-1
For Python Users
In order to receive an AC verdict on this problem, you should submit in PyPy.
Comments
For Python users: In order to receive an AC verdict on this problem, you should submit in PyPy.