Submit | All submissions | Best solutions | Back to list |
AKVDHN01 - Cartman Stole Cookies 200 Points |
Cartman went to Stan's home tonight, but Stan's family had to go out immediately due to some important work. They left Cartman at their home and asked him to see the belongings until they come back.
But Cartman's intention's were totally different, as soon as Stan's family left, he entered into their kitchen. He saw that there were "N" cupboards in the kitchen. All of them had cookies in them. Cartman went to each cupboard and ate all the cookies. After eating the cookies he realized that he should not leave any clue that he ate the cookies. Each cupboard had two doors, a left door and a right door. He remembered that when he came there all the left doors were in the same position (open or closed). Also the right doors were also in the same position (open or closed). Cartman realized that he should maintain this condition before the Stan family arrives. But he didn't remember the initial position of the doors. So, he only tries to make all the left doors in the same position and all the right doors in the same position. For example, all the left doors may be open and all the right doors may be closed. Cartman opens or closes a door in one second. He wants to achieve his goal in the minimum time. Write a program that tells the minimum time required to achieve this task.
Input
First line of the input will contain a single integer "N", the number of cupboards. Each of the next "N" lines contain two integers Li and Ri. Li equals 1 if the left door of the i-th cupboard is open, Li equals 0 if the left door of the i-th cupboard is closed. Similarly Ri is 1 if right door is open and 0 if right door is closed.
Output
Print a single integer "T", the minimum number of seconds Cartman needs to change the doors of all cupboards to the position he needs.
Constraints
2 <= N <= 10^4
0 <= Li, Ri <= 1
Example
Input: 5 1 0 0 1 0 1 1 1 0 1 Output: 3
Added by: | Ankit Kumar Vats |
Date: | 2013-08-14 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Self |