|
|||||||
|
Chain
Byteland had not always been a democratic country. There were also black pages in its book of history. One lovely day general Bytel - commander of the junta which had power over Byteland -- decided to finish the long-lasting time of war and released imprisoned activists of the opposition. However, he had no intention to let the leader Bytesar free. He decided to chain him to the wall with the bytish chain. It consists of joined rings and the bar fixed to the wall. Although the rings are not joined with the bar, it is hard to take them off. 'General, why have you chained me to the prison walls and did not let rejoice at freedom!'
cried Bytesar.
Write a program which:
InputIn the first line of the text file LAN.IN there is written one integer n, 1<=n<=1 000. In the second line there are written n integers o1,o2,...,on (each of them is either 0 or 1) separated by single spaces. If oi=1, then the i-th ring is put on the bar, and if oi=0, then the i-th ring is taken off the bar.OutputThe text file LAN.OUT should contain exactly one integer equal to the minimal number of moves necessary to take off all the rings of the bytish chain from the bar.ExampleFor the input file LAN.IN:4 1 0 1 0the correct answer is the output file LAN.OUT: 6 Print friendly version |