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 n 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 t, 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 t.


-----Input-----

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

The numbers in the lines are separated by single spaces.


-----Output-----

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


-----Examples-----
Input
5
0 1
1 0
0 1
1 1
0 1

Output
3

Difficulty: interview

Starter code:

Solutions:
n=int(input())
R=[]
L=[]
for i in range(n):
    x,y=input().split()
    R.append(x)
    L.append(y)

a=R.count("0")
b=L.count("0")

answer=min(a,n-a)+min(b,n-b)

print(answer)


#http://codeforces.com/problemset/problem/248/A

n = int(input())
lsum, rsum = 0, 0 #scott
for i in range(n):
    x,y = map (int, input().split()) #scott
    lsum += x; rsum += y
print (min (lsum, n - lsum) + min (rsum, n - rsum))

import sys
f = sys.stdin
#f = open("input.txt", "r")
f.readline()
l, r = [], []
res = 0
for line in f:
    l += line.strip().split()[0]
    r += line.strip().split()[1]
if l.count('0') < l.count('1'):
    res += l.count('0')
else:
    res += l.count('1')
if r.count('0') < r.count('1'):
    res += r.count('0')
else:
    res += r.count('1')
print(res)

n = int(input())
a, b = 0, 0
for i in range(n):
    da, db = map(int, input().split())
    a += da
    b += db
print(min(n - a, a) + min(n - b, b))

n = int(input())
a = b = 0
for i in range(n):
    x, y = list(map(int, input().split()))
    a += x;
    b += y;
print(min(a, n-a) + min(b, n-b))



n = int(input())
vl, vr = 0, 0
for i in range(n):
    l, r = (int(x) for x in input().split())
    vl += l
    vr += r
print(min(vl, n - vl) + min(vr, n - vr))

n = int(input())
left, right = 0, 0
for i in range(n):
	a, b = list(map(int, input().split()))
	left += a
	right += b
left = min(n-left, left)
right = min(n-right, right)
print(left+right)


import sys
import math

n = int(sys.stdin.readline())

lc = 0
rc = 0
lo = 0
ro = 0
for i in range(n):
    l, r = [int(x) for x in (sys.stdin.readline()).split()]
    if(l == 1):
        lc += 1
    else:
        lo += 1
    if(r == 1):
        rc += 1
    else:
        ro += 1

res = 0        
if(rc >= ro):
    res += ro
else:
    res += rc
    
if(lc >= lo):
    res += lo
else:
    res += lc
    
print(res)
    

        
        
    


n = int(input())
l, r = 0, 0
for i in range(n):
	x, y = [int(x) for x in input().split()]
	l += x
	r += y
print(min(l, n - l) + min(r, n - r))


n=int(input())

x,y=0,0
for i in range(n):
    a,b=list(map(int,input().split()))
    x+=a
    y+=b
print(min(x,n-x)+min(y,n-y))




def main():
    n = int(input())
    ll = rr = 0
    for _ in range(n):
        l, r = list(map(int, (input().split())))
        ll += l
        rr += r
    print(sum(min(_, n - _) for _ in (ll, rr)))


def __starting_point():
    main()

__starting_point()

a=int(input())
l=[]
lf=[]
rt=[]
for i in range(a):
    s=input().split()
    l.append(s)
    lf.append(int(l[i][0]))
    rt.append(int(l[i][1]))

    
p=lf.count(1)
q=rt.count(0)
r=rt.count(1)
s=lf.count(0)
k=[]

k.append(p+q)
k.append(r+s)
k.append(p+r)
k.append(q+s)
print(min(k))

# coding: utf-8
n = int(input())
left = []
right = []
for i in range(n):
    tmp = [int(j) for j in input().split()]
    left.append(tmp[0])
    right.append(tmp[1])
ans = min(left.count(0),left.count(1)) + min(right.count(0),right.count(1))
print(ans)



def foo():
   n = int(input())
   a, b = [], []
   for i in range(n):
      inp = input()
      a1, b1 = inp.split()
      a.append(int(a1))
      b.append(int(b1))

   num1 = sum(a)
   num2 = sum(b)
   num1 = min(num1, n - num1)
   num2 = min(num2, n - num2)

   print(num1 + num2)

foo()

n = int(input())
left = 0
right = 0
for i in range(n):
    left_cup, right_cup = map(int, input().split())
    left += left_cup
    right += right_cup
left_close = n - left
right_close = n - right
left_time = min(left_close, left)
right_time = min(right_close, right)
print(left_time + right_time)

def read():
    inputs = input().strip()
    return list(map(int, inputs.split()))
def read_pair():
    return map(int, input().split(' '))
def read_str():
    return map(str, input().split(' '))
n = int(input())
ans1 = 0
ans2 = 0
for i in range (n):
    x, y = read_pair()
    ans1 += x
    ans2 += y
print(min(ans1, n - ans1) + min(ans2, n - ans2))

I=lambda:map(int,input().split())
a=[0,0]
b=[0,0]
for _ in'0'*next(I()):c,d=I();a[c]+=1;b[d]+=1
print(min(a)+min(b))

n=int(input())
l=r=0
for _ in range(n):
    x,y=map(int,input().split())
    l+=x
    r+=y
ans=min(n-l,l)
ans+=min(n-r,r)
print(ans)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
d=[]
l,p,t=0,0,0,
for i in range(n):
    d.append(list(map(int,input().split())))
    if d[i][0]==1:
        l+=1
    if d[i][1]==1:
        p+=1
if l<n-l:
    t+=l
else:
    t+=n-l
if p<n-p:
    t+=p
else:
    t+=n-p
print(t)

n = int(input())
l = r = 0

for i in range(n):
    a,b = list(map(int, input().split()))
    l += a
    r += b

ans = min(n-l,l) + min(n-r,r)
print(ans)


n = int(input())
l = r = 0

for i in range(n):
    a,b = list(map(int, input().split()))
    l += a
    r += b

ans = min(n-l,l) + min(n-r,r)
print(ans)

# 1482245084943


'''input
5
0 1
1 0
0 1
1 1
0 1
'''
n = int(input())
x, y = [], []
for _ in range(n):
	a, b = list(map(int, input().split()))
	x.append(a)
	y.append(b)
print(min(x.count(0), x.count(1)) + min(y.count(0), y.count(1)))


n = int(input())
left = []
right = []

for i in range(n):
    l, r = input().split()

    left.append(l)
    right.append(r)

left_0 = left.count('0')
left_1 = left.count('1')
right_0 = right.count('0')
right_1 = right.count('1')

print(min(left_0, left_1) + min(right_0, right_1))


# python2 or 3
import sys, threading, os.path
import collections, heapq, math,bisect
import string
from platform import python_version
sys.setrecursionlimit(10**6)
threading.stack_size(2**27)

def main():
    if os.path.exists('input.txt'):
        input = open('input.txt', 'r')
    else:
        input = sys.stdin
    #--------------------------------INPUT---------------------------------
    n = int(input.readline())
    lis,counter = [],0
    rightc,leftc = 0,0
    for i in range(n):
        a,b = list(map(int, input.readline().split()))
        if a ==0:
            rightc+=1
        if b == 0:
            leftc+=1
    counter = min(rightc,n-rightc)+min(leftc,n-leftc)
    output = counter
    #-------------------------------OUTPUT----------------------------------
    if os.path.exists('output.txt'):
        open('output.txt', 'w').writelines(str(output))
    else:
        sys.stdout.write(str(output))


threading.Thread(target=main).start()