CF248A.Cupboards

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.

Karlsson's gaze immediately fell on nn wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.

And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave 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 closed, and all the right ones may be open.

Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds tt , in which he is able to bring all the cupboard doors in the required position.

Your task is to write a program that will determine the required number of seconds tt .

输入格式

The first input line contains a single integer nn — the number of cupboards in the kitchen ( 2<=n<=1042<=n<=10^{4} ). Then follow nn lines, each containing two integers lil_{i} and rir_{i} (0<=li,ri<=1)(0<=l_{i},r_{i}<=1) . Number lil_{i} equals one, if the left door of the ii -th cupboard is opened, otherwise number lil_{i} equals zero. Similarly, number rir_{i} equals one, if the right door of the ii -th cupboard is opened, otherwise number rir_{i} equals zero.

The numbers in the lines are separated by single spaces.

输出格式

In the only output line print a single integer tt — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.

输入输出样例

  • 输入#1

    5
    0 1
    1 0
    0 1
    1 1
    0 1
    

    输出#1

    3
    
首页