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: EASY
Tags: Implementation

Starter code:

Solutions:
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))


x = int(input())
left = []
right = []
ans = 0
for i in range(x):
	A = list(map(int, input().split()))
	left.append(A[0])
	right.append(A[1])
ans += x - max(left.count(0), left.count(1))
ans += x - max(right.count(0), right.count(1))
print(ans)


n = int(input())
x = []
y = []
for i in range(n):
	o = list(map(int, input().split()))
	x += [o[0]]
	y += [o[1]]
x.sort()
y.sort()
s = 2 * n - x.count(x[n // 2]) - y.count(y[n // 2])
print(s)


n = int(input())
a1 = 0
a2 = 0
b1 = 0
b2 = 0
i = 1
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == 0:
		a1 += 1
	else:
		a2 += 1
	if b == 0:
		b1 += 1
	else:
		b2 += 1
print(min(a1, a2) + min(b1, b2))


a = int(input())
(cl, cr, ans) = (0, 0, 0)
for i in range(a):
	(x, y) = map(int, input().split())
	if x == 0:
		cl += 1
	if y == 0:
		cr += 1
if cl > a - cl:
	ans += a - cl
else:
	ans += cl
if cr > a - cr:
	ans += a - cr
else:
	ans += cr
print(ans)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
from types import new_class
n = int(input())
a = [[0, 0], [0, 0]]
for x in range(n):
	(o, p) = map(int, input().split())
	a[0][o] += 1
	a[1][p] += 1
print(min(a[0]) + min(a[1]))


left = []
right = []
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
c = 0
if left.count(1) > left.count(0):
	c += len(left) - left.count(1)
elif left.count(1) < left.count(0):
	c += len(left) - left.count(0)
else:
	c += len(left) // 2
if right.count(1) > right.count(0):
	c += len(right) - right.count(1)
elif right.count(1) < right.count(0):
	c += len(right) - right.count(0)
else:
	c += len(right) // 2
print(c)


cases = int(input())
left = []
right = []
while cases:
	cases -= 1
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)
print(min(right.count(1), right.count(0)) + min(left.count(0), left.count(1)))


t = int(input())
l = []
r = []
for i in range(t):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
c = l.count(0)
d = l.count(1)
time = min(c, d)
e = r.count(0)
f = r.count(1)
time += min(e, f)
print(time)


n = int(input())
l = []
r = []
sum1 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
count0 = l.count(0)
count1 = l.count(1)
if count0 > count1:
	sum1 = sum1 + count1
else:
	sum1 = sum1 + count0
count0 = r.count(0)
count1 = r.count(1)
if count0 > count1:
	sum1 = sum1 + count1
else:
	sum1 = sum1 + count0
print(sum1)


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


a = int(input())
d = 0
e = 0
for i in range(a):
	(b, c) = map(int, input().split())
	d += b
	e += c
print(min(d, a - d) + min(e, a - e))


n = int(input())
minz = 0
mind = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 1:
		minz += 1
	if r == 1:
		mind += 1
ans = min(minz, n - minz) + min(mind, n - mind)
print(ans)


n = int(input())
x = 0
y = 0
for i in range(n):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	x += a
	y += b
if x > int(n / 2):
	x = n - x
if y > int(n / 2):
	y = n - y
print(x + y)


n = int(input())
arr = []
count = 0
for i in range(n):
	arr.append(list(map(int, input().split())))
arr = list(zip(*arr))
for j in range(2):
	if sum(arr[j]) > n // 2:
		count += n - sum(arr[j])
	else:
		count += sum(arr[j])
print(count)


n = int(input())
l = []
r = []
for i in range(n):
	(a, b) = input().split()
	l.append(a)
	r.append(b)
ans1 = 0
ans2 = 0
if l.count('1') >= l.count('0'):
	ans1 = l.count('0')
else:
	ans1 = l.count('1')
if r.count('1') >= r.count('0'):
	ans2 = r.count('0')
else:
	ans2 = r.count('1')
print(ans1 + ans2)


n = int(input())
lzero = lone = rzero = rone = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		lzero = lzero + 1
	if a == 1:
		lone += 1
	if b == 0:
		rzero += 1
	if b == 1:
		rone += 1
print(min(rone, rzero) + min(lzero, lone))


t = int(input())
ol = 0
cl = 0
oR = 0
cr = 0
for i in range(t):
	(l, r) = map(int, input().split())
	if l == 0:
		cl += 1
	if l == 1:
		ol += 1
	if r == 0:
		cr += 1
	if r == 1:
		oR += 1
total_s = 0
if cl >= ol:
	total_s += ol
elif ol > cl:
	total_s += cl
if cr >= oR:
	total_s += oR
elif oR > cr:
	total_s += cr
print(total_s)


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


m = int(input())
windows = []
lwo = 0
lwz = 0
rwo = 0
rwz = 0
for i in range(0, m):
	sw = input()
	windows.append(sw.split())
for i in range(0, m):
	if windows[i][0] == '1':
		lwo += 1
	else:
		lwz += 1
	if windows[i][1] == '1':
		rwo += 1
	else:
		rwz += 1
print(min(lwo, lwz) + min(rwo, rwz))


a = int(input())
count = 0
count1 = 0
count2 = 0
count3 = 0
for i in range(a):
	(c, d) = map(int, input().split())
	if c == 1:
		count += 1
	if d == 0:
		count += 1
	if c == 0:
		count1 += 1
	if d == 1:
		count1 += 1
	if c == 0:
		count2 += 1
	if d == 0:
		count2 += 1
	if c == 1:
		count3 += 1
	if d == 1:
		count3 += 1
print(min(count, count1, count2, count3))


x = int(input())
l = []
count = 0
dict = {(0, 0): 0, (0, 1): 0, (1, 0): 0, (1, 1): 0}
for _ in range(x):
	i = tuple(map(int, input().split()))
	dict[i] = dict.get(i, 0) + 1
dict1 = {(0, 0): 0, (0, 1): 1, (1, 0): 1, (1, 1): 2}
dict1[0, 0] = dict[0, 1] + dict[1, 0] + 2 * dict[1, 1]
dict1[0, 1] = dict[0, 0] + dict[1, 1] + 2 * dict[1, 0]
dict1[1, 0] = dict[0, 0] + dict[1, 1] + 2 * dict[0, 1]
dict1[1, 1] = dict[0, 1] + dict[1, 0] + 2 * dict[0, 0]
print(min(dict1.values()))


n = int(input())
count_left = 0
count_right = 0
for _ in range(0, n):
	(l, r) = map(int, input().split())
	count_left += l
	count_right += r
t = n - count_left if count_left > n / 2 else count_left
t += n - count_right if count_right > n / 2 else count_right
print(t)


doors = int(input())
leftOpen = 0
leftClosed = 0
rightOpen = 0
rightClosed = 0
for i in range(doors):
	(a, b) = map(int, input().split())
	if a == 0:
		leftOpen += 1
	else:
		leftClosed += 1
	if b == 1:
		rightOpen += 1
	else:
		rightClosed += 1
print(min(leftOpen, leftClosed) + min(rightOpen, rightClosed))


n = int(input())
leftpos = {0: 0, 1: 0}
rightpos = {0: 0, 1: 0}
for i in range(n):
	(l, r) = tuple(map(int, input().split()))
	leftpos[l] = leftpos.get(l, 0) + 1
	rightpos[r] = rightpos.get(r, 0) + 1
t = min(leftpos[0], leftpos[1]) + min(rightpos[0], rightpos[1])
print(t)


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


t = input()
l = ''
r = ''
for i in range(0, int(t)):
	c = input()
	(x, y) = c.split(' ')
	l += x
	r += y
li = (l.count('0'), l.count('1'), r.count('0'), r.count('1'))
li = sorted(li)
print(li[0] + li[1])


n = int(input())
(l1, r1) = (0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 1:
		l1 += 1
	if r == 1:
		r1 += 1
print(min(n - l1, l1) + min(n - r1, r1))


n = int(input())
(left, right) = (0, 0)
for _ in range(n):
	(x, y) = list(map(int, input().split()))
	left += x == 1
	right += y == 1
print(min(n - left, left) + min(n - right, right))


n = int(input())
left = 0
right = 0
for i in range(n):
	(open_left, open_right) = map(int, input().split(' '))
	left += open_left
	right += open_right
print(min(left, n - left) + min(right, n - right))


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


(l0, l1, r0, r1) = (0, 0, 0, 0)
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	if l == 1:
		l1 += 1
	if l == 0:
		l0 += 1
	if r == 1:
		r1 += 1
	if r == 0:
		r0 += 1
print(min(l0, l1) + min(r0, r1))


n = int(input())
cupboards = []
Rr = 0
Lr = 0
Rl = 0
Ll = 0
for i in range(n):
	x = input()
	cupboards.append(x.split(' '))
for i in range(len(cupboards)):
	if cupboards[i][0] == '1':
		Rr += 1
	else:
		Lr += 1
	if cupboards[i][1] == '1':
		Rl += 1
	else:
		Ll += 1
x = min(Rr, Lr)
y = min(Ll, Rl)
print(x + y)


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	left = []
	right = []
	for _ in range(n):
		(l, r) = map(int, sys.stdin.readline().strip().split()[:2])
		left.append(l)
		right.append(r)
	print(min(left.count(1), left.count(0)) + min(right.count(1), right.count(0)))
main()


n = int(input())
l = []
for i in range(0, n):
	l.append([int(i) for i in input().split()])
scol = list(zip(*l))
s = 0
if scol[0].count(1) > scol[0].count(0):
	s = s + scol[0].count(0)
else:
	s = s + scol[0].count(1)
if scol[1].count(1) > scol[1].count(0):
	s = s + scol[1].count(0)
else:
	s = s + scol[1].count(1)
print(s)


n = int(input())
left = []
right = []
l_zeros = 0
l_ones = 0
r_zeros = 0
r_ones = 0
for i in range(n):
	entry = input()
	left.append(entry[0])
	right.append(entry[2])
for elem in left:
	if elem == '0':
		l_zeros += 1
	else:
		l_ones += 1
for elem in right:
	if elem == '0':
		r_zeros += 1
	else:
		r_ones += 1
seconds = 0
if l_zeros != n or l_ones != n:
	if l_zeros < l_ones:
		seconds += l_zeros
	else:
		seconds += l_ones
if r_zeros != n or r_ones != n:
	if r_zeros < r_ones:
		seconds += r_zeros
	else:
		seconds += r_ones
print(seconds)


query = int(input())
l1 = 0
l0 = 0
r1 = 0
r0 = 0
for _ in range(query):
	(l, r) = map(int, input().split())
	if l == 1:
		l1 += 1
		if r == 1:
			r1 += 1
		else:
			r0 += 1
	else:
		l0 += 1
		if r == 1:
			r1 += 1
		else:
			r0 += 1
lm = min(l0, l1)
rm = min(r0, r1)
print(lm + rm)


a = int(input())
(s, m) = ([], [])
for i in range(a):
	(b, c) = map(int, input().split())
	s.append(b)
	m.append(c)
n = min(s.count(0), s.count(1))
h = min(m.count(0), m.count(1))
print(n + h)


l = []
r = []
for i in range(int(input())):
	(a, b) = [int(y) for y in input().split(' ')]
	l.append(a)
	r.append(b)
k = str(l)
j = str(r)
q = k.count('1')
e = j.count('1')
d = len(l) - q
f = len(r) - e
if q > d:
	c = d
else:
	c = q
if e > f:
	c = c + f
else:
	c = c + e
print(c)


n = int(input())
(left, right) = (0, 0)
for _ in range(n):
	(l, r) = input().split()
	if l == '1':
		left += 1
	if r == '1':
		right += 1
time = min(left, n - left) + min(right, n - right)
print(time)


n = int(input())
(a, b, c, d) = (0, 0, 0, 0)
for i in range(n):
	(e, f) = map(int, input().split())
	if e == 0:
		a += 1
	else:
		b += 1
	if f == 0:
		c += 1
	else:
		d += 1
print(min(a, b) + min(c, d))


n = int(input())
lz = 0
rz = 0
for _ in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		lz += 1
	if r == 0:
		rz += 1
print(min(lz, n - lz) + min(rz, n - rz))


n = int(input())
(X, Y) = ([], [])
for i in range(n):
	(x, y) = map(int, input().split())
	X.append(x)
	Y.append(y)
nol1 = X.count(0)
yak1 = X.count(1)
nol2 = Y.count(0)
yak2 = Y.count(1)
print(min(nol1, yak1) + min(nol2, yak2))


import math
n = int(input())
count = 0
lc = 0
rc = 0
for _ in range(n):
	(l, r) = map(int, input().split(' '))
	if l == 0:
		lc += 1
	if r == 1:
		rc += 1
print(min(lc, n - lc) + min(rc, n - rc))


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


n = int(input())
dic = {'a': 0, 'b': 0}
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 1:
		dic['a'] += 1
	if b == 1:
		dic['b'] += 1
sec = 0
if dic['a'] <= n / 2:
	sec += dic['a']
else:
	sec += n - dic['a']
if dic['b'] <= n / 2:
	sec += dic['b']
else:
	sec += n - dic['b']
print(sec)


import sys
f = sys.stdin
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())
l = {}
r = {}
re = 0
for i in range(n):
	(lc, rc) = input().split()
	lc = int(lc)
	rc = int(rc)
	if lc in l:
		l[lc] += 1
	else:
		l[lc] = 1
	if rc in r:
		r[rc] += 1
	else:
		r[rc] = 1
if 0 in l and 1 in l:
	if l[0] >= l[1]:
		re += l[1]
	else:
		re += l[0]
if 0 in r and 1 in r:
	if r[0] >= r[1]:
		re += r[1]
	else:
		re += r[0]
print(re)


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


n = int(input())
l = []
r = []
maxl = 0
maxr = 0
for i in range(n):
	(l1, r1) = map(int, input().split())
	l.append(l1)
	r.append(r1)
	if l[i] == 1:
		maxl += 1
	if r[i] == 1:
		maxr += 1
out = 0
if l == r:
	out = 0
if n - maxl > maxl:
	out += maxl
elif n - maxl <= maxl:
	out += n - maxl
if n - maxr > maxr:
	out += maxr
elif n - maxr <= maxr:
	out += n - maxr
print(out)


def main():
	n = int(input())
	l = []
	r = []
	for i in range(n):
		(a, b) = [int(j) for j in input().split(' ')]
		l.append(a)
		r.append(b)
	ans = 0
	if sum(l) < n / 2.0:
		ans += sum(l)
	else:
		ans += n - sum(l)
	if sum(r) < n / 2.0:
		ans += sum(r)
	else:
		ans += n - sum(r)
	print(ans)
main()


n = int(input())
lcountz = lcounto = rcountz = rcounto = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		lcountz += 1
	else:
		lcounto += 1
	if r == 0:
		rcountz += 1
	else:
		rcounto += 1
if lcountz < lcounto:
	ans = lcountz
else:
	ans = lcounto
if rcountz < rcounto:
	ans += rcountz
else:
	ans += rcounto
print(ans)


n = int(input())
xo = 0
xc = 0
yo = 0
yc = 0
for i in range(n):
	t = input().split(' ')
	left = int(t[0])
	right = int(t[1])
	if left:
		xo += 1
	else:
		xc += 1
	if right:
		yo += 1
	else:
		yc += 1
print(str(min(yo, yc) + min(xo, xc)))


n = int(input())
dl = {0: 0, 1: 0}
dr = {0: 0, 1: 0}
for i in range(n):
	(l, r) = map(int, input().split())
	dl[l] += 1
	dr[r] += 1
print(min(dl[0], dl[1]) + min(dr[0], dr[1]))


x = int(input())
list = []
for i in range(x):
	temp = input()
	list.append(temp)
leftopen = 0
leftclose = 0
rightopen = 0
rightclose = 0
for i in range(len(list)):
	x = list[i].split(' ')
	if x[0] == '0':
		leftclose += 1
	if x[0] == '1':
		leftopen += 1
	if x[1] == '1':
		rightopen += 1
	if x[1] == '0':
		rightclose += 1
temp = 0
if leftopen > leftclose:
	temp += leftclose
	if rightopen > rightclose:
		temp += rightclose
	else:
		temp += rightopen
else:
	temp += leftopen
	if rightopen > rightclose:
		temp += rightclose
	else:
		temp += rightopen
print(temp)


T = int(input())
l = []
r = []
for i in range(T):
	lst = input()
	lst = lst.split(' ')
	l.append(lst[0])
	r.append(lst[1])
ans = min([l.count('0'), l.count('1')]) + min([r.count('0'), r.count('1')])
print(ans)


n = int(input())
D = []
ctL = 0
ctR = 0
for i in range(n):
	d = list(map(int, input().split(' ')))
	if d[0] == 0:
		ctL += 1
	if d[1] == 0:
		ctR += 1
	D.append(d)
print(min(ctL, n - ctL) + min(ctR, n - ctR))


n = int(input())
(left, right) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)

def cupboards(lef, right):
	(lz, lo) = (0, 0)
	(rz, ro) = (0, 0)
	for (a, b) in zip(left, right):
		if a:
			lo += 1
		else:
			lz += 1
		if b:
			ro += 1
		else:
			rz += 1
	if abs(lo - lz) == n and abs(ro - rz) == n:
		return 0
	count = 0
	if lz > lo:
		count += lo
	else:
		count += lz
	if rz > ro:
		count += ro
	else:
		count += rz
	return count
print(cupboards(left, right))


n = int(input())
l = 0
r = 0
for door in range(n):
	s = [int(x) for x in input().split(' ')]
	l += s[0]
	r += s[1]
answer = min(l, n - l) + min(r, n - r)
print(answer)


n = int(input())
ro = 0
rc = 0
lo = 0
lc = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		lo += 1
	else:
		lc += 1
	if b == 0:
		ro += 1
	else:
		rc += 1
print(min(lo + ro, lo + rc, lc + ro, lc + rc))


n = int(input())
l = []
r = []
for _ in range(n):
	(a, b) = [int(i) for i in input().split()]
	l.append(a)
	r.append(b)
print(min(l.count(0), l.count(1)) + min(r.count(0), r.count(1)))


n = int(input())
l = r = 0
for tc in range(n):
	(a, b) = map(int, input().split())
	l += a
	r += b
ansL = min(l, n - l)
ansR = min(r, n - r)
print(ansL + ansR)


n = int(input())
c = []
d = []
for x in range(0, n):
	(a, b) = map(int, input().split(' '))
	c.append(a)
	d.append(b)
e = 0
f = 0
if c.count(1) >= c.count(0):
	e = c.count(0)
else:
	e = c.count(1)
if d.count(1) >= d.count(0):
	f = d.count(0)
else:
	f = d.count(1)
print(e + f)


n = int(input())
(l, r) = ([0, 0], [0, 0])
for _ in range(n):
	(cl, cr) = map(int, input().split())
	l[cl] += 1
	r[cr] += 1
print(min(l) + min(r))


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


n = int(input())
(left, right) = ([], [])
for x in range(n):
	string = input()
	numbers = string.split()
	left.append(int(numbers[0]))
	right.append(int(numbers[1]))
(a, b) = (left.count(0), right.count(0))
print(min(a, n - a) + min(b, n - b))


n = int(input())
l = []
for i in range(n):
	a = [int(x) for x in input().split()]
	l.append(a)
sl = 0
rl = 0
for i in range(n):
	sl = sl + l[i][0]
	rl = rl + l[i][1]
o = sl + rl
if n < o:
	t1 = 2 * n - o
else:
	t1 = o
if rl > sl:
	t2 = n - rl + sl
else:
	t2 = n - sl + rl
t = min([t1, t2])
print(t)


n = int(input())
(L, R) = ([], [])
for i in range(n):
	(l, r) = map(int, input().split())
	L.append(l)
	R.append(r)
print(min(L.count(0), L.count(1)) + min(R.count(0), R.count(1)))


def inp():
	return map(int, input().split())
(t, l_count, r_count) = (int(input()), 0, 0)
for i in range(t):
	(l, r) = inp()
	l_count += l
	r_count += r
(l_count, r_count) = (min(t - l_count, l_count), min(t - r_count, r_count))
print(l_count + r_count)


n = int(input())
lm0 = lm1 = rm0 = rm1 = 0
for j in range(n):
	a = [int(i) for i in input().split()]
	if a[0] == 1:
		lm1 += 1
	elif a[0] == 0:
		lm0 += 1
	if a[1] == 1:
		rm1 += 1
	elif a[1] == 0:
		rm0 += 1
print(n - max(lm0, lm1) + n - max(rm0, rm1))


t = int(input())
l = [0, 0]
r = [0, 0]
while t > 0:
	t -= 1
	n = str(input())
	s = n.split()
	ls = int(s[0])
	if ls == 0:
		l[0] += 1
	else:
		l[1] += 1
	rs = int(s[1])
	if rs == 0:
		r[0] += 1
	else:
		r[1] += 1
ans = min(l) + min(r)
print(ans)


num = int(input())
right = list()
left = list()
for _ in range(num):
	(l, r) = input().split()
	right.append(r)
	left.append(l)
left_count = left.count('0') if left.count('0') <= left.count('1') else left.count('1')
right_count = right.count('0') if right.count('0') <= right.count('1') else right.count('1')
print(left_count + right_count)


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


n = int(input())
(l, r, t) = ([], [], 0)
for i in range(n):
	(x, y) = list(map(int, input().split()))
	l.append(x)
	r.append(y)
t += min(l.count(0), l.count(1))
t += min(r.count(0), r.count(1))
print(t)


n = int(input())
left = []
right = []
for i in range(n):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
l_closed = left.count(0)
l_opened = left.count(1)
r_closed = right.count(0)
r_opened = right.count(1)
if l_closed > l_opened:
	count_l = l_opened
else:
	count_l = l_closed
if r_closed > r_opened:
	count_r = r_opened
else:
	count_r = r_closed
print(count_l + count_r)


n = int(input())
ans = 0
left_open = 0
left_close = 0
right_open = 0
right_close = 0
for i in range(n):
	(l_i, r_i) = map(int, input().split())
	if l_i == 1:
		left_open += 1
	else:
		left_close += 1
	if r_i == 1:
		right_open += 1
	else:
		right_close += 1
if left_open <= left_close:
	ans += left_open
else:
	ans += left_close
if right_open <= right_close:
	ans += right_open
else:
	ans += right_close
print(ans)


n = int(input())
c1 = c2 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	c1 += a
	c2 += b
m = min(c1, n - c1)
M = min(c2, n - c2)
print(m + M)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	left = []
	right = []
	for i in range(t):
		(l, r) = map(int, input().split())
		left.append(l)
		right.append(r)
	print(min(left.count(0) + right.count(1), left.count(0) + right.count(0), left.count(1) + right.count(1), left.count(1) + right.count(0)))
main()


n = int(input())
l1 = r1 = l0 = r0 = 0
for i in range(n):
	(l, r) = map(int, input().split())
	l1 += l
	r1 += r
l0 = n - l1
r0 = n - r1
if l0 == 0 and r0 == 0 or (l1 == n and r1 == n):
	print(0)
elif r1 == n and n - l1 < l1:
	print(l0)
elif l1 == n and n - r1 < r1:
	print(r0)
elif r0 == 0 and n - l0 < l0:
	print(l1)
elif l0 == 0 and n - r0 < r0:
	print(r1)
elif l1 == r1 and l1 + r1 <= l0 + r0:
	print(l1 + r1)
elif l0 == r0 and l0 + r0 <= l1 + r1:
	print(l0 + r0)
elif l1 + r0 < l0 + r1:
	print(l1 + r0)
elif l0 + r1 < l1 + r0:
	print(l0 + r1)


a = b = c = d = 0
for _ in range(int(input())):
	str = input()
	if str[0] == '1':
		a += 1
	else:
		b += 1
	if str[2] == '1':
		c += 1
	else:
		d += 1
print(min(a, b) + min(c, d))


import sys
try:
	sys.stdin = open('inputs.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
finally:
	input = sys.stdin.readline
	print = sys.stdout.write
t = int(input())
left_closed = 0
right_closed = 0
for _ in range(t):
	(l, r) = input().split()
	if l == '0':
		left_closed += 1
	if r == '0':
		right_closed += 1
total = (left_closed if left_closed <= t // 2 else t - left_closed) + (right_closed if right_closed <= t // 2 else t - right_closed)
print(str(total))


n = int(input())
suml = sumr = 0
for i in range(n):
	(l, r) = map(int, input().split())
	suml += l
	sumr += r
print(min(sumr, n - sumr) + min(suml, n - suml))


n = int(input())
count01 = 0
count10 = 0
count11 = 0
count00 = 0
for _ in range(n):
	(l, r) = map(int, input().split())
	if l == 0 and r == 1:
		count01 += 1
	elif l == 1 and r == 0:
		count10 += 1
	elif l == 1 and r == 1:
		count11 += 1
	elif l == 0 and r == 0:
		count00 += 1
print(min(count10 * 2 + count11 + count00, count01 * 2 + count11 + count00, count10 + count01 + count11 * 2, count10 + count01 + count00 * 2))


n = int(input())
arr = []
l1 = l0 = r1 = r0 = 0
for i in range(n):
	arr.append(list(map(int, input().split())))
	if arr[i][0] == 0:
		l0 += 1
	elif arr[i][0] == 1:
		l1 += 1
	if arr[i][1] == 0:
		r0 += 1
	elif arr[i][1] == 1:
		r1 += 1
result = 0
if l0 >= l1:
	result = result + l1
elif l1 > l0:
	result = result + l0
if r0 >= r1:
	result = result + r1
elif r1 > r0:
	result = result + r0
print(result)


n = int(input())
o = []
l = []
for i in range(n):
	(g, h) = list(map(int, input().split()))
	o += [g]
	l += [h]
a = [o.count(1), o.count(0)]
d = [l.count(1), l.count(0)]
c = min(d) + min(a)
print(c)


n = int(input())
cupboards = [input().split() for _ in range(n)]
a = sum((1 for c in cupboards if c[0] == '0'))
b = sum((1 for c in cupboards if c[1] == '0'))
print(min(a, n - a) + min(b, n - b))


n = int(input())
left = ''
right = ''
for i in range(n):
	pair = input().split(' ')
	left += pair[0]
	right += pair[1]
print(min(left.count('0'), left.count('1')) + min(right.count('0'), right.count('1')))


n = int(input())
left = []
right = []
for i in range(n):
	a = input().split()
	left.append(a[0])
	right.append(a[1])
left1 = left.count('0')
left0 = left.count('1')
right1 = right.count('1')
right0 = right.count('0')
final = 0
if left1 <= left0:
	final += left1
else:
	final += left0
if right1 <= right0:
	final += right1
else:
	final += right0
print(final)


n = int(input())
(left, right) = ({0: 0, 1: 0}, {0: 0, 1: 0})
for _ in range(n):
	(a, b) = map(int, input().split())
	left[a] += 1
	right[b] += 1
ans = 0
if left[0] >= left[1]:
	ans += n - left[0]
else:
	ans += n - left[1]
if right[0] >= right[1]:
	ans += n - right[0]
else:
	ans += n - right[1]
print(ans)


n = int(input())
li = []
(lil, lir) = ([], [])
count_l = 0
count_r = 0
for i in range(n):
	li.append(list(map(int, input().split())))
for i in range(n):
	lil.append(li[i][0])
	lir.append(li[i][1])
if lil.count(0) > lil.count(1):
	count_l += lil.count(1)
elif lil.count(0) < lil.count(1):
	count_l = lil.count(0)
else:
	count_l += lil.count(0)
if lir.count(0) > lir.count(1):
	count_r += lir.count(1)
elif lir.count(0) < lir.count(1):
	count_r += lir.count(0)
else:
	count_r += lir.count(0)
print(count_l + count_r)


i = lambda : map(int, input().split())
(n,) = i()
c = d = 0
for _ in [0] * n:
	(x, y) = i()
	c += x > 0
	d += y > 0
c = min(c, n - c)
d = min(d, n - d)
print(c + d)


n = int(input())
l = []
r = []
for i in range(n):
	lst = list(map(int, input().split()))
	l.append(lst[0])
	r.append(lst[1])
t = 0
if 0 in l and 1 in l:
	if l.count(1) >= l.count(0):
		for i in l:
			if i == 0:
				t = t + 1
	elif l.count(0) > l.count(1):
		for i in l:
			if i == 1:
				t = t + 1
if 0 in r and 1 in r:
	if r.count(1) >= r.count(0):
		for i in r:
			if i == 0:
				t = t + 1
	elif r.count(0) > r.count(1):
		for i in r:
			if i == 1:
				t = t + 1
print(t)


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


n = int(input())
L = []
R = []
for _ in range(n):
	(i, j) = input().split()
	i = int(i)
	j = int(j)
	L.append(i)
	R.append(j)
forLeft = max(L.count(1), L.count(0))
forRight = max(R.count(1), R.count(0))
ans = 2 * n - forLeft - forRight
print(ans)


n = int(input())
list1 = []
for i in range(n):
	(l, r) = map(int, input().split())
	list1.append([l, r])
count1 = 0
count2 = 0
for i in range(len(list1)):
	if list1[i][0] == 0:
		count1 = count1 + 1
	if list1[i][1] == 0:
		count2 = count2 + 1
count2a = n - count2
count1a = n - count1
count = 0
if count1a < count1:
	count = count + count1a
if count1a > count1:
	count = count + count1
if count1a == count1:
	count = count + count1
if count2a < count2:
	count = count + count2a
if count2a > count2:
	count = count + count2
if count2a == count2:
	count = count + count2
print(count)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	a = []
	b = []
	for _ in range(n):
		(c, d) = LI()
		a.append(c)
		b.append(d)
	ansA = 0
	for i in range(n):
		c = a[i]
		d = b[i]
		if c != 0:
			ansA += 1
		if d != 0:
			ansA += 1
	ansB = 0
	for i in range(n):
		c = a[i]
		d = b[i]
		if c != 0:
			ansB += 1
		if d != 1:
			ansB += 1
	ansC = 0
	for i in range(n):
		c = a[i]
		d = b[i]
		if c != 1:
			ansC += 1
		if d != 0:
			ansC += 1
	ansD = 0
	for i in range(n):
		c = a[i]
		d = b[i]
		if c != 1:
			ansD += 1
		if d != 1:
			ansD += 1
	return min(ansA, ansB, ansC, ansD)
print(main())


n = int(input())
l = 0
r = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		l -= 1
	else:
		l += 1
	if b == 0:
		r -= 1
	else:
		r += 1
print(n - abs(l) + n - abs(r) >> 1)


def cupboard(n, l, r):
	lcount = l.count(1)
	rcount = r.count(1)
	li = min(lcount, n - lcount)
	ri = min(rcount, n - rcount)
	return li + ri
n = int(input())
larr = []
rarr = []
for i in range(n):
	(l, r) = map(int, input().split())
	larr.append(l)
	rarr.append(r)
print(cupboard(n, larr, rarr))


cupboards = int(input())
left_doors = []
right_doors = []
time_required = 0
for i in range(cupboards):
	(left, right) = [int(i) for i in input().split(' ')]
	left_doors.append(left)
	right_doors.append(right)
if left_doors.count(0) > left_doors.count(1):
	time_required += left_doors.count(1)
else:
	time_required += left_doors.count(0)
if right_doors.count(0) > right_doors.count(1):
	time_required += right_doors.count(1)
else:
	time_required += right_doors.count(0)
print(time_required)


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))


n = int(input())
cl = cr = 0
for i in range(n):
	(l, r) = map(int, input().split())
	cl += l
	cr += r
print(min(cl, n - cl) + min(cr, n - cr))


n = int(input())
(a, b) = ([], [])
for i in range(n):
	(l, r) = map(int, input().split())
	a.append(l)
	b.append(r)
x = a.count(0)
y = a.count(1)
c = b.count(0)
d = b.count(1)
print(min(x, y) + min(c, d))


l = []
r = []
(lo, lt, ro, rt) = (0, 0, 0, 0)
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	l.append(a)
	r.append(b)
if 0 in l:
	lo = l.count(0)
if 1 in l:
	lt = l.count(1)
if 0 in r:
	ro = r.count(0)
if 1 in l:
	rt = r.count(1)
print(min(lo, lt) + min(ro, rt))


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())
a = []
for i in range(n):
	x = [int(i) for i in input().strip().split()]
	a.append(x)
count_0l = 0
count_1l = 0
count_0r = 0
count_1r = 0
for i in range(n):
	if a[i][0] == 0:
		count_0l += 1
	else:
		count_1l += 1
	if a[i][1] == 0:
		count_0r += 1
	else:
		count_1r += 1
left = [count_0l, count_1l]
right = [count_0r, count_1r]
print(min(left) + min(right))


t = int(input())
a = []
b = []
for i in range(t):
	(l, r) = map(int, input().split())
	a.append(l)
	b.append(r)
a1 = a.count(0)
a2 = a.count(1)
b1 = b.count(0)
b2 = b.count(1)
a3 = min(a1, a2)
b3 = min(b1, b2)
print(a3 + b3)


def solve(doors, n):
	l = sum((1 for i in range(n) if doors[i][0] == 0))
	r = sum((1 for i in range(n) if doors[i][1] == 0))
	return min(n - l, l) + min(n - r, r)

def main():
	n = int(input())
	doors = [tuple(map(int, input().split())) for _ in range(n)]
	print(solve(doors, n))
main()


(left, right) = ([], [])
for _ in range(int(input())):
	(leftin, rightin) = map(int, input().split())
	left.append(leftin)
	right.append(rightin)
print(min(left.count(0), left.count(1)) + min(right.count(0), right.count(1)))


left_op = 0
left_cl = 0
right_op = 0
right_cl = 0
for _ in range(0, int(input())):
	(l, r) = map(int, input().strip().split())
	if l == 0:
		left_cl += 1
	else:
		left_op += 1
	if r == 1:
		right_op += 1
	else:
		right_cl += 1
print(min(left_cl, left_op) + min(right_cl, right_op))


(c, d) = ([], [])
z = lambda x, y: x.count(y)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c += [a]
	d += [b]
print(min(z(c, 0), z(c, 1)) + min(z(d, 1), z(d, 0)))


n = int(input())
l = []
r = []
for i in range(n):
	(a, b) = map(lambda x: int(x), input().split())
	l.append(a)
	r.append(b)
l0 = l.count(0)
l1 = l.count(1)
r0 = r.count(0)
r1 = r.count(1)
p = min(l0, l1)
q = min(r0, r1)
print(q + p)


n = int(input())
L = []
R = []
countL = [0, 0]
countR = [0, 0]
for _ in range(n):
	(x, y) = map(int, input().split())
	L.append(x)
	R.append(y)
	countL[x] += 1
	countR[y] += 1
maxL = countL.index(max(countL))
maxR = countR.index(max(countR))
count = 0
for i in range(n):
	if L[i] != maxL:
		count += 1
	if R[i] != maxR:
		count += 1
print(count)


n = int(input())
left_side = []
right_side = []
for cupboard in range(n):
	l_r = input().split()
	left = int(l_r[0])
	right = int(l_r[1])
	left_side.append(left)
	right_side.append(right)
sum_l = sum(left_side)
sum_r = sum(right_side)
if sum_l <= len(left_side) / 2:
	left = sum_l
else:
	left = len(left_side) - sum_l
if sum_r <= len(right_side) / 2:
	right = sum_r
else:
	right = len(right_side) - sum_r
print(left + right)


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)


n = int(input())
(x, y) = (0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	if l > 0:
		x = x + 1
	if r > 0:
		y += 1
print(min(x, n - x) + min(y, n - y))


n = int(input())
l = list()
r = list()
for i in range(n):
	(li, ri) = [int(k) for k in input().split()]
	(l.append(li), r.append(ri))
lones = 0
lzeros = 0
rzeros = 0
rones = 0
for j in range(n):
	if l[j] == 0:
		lzeros += 1
	else:
		lones += 1
	if r[j] == 0:
		rzeros += 1
	else:
		rones += 1
ans = min(lzeros, lones) + min(rzeros, rones)
print(ans)


def single_integer():
	return int(input())

def multi_integer():
	return map(int, input().split())

def string():
	return input()

def multi_string():
	return input().split()
n = single_integer()
l_open = 0
l_close = 0
r_open = 0
r_close = 0
for i in range(n):
	(l, r) = multi_string()
	if l == '1':
		l_open += 1
	else:
		l_close += 1
	if r == '1':
		r_open += 1
	else:
		r_close += 1
print(min(l_open, l_close) + min(r_open, r_close))


from collections import Counter
n = int(input())
(ld, rd) = ([], [])
for _ in range(n):
	doors = list(map(int, input().split()))
	ld.append(doors[0])
	rd.append(doors[1])
rd_change = 0
ld_change = 0
if len(Counter(rd).most_common()) > 1:
	rd_least = Counter(rd).most_common()[1][0]
	rd_change = Counter(rd)[rd_least]
if len(Counter(ld).most_common()) > 1:
	ld_least = Counter(ld).most_common()[1][0]
	ld_change = Counter(ld)[ld_least]
print(ld_change + rd_change)


n = int(input())
left_open = 0
right_open = 0
for _ in range(n):
	(l, r) = input().split()
	if l == '1':
		left_open += 1
	if r == '1':
		right_open += 1
time_cl = left_open
time_ol = n - left_open
time_cr = right_open
time_or = n - right_open
time = 0
if time_cl > time_ol:
	time += time_ol
else:
	time += time_cl
if time_cr > time_or:
	time += time_or
else:
	time += time_cr
print(time)


(l0, l1) = (0, 0)
(r0, r1) = (0, 0)
ans = 0
for i in range(int(input())):
	(l, r) = input().split()
	if l == '0':
		l0 += 1
	else:
		l1 += 1
	if r == '0':
		r0 += 1
	else:
		r1 += 1
if l0 > l1:
	ans += l1
else:
	ans += l0
if r0 > r1:
	ans += r1
else:
	ans += r0
print(ans)


n = int(input())
s0 = 0
s1 = 0
b0 = 0
b1 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		s0 += 1
	else:
		s1 += 1
	if b == 0:
		b0 += 1
	else:
		b1 += 1
x = s1
if s0 < s1:
	x = s0
y = b1
if b0 < b1:
	y = b0
print(x + y)


n = int(input())
l = []
s = 0
for i in range(n):
	l.extend(map(int, input().split()))
le = sum(l[::2])
r = sum(l[-1::-2])
if le > n // 2:
	s += n - le
else:
	s += le
if r > n // 2:
	s += n - r
else:
	s += r
print(s)


def main():
	n = int(input())
	doors = []
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		doors.append((l, r))
	lopen = 0
	ropen = 0
	for door in doors:
		lopen += door[0]
		ropen += door[1]
	ans = 0
	if lopen > n // 2:
		ans += n - lopen
	else:
		ans += lopen
	if ropen > n // 2:
		ans += n - ropen
	else:
		ans += ropen
	print(ans)
	return
main()


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


left = []
right = []
for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	left.append(l)
	right.append(r)
a = left.count(0)
b = left.count(1)
ls = min(a, b)
x = right.count(0)
y = right.count(1)
rs = min(x, y)
print(ls + rs)


(a, ans) = ([], 0)
for i in range(int(input())):
	a.extend(input().split())
print(min(a[::2].count('0'), a[::2].count('1')) + min(a[1::2].count('0'), a[1::2].count('1')))


n = int(input())
left = list()
right = list()
for i in range(n):
	doors = input().split()
	left.append(int(doors[0]))
	right.append(int(doors[1]))
seconds = 0
l_zero = n - sum(left)
l_one = sum(left)
r_zero = n - sum(right)
r_one = sum(right)
if l_one > l_zero:
	seconds += l_zero
else:
	seconds += l_one
if r_one > r_zero:
	seconds += r_zero
else:
	seconds += r_one
print(seconds)


l = []
r = []
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l.append(x)
	r.append(y)
print(min(l.count(1), l.count(0)) + min(r.count(1), r.count(0)))


n = int(input())
left = list()
right = list()
while n > 0:
	l = input().split()
	left.append(int(l[0]))
	right.append(int(l[1]))
	n -= 1
total = 0
lzero = left.count(0)
lone = left.count(1)
rzero = right.count(0)
rone = right.count(1)
if lzero < lone:
	total = lzero
else:
	total = lone
if rzero < rone:
	total += rzero
else:
	total += rone
print(total)


n = int(input())
leftOne = 0
rightOne = 0
for i in range(n):
	(left, right) = list(map(int, input().split()))
	if left == 1:
		leftOne += 1
	if right == 1:
		rightOne += 1
work = 0
if n - leftOne > leftOne:
	work += leftOne
else:
	work += n - leftOne
if n - rightOne > rightOne:
	work += rightOne
else:
	work += n - rightOne
print(work)


n = int(input())
p = []
l = []
c = 0
for x in range(n):
	(pa, k) = list(map(int, input().split()))
	p.append(pa)
	l.append(k)
if p.count(0) > p.count(1):
	c += p.count(1)
else:
	c += p.count(0)
if l.count(0) > l.count(1):
	c += l.count(1)
else:
	c += l.count(0)
print(c)


n = int(input())
L = []
R = []
for _ in range(n):
	(l, r) = map(int, input().split())
	L.append(l)
	R.append(r)
l0 = L.count(0)
l1 = n - l0
r0 = R.count(0)
r1 = n - r0
t = 0
if r0 > r1:
	t += r1
else:
	t += r0
if l0 > l1:
	t += l1
else:
	t += l0
print(t)


n = int(input())
l = []
r = []
for i in range(n):
	(a, b) = input().split()
	l.append(int(a))
	r.append(int(b))
sum1 = sum(l)
sum2 = sum(r)
total = 0
if sum1 == sum2 == n:
	print(0)
else:
	if sum1 > n // 2:
		total += n - sum1
	else:
		total += sum1
	if sum2 > n // 2:
		total += n - sum2
	else:
		total += sum2
	print(total)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		lr = [LI() for _ in range(n)]
		a = [0] * 2
		b = [0] * 2
		for (l, r) in lr:
			a[l] += 1
			b[r] += 1
		rr.append(n * 2 - max(a) - max(b))
	return JA(rr, '\n')
print(main())


def calc(cp):
	OPEN = 1
	CLOSED = 0
	N = len(cp)
	(lo, ro) = (0, 0)
	for (l, r) in cp:
		if l == OPEN:
			lo += 1
		if r == OPEN:
			ro += 1
	l = min(lo, N - lo)
	r = min(ro, N - ro)
	return l + r
n = int(input())
cp = []
for _ in range(n):
	cp.append(list(map(int, input().split())))
print(calc(cp))


n = int(input())
(l, r) = ([], [])
for i in range(n):
	temp = list(map(int, input().split()))
	l.append(temp[0])
	r.append(temp[1])
lcount = 0
for i in l:
	if i == 0:
		lcount += 1
rcount = 0
for i in r:
	if i == 0:
		rcount += 1
t = 0
if lcount < n / 2:
	t += lcount
else:
	t += n - lcount
if rcount < n / 2:
	t += rcount
else:
	t += n - rcount
print(t)


p = input
N = int(p())
L = 0
R = 0
for _ in '.' * N:
	(l, r) = map(int, p().split())
	L += l
	R += r
print(min(L, N - L) + min(R, N - R))


n = int(input())
(a, b) = zip(*(input().split() for _ in ' ' * n))
print(min(a.count('1'), a.count('0')) + min(b.count('0'), b.count('1')))


import sys
n = int(input())
(lft, rt) = (0, 0)
for line in sys.stdin:
	(l, r) = line.split()
	if l == '1':
		lft += 1
	if r == '1':
		rt += 1
ans = 0
if lft > n // 2:
	ans += n - lft
else:
	ans += lft
if rt > n // 2:
	ans += n - rt
else:
	ans += rt
print(ans)


n = int(input())
l = ''
r = ''
for i in range(n):
	(a, b) = map(str, input().split())
	l += a
	r += b
lc = l.count('1')
rc = r.count('1')
count = 0
if rc > n // 2:
	count += n - rc
else:
	count += rc
if lc > n // 2:
	count += n - lc
else:
	count += lc
print(count)


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


n = int(input())
rightClosed = 0
rightOpen = 0
leftClosed = 0
leftOpen = 0
count = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		leftClosed += 1
	if l == 1:
		leftOpen += 1
	if r == 0:
		rightClosed += 1
	if r == 1:
		rightOpen += 1
if rightClosed >= rightOpen:
	count += rightOpen
else:
	count += rightClosed
if leftClosed >= leftOpen:
	count += leftOpen
else:
	count += leftClosed
print(count)


n = int(input())
a = []
b = []
flag = 0
for i in range(n):
	(p, q) = [int(x) for x in input().split()]
	a.append(p)
	b.append(q)
zeroa = a.count(0)
zerob = b.count(0)
onea = a.count(1)
oneb = b.count(1)
count = 0
if zeroa <= onea:
	count += zeroa
else:
	count += onea
if zerob <= oneb:
	count += zerob
else:
	count += oneb
print(count)


import math
n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
cols = len(arr[0])
rows = len(arr)
l_closed_count = 0
r_closed_count = 0
l_open_count = 0
r_open_count = 0
for j in range(cols):
	for i in range(rows):
		if arr[i][j] == 0 and j == 0:
			l_closed_count += 1
		elif arr[i][j] == 1 and j == 0:
			l_open_count += 1
		elif arr[i][j] == 0 and j == 1:
			r_closed_count += 1
		elif arr[i][j] == 1 and j == 1:
			r_open_count += 1
moves = 0
if l_closed_count >= l_open_count:
	moves += l_open_count
else:
	moves += l_closed_count
if r_closed_count >= r_open_count:
	moves += r_open_count
else:
	moves += r_closed_count
print(moves)


l = []
ls = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	ls.append(b)
a0 = l.count(0)
a1 = l.count(1)
b0 = ls.count(0)
b1 = ls.count(1)
c = 0
if a0 >= a1:
	c += a1
else:
	c += a0
if b0 >= b1:
	c += b1
else:
	c += b0
print(c)


n = int(input())
left = {0: 0, 1: 0}
right = {0: 0, 1: 0}
for i in range(n):
	arr = input().split(' ')
	if int(arr[0]) == 0:
		left[0] += 1
	else:
		left[1] += 1
	if int(arr[1]) == 0:
		right[0] += 1
	else:
		right[1] += 1
res = min(left[0], left[1]) + min(right[0], right[1])
print(res)


from sys import *
from math import *

def main():
	pass
	n = int(input())
	(a, c) = [0] * 2
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		if l == 0:
			a += 1
		if r == 0:
			c += 1
	print(min(a, n - a) + min(c, n - c))
main()


c = int(input())
states = []
for i in range(c):
	states.append(list(map(int, input().split())))
lopen = 0
ropen = 0
for cup in states:
	if cup[0] == 1:
		lopen += 1
	if cup[1] == 1:
		ropen += 1
t = 0
r = min(ropen, c - ropen) + min(lopen, c - lopen)
t += r
print(t)


n = int(input())
left = []
right = []
count = 0
for i in range(n):
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)
left1 = left.count(1)
left0 = left.count(0)
count += min(left1, left0)
right1 = right.count(1)
right0 = right.count(0)
count += min(right1, right0)
print(count)


import sys
t = int(input())
m = []
n = []
c = 0
for i in range(0, t):
	(a, b) = map(int, sys.stdin.readline().strip().split())
	m.append(a)
	n.append(b)
if m.count(1) > m.count(0):
	c += m.count(0)
else:
	c += m.count(1)
if n.count(1) > n.count(0):
	c += n.count(0)
else:
	c += n.count(1)
print(c)


n = int(input())
l = [0] * n
r = [0] * n
c = 0
for i in range(n):
	(l[i], r[i]) = map(int, input().split())
if l.count(1) > l.count(0):
	c = c + l.count(0)
else:
	c = c + l.count(1)
if r.count(1) > r.count(0):
	c = c + r.count(0)
else:
	c = c + r.count(1)
print(c)


n = int(input())
a = []
v = z = x = y = 0
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	if a[i][0] == 0:
		x += 1
	if a[i][1] == 1:
		z += 1
	if a[i][0] == 1:
		y += 1
	if a[i][1] == 0:
		v += 1
if x < y:
	if z < v:
		print(x + z)
	else:
		print(x + v)
elif z < v:
	print(y + z)
else:
	print(y + v)


x_0 = 0
y_0 = 0
x_1 = 0
y_1 = 0
count = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x == 0:
		x_0 += 1
	elif x == 1:
		x_1 += 1
	if y == 0:
		y_0 += 1
	elif y == 1:
		y_1 += 1
if x_0 > x_1:
	count += x_1
elif x_0 <= x_1:
	count += x_0
if y_0 > y_1:
	count += y_1
elif y_0 <= y_1:
	count += y_0
print(count)


(l, r) = ([], [])
t = 0
for x in range(int(input())):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
if r.count(1) > r.count(0):
	t += r.count(0)
else:
	t += r.count(1)
if l.count(1) > l.count(0):
	t += l.count(0)
else:
	t += l.count(1)
print(t)


def fn(l):
	if l.count(0) > l.count(1):
		return l.count(1)
	else:
		return l.count(0)
n = int(input())
l = []
r = []
for i in range(n):
	(a, b) = input().split()
	l.append(int(a))
	r.append(int(b))
c = 0
c += fn(l)
c += fn(r)
print(c)


l0 = r0 = 0
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		l0 += 1
	if b == 0:
		r0 += 1
print(min(l0, n - l0) + min(r0, n - r0), end='')


n = int(input())
l = [0, 0]
r = [0, 0]
while n > 0:
	(li, ri) = [int(x) for x in input().split()]
	l[li] += 1
	r[ri] += 1
	n -= 1
print(min(l) + min(r))


t = int(input())
count_l_zero = 0
count_r_zero = 0
count_l_one = 0
count_r_one = 0
count = 0
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == 0:
		count_l_zero += 1
	else:
		count_l_one += 1
	if b == 0:
		count_r_zero += 1
	else:
		count_r_one += 1
if count_l_zero > count_l_one:
	count += count_l_one
elif count_l_zero < count_l_one:
	count += count_l_zero
else:
	count += count_l_zero
if count_r_zero > count_r_one:
	count += count_r_one
elif count_r_zero < count_r_one:
	count += count_r_zero
else:
	count += count_r_zero
print(count)


t = int(input())
l = []
for i in range(t):
	l.append(list(map(int, input().split())))
leftone = 0
rightone = 0
leftzero = 0
rightzero = 0
for i in range(t):
	if l[i][0] == 0:
		leftzero += 1
	else:
		leftone += 1
	if l[i][1] == 0:
		rightzero += 1
	else:
		rightone += 1
print(min(leftzero, leftone) + min(rightzero, rightone))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
left = [1] * n
right = [1] * n
for i in range(n):
	(left[i], right[i]) = get_int_list()
l = min(left.count(0), left.count(1))
r = min(right.count(0), right.count(1))
print(l + r)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
n = int(input())
a = []
b = []
for i in range(n):
	temp = lis()
	a.append(temp[0])
	b.append(temp[1])
print(min(a.count(0), a.count(1)) + min(b.count(0), b.count(1)))


num = int(input())
left_open = 0
left_close = 0
right_open = 0
right_close = 0
for _ in range(num):
	(l, r) = input().split()
	if l == '1':
		left_open += 1
	else:
		left_close += 1
	if r == '1':
		right_open += 1
	else:
		right_close += 1
print(sum([min([left_close, left_open]), min([right_open, right_close])]))


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())
ls1 = []
ls2 = []
for _ in range(n):
	(x, y) = map(int, input().split())
	ls1.append(x)
	ls2.append(y)
a = sum(ls1)
b = sum(ls2)
x = max(a, b)
y = min(a, b)
if x > n / 2:
	x = n - x
if y > n / 2:
	y = n - y
print(x + y)


t = int(input())
l = list()
r = list()
for _ in range(t):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
print(min(l.count(0), l.count(1)) + min(r.count(0), r.count(1)))


n = int(input())
lc = 0
rc = 0
for _ in range(n):
	(l, r) = [int(x) for x in input().split(' ')]
	lc += l
	rc += r
s = min(lc, n - lc) + min(rc, n - rc)
print(s)


n = int(input())
a = 0
b = 0
for _ in range(n):
	(aa, bb) = map(int, input().split(' '))
	a += aa
	b += bb
ans = min(a, n - a) + min(b, n - b)
print(ans)


n = int(input())
left_zero = 0
left_one = 0
right_zero = 0
right_one = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		left_zero += 1
	else:
		left_one += 1
	if b == 0:
		right_zero += 1
	else:
		right_one += 1
print(min(left_zero, left_one) + min(right_zero, right_one))


n = int(input())
ca = 0
cb = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		ca = ca + 1
	if b == 0:
		cb = cb + 1
ma = min(ca, n - ca)
mb = min(cb, n - cb)
print(ma + mb)


n = int(input())
(c, f) = (0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	if l:
		c += 1
	if r:
		f += 1
print(min(c, n - c) + min(f, n - f))


from operator import itemgetter
n = int(input())
num = 0
num2 = 0
for i in range(n):
	(l, r) = map(int, input().split())
	num += l
	num2 += r
print(min(num, n - num) + min(num2, n - num2))


def cupboards(nums):
	(l, r) = (0, 0)
	for pair in nums:
		l += pair[0]
		r += pair[1]
	return min(l, len(nums) - l) + min(r, len(nums) - r)
arr = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	arr.append([a, b])
print(cupboards(arr))


right = []
left = []
for _ in range(int(input())):
	(r, l) = map(int, input().split())
	right.append(r)
	left.append(l)
n1 = min(right.count(0), right.count(1))
n2 = min(left.count(0), left.count(1))
print(n1 + n2)


Left1 = Left0 = Right0 = Right1 = 0
essi = int(input())
for i in range(essi):
	(a, b) = map(int, input().split())
	if a == 0:
		Left0 += 1
	else:
		Left1 += 1
	if b == 0:
		Right0 += 1
	else:
		Right1 += 1
print(min(Left0, Left1) + min(Right0, Right1))


import sys
import collections
import math
import itertools as it

def readArray(type=int):
	line = input()
	return [type(x) for x in line.split()]

def solve():
	n = int(input())
	loc = 0
	roc = 0
	t = 0
	for x in range(n):
		(l, r) = readArray()
		loc += l
		roc += r
	t += n - loc if loc > n - loc else loc
	t += n - roc if roc > n - roc else roc
	print(t)
solve()


li = []
li2 = []
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	li.append(l)
	li2.append(r)
print(min(li.count(1), li.count(0)) + min(li2.count(1), li2.count(0)))


n = int(input())
cupboards = []
for _ in range(n):
	cupboards.append(list(map(int, input().split())))
(l, r) = ([0, 0], [0, 0])
for i in range(n):
	if cupboards[i][0] == 1:
		l[1] += 1
	elif cupboards[i][0] == 0:
		l[0] += 1
	if cupboards[i][1] == 1:
		r[1] += 1
	elif cupboards[i][1] == 0:
		r[0] += 1
output = min([l[0], l[1]]) + min([r[0], r[1]])
print(output)


n = int(input())
doors = []
(left, right) = (0, 0)
for i in range(n):
	(a, b) = (int(d) for d in input().split())
	left += a
	right += b
print(min(left, n - left) + min(right, n - right))


n = int(input())
l0 = 0
l1 = 0
r0 = 0
r1 = 0
for i in range(n):
	[l, r] = [int(x) for x in input().split()]
	if l == 0:
		l0 += 1
	else:
		l1 += 1
	if r == 0:
		r0 += 1
	else:
		r1 += 1
print(min(l0, l1) + min(r0, r1))


lz = 0
lo = 0
rz = 0
ro = 0
for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	if l == 0:
		lz += 1
	else:
		lo += 1
	if r == 0:
		rz += 1
	else:
		ro += 1
print(min(lz, lo) + min(ro, rz))


n = int(input())
p = []
q = []
for i in range(n):
	(s, t) = map(int, input().split())
	p.append(s)
	q.append(t)
a = p.count(0)
b = p.count(1)
c = q.count(0)
d = q.count(1)
print(min(a, b) + min(c, d))


doors = [0, 0]
x = int(input())
for _ in range(x):
	(a, b) = (int(i) for i in input().split())
	doors[0] += a
	doors[1] += b
secs = min(doors[0], x - doors[0]) + min(doors[1], x - doors[1])
print(secs)


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


num_cupboards = int(input())
total_left = 0
total_right = 0
for _ in range(num_cupboards):
	(left, right) = map(int, input().split())
	total_left += left
	total_right += right
min_left = min(total_left, num_cupboards - total_left)
min_right = min(total_right, num_cupboards - total_right)
print(min_left + min_right)


n = int(input())
l = []
for i in range(n):
	l1 = list(map(int, input().split()))
	l.append(l1)
cl0 = 0
cl1 = 0
cr0 = 0
cr1 = 0
for i in range(len(l)):
	if l[i][0] == 0:
		cl0 += 1
	else:
		cl1 += 1
	if l[i][1] == 0:
		cr0 += 1
	else:
		cr1 += 1
left = min(cl0, cl1)
right = min(cr0, cr1)
print(left + right)


import collections
n = int(input())
a = []
b = []
c = 0
for i in range(0, n):
	(l, r) = input().split()
	(l, r) = [int(l), int(r)]
	a.append(l)
	b.append(r)
a1 = collections.Counter(a)
b1 = collections.Counter(b)
if a1[0] > a1[1]:
	c += a1[1]
else:
	c += a1[0]
if b1[0] > b1[1]:
	c += b1[1]
else:
	c += b1[0]
print(c)


loop = int(input())
firstCol = 0
firCols = 0
secCol = 0
secCols = 0
for i in range(loop):
	e = str(input())
	s = e.split(' ')
	if s[0] == '0':
		firstCol += 1
	elif s[0] == '1':
		firCols += 1
	if s[1] == '0':
		secCol += 1
	elif s[1] == '1':
		secCols += 1
answerOne = 0
answerTwo = 0
if firstCol >= firCols:
	answerOne = loop - firstCol
elif firstCol <= firCols:
	answerOne = loop - firCols
if secCol >= secCols:
	answerTwo = loop - secCol
elif secCol <= secCols:
	answerTwo = loop - secCols
print(answerOne + answerTwo)


sum1 = 0
sum2 = 0
n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	sum1 = a[0] + sum1
	sum2 = a[1] + sum2
print(min(sum1, n - sum1) + min(sum2, n - sum2))


num_cupboards = int(input())
left_pos = list()
right_pos = list()
for idx in range(num_cupboards):
	(left, right) = list(map(int, input().split()))
	left_pos.append(left)
	right_pos.append(right)
left_sum = sum(left_pos)
right_sum = sum(right_pos)
left_time = min(left_sum, num_cupboards - left_sum)
right_time = min(right_sum, num_cupboards - right_sum)
print(left_time + right_time)


n = int(input())
l = [0] * n
r = [0] * n
for i in range(n):
	(l[i], r[i]) = input().split()
total1 = 0
total2 = 0
for ele in range(0, len(l)):
	total1 = total1 + int(l[ele])
for ele in range(0, len(r)):
	total2 = total2 + int(r[ele])
if total1 > n / 2:
	t1 = len(l) - total1
else:
	t1 = total1
if total2 > n / 2:
	t2 = len(r) - total2
else:
	t2 = total2
t = t1 + t2
print(t)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import random
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
ninf = float('-inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def max_val(arr, x):
	count = [i for i in arr if i <= x]
	return max(count)

def main():
	(L_C, R_C) = (0, 0)
	n = ii()
	List = []
	for _ in range(n):
		List.append(li())
	(zero_count_left, one_count_left) = (0, 0)
	(zero_count_right, one_count_right) = (0, 0)
	for cupboard in List:
		if cupboard[0] == 0:
			zero_count_left += 1
		if cupboard[0] == 1:
			one_count_left += 1
		if cupboard[1] == 0:
			zero_count_right += 1
		if cupboard[1] == 1:
			one_count_right += 1
	print(min(zero_count_left, one_count_left) + min(zero_count_right, one_count_right))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l0 = l1 = r0 = r1 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a:
		l1 += 1
	else:
		l0 += 1
	if b:
		r0 += 1
	else:
		r1 += 1
print(min(l1, l0) + min(r1, r0))


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


n = int(input())
l1 = l0 = r1 = r0 = 0
ans = 0
for i in range(n):
	(x, y) = map(int, input().split())
	if x == 1:
		l1 += 1
	if x == 0:
		l0 += 1
	if y == 1:
		r1 += 1
	if y == 0:
		r0 += 1
if l1 >= l0:
	ans += l0
else:
	ans += l1
if r1 >= r0:
	ans += r0
else:
	ans += r1
print(ans)


n = int(input())
(a, b) = ([], [])
for i in range(n):
	(an, bn) = map(int, input().strip().split())
	a.append(an)
	b.append(bn)
suma = sum(a)
sumb = sum(b)
a = suma + sumb
b = 2 * n - suma - sumb
c = suma + n - sumb
d = sumb + n - suma
print(min(a, b, c, d))


n = int(input())
nsl = 0
nsr = 0
t = 0
ldzc = 0
ldoc = 0
rdzc = 0
rdoc = 0
ans = []
for x in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		ldzc += 1
	if l == 1:
		ldoc += 1
	if r == 0:
		rdzc += 1
	if r == 1:
		rdoc += 1
	ans.append([l, r])
if ldzc > ldoc:
	lds = 0
else:
	lds = 1
if rdzc > rdoc:
	rds = 0
else:
	rds = 1
t = 0
for x in range(0, len(ans)):
	if ans[x][0] != lds and ans[x][1] != rds:
		t += 2
	elif ans[x][0] != lds or ans[x][1] != rds:
		t += 1
print(t)


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


n = int(input())
lis1 = []
lis2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	lis1.append(a)
	lis2.append(b)
count1 = min(lis1.count(1), lis1.count(0))
count2 = min(lis2.count(1), lis2.count(0))
print(count1 + count2)


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
n = I()
D = [tuple(IL()) for i in range(n)]
ans = 10 ** 10
for d0 in set(D):
	ans = min(ans, sum([(d[0] != d0[0]) + (d[1] != d0[1]) for d in D]))
print(ans)


n = int(input())
lst = []
lst1 = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	lst.append(a)
	lst1.append(b)
if lst != lst1:
	miny = min(lst.count(0), lst.count(1))
	miny1 = min(lst1.count(0), lst1.count(1))
	print(miny + miny1)
else:
	print('0')


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


n = int(input())
a = []
for i in range(n):
	t = input().split()
	a.append(t)
l = 0
r = 0
for t in a:
	if t[0] == '1':
		l += 1
	if t[1] == '1':
		r += 1
c = 0
if r > n // 2:
	c += n - r
else:
	c += r
if l > n // 2:
	c += n - l
else:
	c += l
print(c)


n = int(input())
l1 = []
d1 = {}
l2 = []
d2 = {}
c = 0
for i in range(n):
	(x, y) = input().split()
	l1.append(x)
	l2.append(y)
for j in l1:
	if j in d1:
		d1[j] = d1[j] + 1
	else:
		d1[j] = 1
for j in l2:
	if j in d2:
		d2[j] = d2[j] + 1
	else:
		d2[j] = 1
if len(d1) == 1 and len(d2) == 1:
	print('0')
elif len(d2) == 1 and len(d1) != 1:
	if d1['0'] >= d1['1']:
		print(d1['1'])
	else:
		print(d1['0'])
elif len(d1) == 1 and len(d2) != 1:
	if d2['0'] >= d2['1']:
		print(d2['1'])
	else:
		print(d2['0'])
else:
	if d1['0'] >= d1['1']:
		c = c + d1['1']
	else:
		c = c + d1['0']
	if d2['0'] >= d2['1']:
		c = c + d2['1']
	else:
		c = c + d2['0']
	print(c)


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))


l0 = l1 = r0 = r1 = 0
for _ in range(int(input())):
	s = input().split()
	if s[0] == '0':
		l0 += 1
	else:
		l1 += 1
	if s[1] == '0':
		r0 += 1
	else:
		r1 += 1
print(min(l0, l1) + min(r0, r1))


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)


n = int(input())
t = list()
p = list()
soT = 0
soP = 0
for i in range(0, n):
	h = list(map(int, input().split(' ')))
	t.append(h[0])
	p.append(h[1])
setT = set(t)
setP = set(p)
if len(setP) == 1 and len(setT) == 1:
	print(0)
elif t.count(1) == p.count(1) or t.count(0) == p.count(0):
	print((n - t.count(1)) * 2)
elif t.count(1) == n:
	print(n - p.count(1))
elif t.count(0) == n:
	print(n - p.count(0))
elif p.count(1) == n:
	print(n - t.count(1))
elif p.count(0) == n:
	print(n - t.count(0))
elif t.count(1) > p.count(1):
	soT = n - t.count(1)
	soP = n - p.count(0)
	print(soT + soP)
else:
	soT = n - t.count(0)
	soP = n - p.count(1)
	print(soT + soP)


n = int(input())
l = []
r = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	l.append(x)
	r.append(y)
a = l.count(0)
b = l.count(1)
c = r.count(0)
d = r.count(1)
ans = 0
if a >= b:
	if c >= d:
		ans = b + d
	else:
		ans = c + b
elif b > a:
	if c >= d:
		ans = a + d
	else:
		ans = a + c
print(ans)


l = []
r = []
for i in range(int(input())):
	lr = input().split()
	l.append(int(lr[0]))
	r.append(int(lr[1]))
x = min(l.count(0), l.count(1))
y = min(r.count(0), r.count(1))
print(x + y)


o = 0
c = 0
oo = 0
cc = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1:
		o += 1
	elif a == 0:
		c += 1
	if b == 1:
		oo += 1
	elif b == 0:
		cc += 1
ans = min(o, c) + min(oo, cc)
print(ans)


total = [0, 0]
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	total[0] += l
	total[1] += r
for i in range(2):
	total[i] = min(total[i], n - total[i])
print(sum(total))


def main():
	n = int(input())
	left1 = 0
	right1 = 0
	for _ in range(n):
		[l, r] = input().split()
		left1 += 1 if l == '1' else 0
		right1 += 1 if r == '1' else 0
	left1 = min(left1, n - left1)
	right1 = min(right1, n - right1)
	print(left1 + right1)
main()


n = int(input())
(ll, rr) = ([], [])
for i in range(n):
	(l, r) = map(int, input().split())
	ll.append(l)
	rr.append(r)
cl0 = ll.count(0)
cl1 = ll.count(1)
cr0 = rr.count(0)
cr1 = rr.count(1)
sum = min(cl0, cl1) + min(cr0, cr1)
print(sum)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = iinput()
col1 = []
col2 = []
for i in range(n):
	temp = get_list()
	col1.append(temp[0])
	col2.append(temp[1])
z1 = col1.count(0)
o1 = col1.count(1)
z2 = col2.count(0)
o2 = col2.count(1)
count = 0
if z1 >= o1:
	count += o1
else:
	count += z1
if z2 >= o2:
	count += o2
else:
	count += z2
print(count)


nb_cabs = int(input())
(l, r) = (0, 0)
for _ in range(nb_cabs):
	(a, b) = [int(x) for x in input().split()]
	l += a
	r += b
print(min(l, nb_cabs - l) + min(r, nb_cabs - r))


from collections import Counter
l_o = 0
l_c = 0
r_o = 0
r_c = 0
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		l_o += 1
	else:
		l_c += 1
	if b == 1:
		r_c += 1
	else:
		r_o += 1
print(min(r_o, r_c) + min(l_o, l_c))


n = int(input())
list1 = []
list2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	list1.append(x)
	list2.append(y)
count1 = list1.count(0)
count2 = list1.count(1)
result1 = 0
if count1 >= count2:
	result1 = count2
else:
	result1 = count1
count3 = list2.count(0)
count4 = list2.count(1)
result2 = 0
if count3 >= count4:
	result2 = count4
else:
	result2 = count3
print(result1 + result2)


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


n = int(input())
a0 = 0
a1 = 0
b0 = 0
b1 = 0
for i in range(n):
	(a, b) = input().split()
	if a == '0':
		a0 += 1
	else:
		a1 += 1
	if b == '0':
		b0 += 1
	else:
		b1 += 1
print(min(a0, a1) + min(b0, b1))


sum1 = 0
sum2 = 0
ans = 0
n = int(input())
for i in range(0, n):
	(l, r) = input().split()
	sum1 = sum1 + int(l)
	sum2 = sum2 + int(r)
if sum1 > n - sum1:
	ans = ans + (n - sum1)
else:
	ans += sum1
if sum2 > n - sum2:
	ans = ans + (n - sum2)
else:
	ans += sum2
print(ans)


l = []
r = []
t = 0
n = int(input())
c10 = 0
c11 = 0
c20 = 0
c21 = 0
for x in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
for i in l:
	if i == 0:
		c10 += 1
	else:
		c11 += 1
for j in r:
	if j == 0:
		c20 += 1
	else:
		c21 += 1
if c10 > c11:
	t += c11
else:
	t += c10
if c20 > c21:
	t += c21
else:
	t += c20
print(t)


n = int(input())
(leftOne, rightOne) = (0, 0)
for _ in range(n):
	(x, y) = map(int, input().split())
	leftOne += x
	rightOne += y
print((n - leftOne if leftOne > n // 2 else leftOne) + (n - rightOne if rightOne > n // 2 else rightOne))


n = int(input())
door = []
(r0, l0, t) = (0, 0, 0)
for i in range(n):
	door.append(list(map(int, input().split())))
for x in door:
	if x[0] == 0:
		l0 += 1
	if x[1] == 0:
		r0 += 1
if l0 > n - l0:
	t += n - l0
else:
	t += l0
if r0 > n - r0:
	t += n - r0
else:
	t += r0
print(t)


n = int(input())
left = []
right = []
for i in range(n):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
lo = left.count(1)
lc = left.count(0)
ro = right.count(1)
rc = right.count(0)
count = 0
if lo >= lc:
	count = count + lc
else:
	count = count + lo
if ro >= rc:
	count = count + rc
else:
	count = count + ro
print(count)


a = int(input())
l = []
r = []
for i in range(0, a):
	t = list(map(int, input().split()))
	l.append(t[0])
	r.append(t[1])
x = l.count(0) if l.count(0) < l.count(1) else l.count(1)
y = r.count(0) if r.count(0) < r.count(1) else r.count(1)
print(x + y)


n = int(input())
h = [[int(i) for i in input().split()] for j in range(n)]
ans = 0
l = []
r = []
for i in range(n):
	l.append(h[i][0])
	r.append(h[i][1])
l0 = l.count(0)
l1 = l.count(1)
r0 = r.count(0)
r1 = r.count(1)
if l0 > l1:
	ans += l1
else:
	ans += l0
if r0 > r1:
	ans += r1
else:
	ans += r0
print(ans)


n = int(input())
count = 0
a = ['0'] * n
b = ['0'] * n
for i in range(n):
	(a[i], b[i]) = map(str, input().split())
if a.count('0') > a.count('1'):
	count += a.count('1')
else:
	count += a.count('0')
if b.count('0') > b.count('1'):
	count += b.count('1')
else:
	count += b.count('0')
print(count)


(n, left, right) = (int(input()), [], [])
for i in range(n):
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)
res = left.count(0) if left.count(0) < left.count(1) else left.count(1)
res += right.count(0) if right.count(0) < right.count(1) else right.count(1)
print(res)


n = int(input())
s = []
sample = [[0, 0], [0, 1], [1, 0], [1, 1]]
c = [0] * 4
for i in range(n):
	s.append(list(map(int, input().split())))
for i in range(4):
	for j in range(n):
		c[i] += abs(sample[i][0] - s[j][0]) + abs(sample[i][1] - s[j][1])
print(min(c))


l = []
r = []
t = 0
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().strip().split()))
	l += [a]
	r += [b]
m = max(l.count(1), l.count(0))
t += n - m
s = max(r.count(1), r.count(0))
t += n - s
print(t)


n = int(input())
lef = []
rig = []
for _ in range(n):
	(a, b) = map(int, input().split())
	lef.append(a)
	rig.append(b)
t = 0
t += min(lef.count(0), lef.count(1))
t += min(rig.count(0), rig.count(1))
print(t)


def check(mass):
	if mass.count(1) > mass.count(0):
		return 0
	return 1
n = int(input())
left = []
right = []
for _ in range(n):
	(l, r) = input().split()
	left.append(int(l))
	right.append(int(r))
l_m = check(left)
r_m = check(right)
ans = left.count(l_m) + right.count(r_m)
print(ans)


from collections import Counter
n = int(input())
(L, R) = ([], [])
for i in range(n):
	(li, ri) = [int(c) for c in input().split()]
	L.append(li)
	R.append(ri)
cnt_l = Counter(L)
cnt_r = Counter(R)
ans = min(cnt_l[0], cnt_l[1]) + min(cnt_r[0], cnt_r[1])
print(ans)


def solve(n, left, right):
	leftSum = sum(left)
	rightSum = sum(right)
	leftTime = leftSum if leftSum <= n // 2 else n - leftSum
	rightTime = rightSum if rightSum <= n // 2 else n - rightSum
	return leftTime + rightTime
n = int(input())
left = []
right = []
for _ in range(n):
	pair = list(map(int, input().split()))
	left.append(pair[0])
	right.append(pair[1])
print(solve(n, left, right))


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))


n = int(input())
l_open = 0
l_close = 0
r_open = 0
r_close = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l:
		l_open += 1
	else:
		l_close += 1
	if r:
		r_open += 1
	else:
		r_close += 1
print(min(l_open, l_close) + min(r_open, r_close))


N = int(input())
R = list()
L = list()
for i in range(N):
	(Left, Right) = list(input().split())
	L.append(Left)
	R.append(Right)
Count = min(R.count('1'), R.count('0'))
Count += min(L.count('1'), L.count('0'))
print(Count)


n = int(input())
p = []
for i in range(n):
	p.append(input().split())
l0 = 0
l1 = 0
r0 = 0
r1 = 0
for i in range(n):
	l0 += p[i][0].count('0')
	l1 += p[i][0].count('1')
	r0 += p[i][1].count('0')
	r1 += p[i][1].count('1')
print(min(l0, l1) + min(r0, r1))


n = int(input())
(l, r) = ([None] * 10001, [None] * 10001)
for i in range(n):
	(l[i], r[i]) = map(int, input().split())
print(min(l.count(1), l.count(0)) + min(r.count(1), r.count(0)))


t = int(input())
b1 = 0
b2 = 0
z = 0
z1 = 0
while t > 0:
	(a, b) = map(int, input().split())
	if a == 0:
		z += 1
	else:
		z1 += 1
	if b == 0:
		b1 += 1
	else:
		b2 += 1
	t -= 1
print(min(z, z1) + min(b1, b2))


n = int(input())
(sl, sr) = (0, 0)
for i in range(n):
	(k, l) = map(int, input().split())
	sl = sl + l
	sr = sr + k
print(min(sl, n - sl) + min(sr, n - sr))


n = int(input())
(l0, l1, r0, r1) = (0, 0, 0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		l0 += 1
	else:
		l1 += 1
	if r == 0:
		r0 += 1
	else:
		r1 += 1
t = n - max(l0, l1) + (n - max(r0, r1))
print(t)


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	z = str(x) + str(y)
	a.append(z)
v = ['zo', 'oo', 'oz', 'zz']
o = []
for k in v:
	if k == 'zo':
		c = '01'
	elif k == 'oo':
		c = '11'
	elif k == 'oz':
		c = '10'
	else:
		c = '00'
	s = 0
	for i in range(n):
		s = s + abs(int(c[0]) - int(a[i][0])) + abs(int(c[1]) - int(a[i][1]))
	o.append(s)
print(min(o))


n = int(input())
output = 0
(lc, rc) = (0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	lc += l
	rc += r
print(min(lc, n - lc) + min(rc, n - rc))


n = int(input())
(l, r) = (0, 0)
ans = 0
for i in range(n):
	(a, b) = input().split()
	l += int(a)
	r += int(b)
if l > n // 2:
	ans += n - l
else:
	ans += l
if r > n // 2:
	ans += n - r
else:
	ans += r
print(ans)


n = int(input())
c = 0
d = 0
e = 0
f = 0
for i in range(n):
	(x, y) = list(map(int, input().split()))
	if x == 0:
		c += 1
	if x == 1:
		d += 1
	if y == 0:
		e += 1
	else:
		f += 1
print(min(c, d) + min(e, f))


n = int(input())
le = 0
ri = 0
for _ in range(n):
	(l, r) = map(int, input().split())
	le += l
	ri += r
print('{}'.format(min(le, n - le) + min(ri, n - ri)))


n = int(input().strip())
(l, r) = (0, 0)
for i in range(n):
	(ld, rd) = tuple(map(int, input().strip().split()))
	if ld:
		l += 1
	if rd:
		r += 1
print(min(l, n - l) + min(r, n - r))


def solve():
	n = int(input())
	doors = []
	l = 0
	r = 0
	t = 0
	for i in range(n):
		doors.append(list(map(int, input().split())))
	for cb in doors:
		l += cb[0]
		r += cb[1]
	if l > n / 2:
		for cb in doors:
			if cb[0] == 0:
				t += 1
	else:
		for cb in doors:
			if cb[0] == 1:
				t += 1
	if r > n / 2:
		for cb in doors:
			if cb[1] == 0:
				t += 1
	else:
		for cb in doors:
			if cb[1] == 1:
				t += 1
	print(t)
solve()


n = int(input())
left_open = 0
right_open = 0
for i in range(n):
	(left, right) = map(int, input().split())
	left_open += left
	right_open += right
score = 0
if left_open > n // 2:
	score += n - left_open
else:
	score += left_open
if right_open > n // 2:
	score += n - right_open
else:
	score += right_open
print(score)


n = int(input())
count = 0
swap = 0
ll = []
lr = []
for i in range(n):
	(a, b) = input().split()
	ll.append(a)
	lr.append(b)
count_0_ll = n - ll.count('0')
count_1_ll = n - ll.count('1')
count_0_lr = lr.count('0')
count_1_lr = lr.count('1')
if count_0_ll <= count_1_ll:
	swap += count_0_ll
else:
	swap += count_1_ll
if count_0_lr <= count_1_lr:
	swap += count_0_lr
else:
	swap += count_1_lr
print(swap)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
t = 1
for _ in range(t):
	n = ii()
	left = 0
	right = 0
	for i in range(n):
		(l, r) = mi()
		left += l
		right += r
	print(min(left, n - left) + min(right, n - right))


n = int(input())
l = []
r = []
for i in range(n):
	(li, ri) = map(int, input().split())
	l.append(li)
	r.append(ri)
lo = 0
lc = 0
for i in l:
	if i == 1:
		lo += 1
	else:
		lc += 1
ml = min(lo, lc)
ro = 0
rc = 0
for i in r:
	if i == 1:
		ro += 1
	else:
		rc += 1
mr = min(ro, rc)
print(ml + mr)


n = int(input())
(a, b, c, d) = (0, 0, 0, 0)
for i in range(n):
	l = input()
	l = l.split()
	if l[0] == '0':
		a += 1
	else:
		b += 1
	if l[1] == '0':
		c += 1
	else:
		d += 1
print(min(a, b) + min(c, d))


(a, b) = ([], [])
for x in range(int(input())):
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
print(min(a.count(0), a.count(1)) + min(b.count(0), b.count(1)))


one = zero = O = Z = 0
for i in range(int(input())):
	(left, right) = map(int, input().split())
	if left == 1:
		one += 1
	else:
		zero += 1
	if right == 1:
		O += 1
	else:
		Z += 1
ans = min(one, zero) + min(O, Z)
print(ans)


def wardrobes(lst):
	(count1, count2) = (0, 0)
	for elem in lst:
		if elem[0] == 1:
			count1 += 1
		if elem[1] == 1:
			count2 += 1
	return min(count1, len(lst) - count1) + min(count2, len(lst) - count2)
n = int(input())
b = list()
for i in range(n):
	(x, y) = [int(j) for j in input().split()]
	b.append([x, y])
print(wardrobes(b))


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))


l0 = 0
l1 = 0
r0 = 0
r1 = 0
for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	if l == 0:
		l0 += 1
	else:
		l1 += 1
	if r == 0:
		r0 += 1
	else:
		r1 += 1
lmin = min(l0, l1)
rmin = min(r0, r1)
print(lmin + rmin)


n = int(input())
left_door = []
right_door = []
for _ in range(n):
	(a, b) = map(int, input().split())
	left_door.append(a)
	right_door.append(b)
print(min(left_door.count(1), left_door.count(0)) + min(right_door.count(1), right_door.count(0)))


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
lc = [0, 0]
rc = [0, 0]
for _ in range(n):
	(l, r) = invr()
	lc[l] += 1
	rc[r] += 1
print(min(lc) + min(rc))


n = int(input())
(leftOpen, leftClosed, rightOpen, rightClosed) = (0, 0, 0, 0)
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		leftClosed += 1
	if l == 1:
		leftOpen += 1
	if r == 0:
		rightClosed += 1
	if r == 1:
		rightOpen += 1
ans = min(leftOpen, leftClosed) + min(rightOpen, rightClosed)
print(ans)


x = int(input())
count1 = 0
count2 = 0
one1 = 0
one2 = 0
tot = 0
list1 = []
for i in range(0, x):
	temp = input().split()
	temp = [int(a) for a in temp]
	list1.append(temp)
for i in range(0, x):
	if list1[i][0] == 0:
		count1 += 1
for i in range(0, x):
	if list1[i][1] == 0:
		count2 += 1
one1 = x - count1
one2 = x - count2
if one1 > count1:
	tot = tot + count1
else:
	tot = tot + one1
if one2 > count2:
	tot = tot + count2
else:
	tot = tot + one2
print(tot)


n = int(input())
(left, right) = ([], [])
for _ in range(n):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
left1 = left.count(1)
left0 = left.count(0)
right1 = right.count(1)
right0 = right.count(0)
ans = 0
if left1 == n or left0 == n:
	ans += 0
else:
	ans += min(left1, left0)
if right1 == n or right0 == n:
	ans += 0
else:
	ans += min(right1, right0)
print(ans)


n = int(input())
l = []
r = []
for i in range(n):
	(x, y) = input().split()
	l.append(int(x))
	r.append(int(y))
z1 = l.count(0)
o1 = l.count(1)
z2 = r.count(0)
o2 = r.count(1)
res = 0
if z1 < o1:
	res += z1
else:
	res += o1
if z2 < o2:
	res += z2
else:
	res += o2
print(res)


numCB = int(input())
leftCB = list()
rightCB = list()
for i in range(numCB):
	(x, y) = list(map(int, input().split()))
	leftCB.append(x)
	rightCB.append(y)
if leftCB.count(1) < leftCB.count(0):
	left = 1
else:
	left = 0
if rightCB.count(1) < rightCB.count(0):
	right = 1
else:
	right = 0
time = leftCB.count(left) + rightCB.count(right)
print(time)


import sys
from collections import Counter as C
(l, r) = ([], [])
for _ in range(int(input())):
	(li, ri) = map(int, input().split())
	l.append(li)
	r.append(ri)
ans = 0
ans = min(l.count(0), l.count(1))
ans += min(r.count(0), r.count(1))
print(ans)


def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))
INF = 1 << 31
n = gint()
open_left = 0
open_right = 0
for i in range(n):
	(l, r) = map(int, input().split())
	open_left += l
	open_right += r
print(min(open_left, n - open_left) + min(open_right, n - open_right))


n = int(input())
l = []
r = []
cnt = 0
for i in range(0, n):
	(a, b) = input().split(' ')
	l.append(int(a))
	r.append(int(b))
if l.count(1) > n / 2:
	cnt += n - l.count(1)
else:
	cnt += n - l.count(0)
if r.count(1) > n / 2:
	cnt += n - r.count(1)
else:
	cnt += n - r.count(0)
print(cnt)


n = int(input())
open = 1
closed = 0
(left_open, left_closed, right_open, right_closed) = (0, 0, 0, 0)
for i in range(n):
	(left, right) = [int(x) for x in input().split()]
	left_open += left == open
	left_closed += left == closed
	right_open += right == open
	right_closed += right == closed
min_left = min(left_open, left_closed)
min_right = min(right_open, right_closed)
print(min_left + min_right)


n = int(input())
l_list = []
r_list = []
c = 0
l0c = 0
l1c = 0
r0c = 0
r1c = 0
for i in range(0, n):
	(l, r) = map(int, input().split())
	l_list.append(l)
	r_list.append(r)
for j in range(0, n):
	if l_list[j] == 1:
		l1c += 1
	elif l_list[j] == 0:
		l0c += 1
	if r_list[j] == 1:
		r1c += 1
	elif r_list[j] == 0:
		r0c += 1
if l1c <= l0c:
	c += l1c
elif l0c < l1c:
	c += l0c
if r1c <= r0c:
	c += r1c
elif r0c < r1c:
	c += r0c
print(c)


n = int(input())
lo = 0
lc = 0
ro = 0
rc = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		lc += 1
	if l == 1:
		lo += 1
	if r == 1:
		ro += 1
	if r == 0:
		rc += 1
print(min(lc, lo) + min(ro, rc))


n = int(input())
c1 = c2 = 0
t = 0
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	if x == 1:
		c1 += 1
	if y == 1:
		c2 += 1
if c1 <= n // 2:
	t += c1
else:
	t += n - c1
if c2 <= n // 2:
	t += c2
else:
	t += n - c2
print(t)


n = int(input())
L = []
R = []
for _ in range(n):
	(l, r) = map(int, input().split())
	L.append(l)
	R.append(r)
c0 = L.count(0)
c1 = L.count(1)
ans = min(c0, c1)
c0 = R.count(0)
c1 = R.count(1)
ans += min(c0, c1)
print(ans)


n = int(input())
l_arr = []
r_arr = []
for i in range(n):
	(l, r) = map(int, input().split())
	l_arr.append(l)
	r_arr.append(r)
l0 = l_arr.count(0)
l1 = l_arr.count(1)
r0 = r_arr.count(0)
r1 = r_arr.count(1)
print(min(l0 + r1, l1 + r0, l0 + r0, l1 + r1))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve(q):
	res = ''
	i = 0
	while i < len(q):
		if q[i] == '.':
			res += '0'
		elif q[i] == '-' and q[i + 1] == '.':
			res += '1'
			i += 1
		else:
			res += '2'
			i += 1
		i += 1
	return res
n = inp()
(l_open, r_open) = (0, 0)
(l_closed, r_closed) = (0, 0)
for i in range(n):
	d = inlt()
	if d[0] == 1:
		l_open += 1
	else:
		l_closed += 1
	if d[1] == 1:
		r_open += 1
	else:
		r_closed += 1
print(n - max(l_open, l_closed) + n - max(r_open, r_closed))


t = int(input())
l = []
r = []
for i in range(t):
	d = [int(i) for i in input().split()]
	l.insert(0, d[0])
	r.insert(0, d[1])
sl = sum(l)
sr = sum(r)
if sl > t // 2:
	sl = t - sl
if sr > t // 2:
	sr = t - sr
print(sl + sr)


n = int(input())
a = [0] * n
b = [0] * n
for i in range(0, n):
	(a[i], b[i]) = input().split()
print(min([a.count('0'), a.count('1')]) + min([b.count('0'), b.count('1')]))


ro = 0
lc = 0
lo = 0
rc = 0
r = []
l = []
n = int(input())
for i in range(0, n):
	l = list(map(int, input().split()))
	if l[0] == 1:
		lo += 1
	else:
		lc += 1
	if l[1] == 1:
		ro += 1
	else:
		rc += 1
maxl = max(lo, lc)
maxr = max(ro, rc)
print(n - maxl + (n - maxr))


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
n = int(stdin.readline().strip('\n'))
(l, r) = ([], [])
for i in range(n):
	(a, b) = list(map(int, stdin.readline().split()))
	l.append(a)
	r.append(b)
ans = 0
if l.count(0) >= l.count(1):
	ans += l.count(1)
else:
	ans += l.count(0)
if r.count(0) >= r.count(1):
	ans += r.count(1)
else:
	ans += r.count(0)
print(ans)


n = int(input())
m = []
for _ in range(n):
	l = [int(x) for x in input().split()[:2]]
	m.append(l)
c = 0
k = 0
m1 = []
m2 = []
for i in m:
	m1.append(i[0])
	m2.append(i[1])
if m1.count(0) > m1.count(1):
	left = 0
else:
	left = 1
if m2.count(0) > m2.count(1):
	right = 0
else:
	right = 1
for i in m1:
	if i != left:
		c += 1
for i in m2:
	if i != right:
		c += 1
print(c)


n = int(input())
left = []
right = []
for i in range(n):
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)
flucs_left = 0
flucs_right = 0
l1 = left.count(0)
l2 = left.count(1)
if l1 > l2:
	flucs_left = l2
elif l2 > l1:
	flucs_left = l1
else:
	flucs_left = l1
r1 = right.count(0)
r2 = right.count(1)
if r1 > r2:
	flucs_right = r2
elif r2 > r1:
	flucs_right = r1
else:
	flucs_right = r1
print(flucs_left + flucs_right)


(a, b) = ([], [])
for i in range(int(input())):
	(i, j) = map(int, input().split())
	a.append(i)
	b.append(j)
print(min(a.count(0), a.count(1)) + min(b.count(0), b.count(1)))


n = int(input())
li = [0 for i in range(n)]
ri = [0 for i in range(n)]
for i in range(n):
	(x, y) = input().split(' ')
	li[i] = x
	ri[i] = y
(count_r, count_l) = (0, 0)
for i in range(n):
	if li[i] == '1':
		count_l += 1
	if ri[i] == '1':
		count_r += 1
print(min(count_l, n - count_l) + min(count_r, n - count_r))


num = int(input())
left_list = []
right_list = []
for i in range(num):
	temp_in = list(map(int, input().split()))
	left_list.append(temp_in[0])
	right_list.append(temp_in[1])
count = 0
count += min(left_list.count(0), left_list.count(1))
count += min(right_list.count(0), right_list.count(1))
print(count)


n = int(input())
leftd = {0: 0, 1: 0}
rightd = {0: 0, 1: 0}
for i in range(n):
	(a, b) = map(int, input().split())
	leftd[a] += 1
	rightd[b] += 1
minl = 0
minr = 0
if leftd[0] < leftd[1]:
	minl = leftd[0]
else:
	minl = leftd[1]
if rightd[0] < rightd[1]:
	minr = rightd[0]
else:
	minr = rightd[1]
print(minl + minr)


n = int(input())
w = x = y = z = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0:
		w += 1
	if a == 1:
		x += 1
	if b == 0:
		y += 1
	if b == 1:
		z += 1
	p = min(w, x)
	p += min(y, z)
print(p)


num = int(input(''))
lists = []
lst2 = []
a = []
b = []
min_a = 0
min_b = 0
for i in range(1, num + 1):
	lst1 = list(map(int, input().split(' ')))
	lists.append(lst1)
j = 0
for j in lists:
	lst2 = j
	a.append(lst2[0])
	b.append(lst2[1])
a_zero = a.count(0)
a_one = a.count(1)
b_zero = b.count(0)
b_one = b.count(1)
if a_zero < a_one:
	min_a = a_zero
else:
	min_a = a_one
if b_zero < b_one:
	min_b = b_zero
else:
	min_b = b_one
t = min_a + min_b
print(t)


n = int(input())
a = [input().split() for i in range(n)]
k = 0
l = 0
for i in range(n):
	if a[i][0] == '1':
		k += 1
	if a[i][-1] == '0':
		l += 1
print(min(k, n - k) + min(l, n - l))


n = int(input())
l1 = 0
l2 = 0
r1 = 0
r2 = 0
while n:
	(l, r) = [int(i) for i in input().split()]
	if l == 0:
		l1 += 1
	if l == 1:
		l2 += 1
	if r == 0:
		r1 += 1
	if r == 1:
		r2 += 1
	n -= 1
print(min(l1, l2) + min(r1, r2))


n = int(input())
countm = []
countn = []
for i in range(n):
	(m, n) = map(int, input().split())
	countm.append(m)
	countn.append(n)
(x, y, z, w) = (countm.count(0), countm.count(1), countn.count(0), countn.count(1))
print(min(x, y) + min(z, w))


class Code:

	def __init__(self):
		self.n = int(input())
		self.arr = []
		for _ in range(self.n):
			self.arr.append(list(map(int, input().split())))

	def process(self):
		cnt = [0, 0, 0, 0]
		for door in self.arr:
			if door[0] == 0:
				cnt[0] += 1
			elif door[0] == 1:
				cnt[1] += 1
			if door[1] == 0:
				cnt[2] += 1
			elif door[1] == 1:
				cnt[3] += 1
		print(min(cnt[0], cnt[1]) + min(cnt[2], cnt[3]))
code = Code()
code.process()


n = int(input())
left_dict = {'0': 0, '1': 0}
right_dict = {'0': 0, '1': 0}
for _ in range(n):
	(l, r) = map(str, input().split())
	left_dict[l] += 1
	right_dict[r] += 1
count = 0
key_l = max(left_dict, key=left_dict.get)
key_r = max(right_dict, key=right_dict.get)
count += n - left_dict[key_l] + (n - right_dict[key_r])
print(count)


n = int(input())
(lo, lc, ro, rc) = (0, 0, 0, 0)
while n:
	n -= 1
	(l, r) = map(int, input().split())
	if l:
		lo += 1
	else:
		lc += 1
	if r:
		ro += 1
	else:
		rc += 1
print(min(rc, ro) + min(lc, lo))


lc = lo = rc = ro = 0
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == 0:
		lc += 1
	else:
		lo += 1
	if b == 0:
		rc += 1
	else:
		ro += 1
print(min(lc, lo) + min(rc, ro))


def solve(doors, n):
	l = [doors[i][0] for i in range(n)]
	r = [doors[i][1] for i in range(n)]
	l0 = l.count(0)
	r0 = r.count(0)
	return min(n - l0, l0) + min(n - r0, r0)

def main():
	n = int(input())
	doors = [tuple(map(int, input().split())) for _ in range(n)]
	print(solve(doors, n))
main()


import sys
n = int(sys.stdin.readline())
left = []
right = []
for i in range(n):
	(l_door, r_door) = map(int, sys.stdin.readline().split())
	left.append(l_door)
	right.append(r_door)
open_left = sum(left)
closed_left = n - open_left
open_right = sum(right)
closed_right = n - open_right
t = min(open_left + open_right, open_left + closed_right, closed_left + open_right, closed_left + closed_right)
sys.stdout.write(str(t))


count = 0
l = []
r = []
n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	l.append(a)
	r.append(b)
c_l_1 = l.count(1)
c_l_0 = l.count(0)
c_r_1 = r.count(1)
c_r_0 = r.count(0)
if c_l_0 < c_l_1:
	count += c_l_0
else:
	count += c_l_1
if c_r_0 < c_r_1:
	count += c_r_0
else:
	count += c_r_1
print(count)


k = int(input())
lo = ro = rc = lc = 0
for _ in range(k):
	(n, m) = map(int, input().split())
	if n == 0:
		lo += 1
	else:
		lc = lc + 1
	if m == 0:
		ro += 1
	else:
		rc = rc + 1
print(min(lo, lc) + min(ro, rc))


import sys
n = int(sys.stdin.readline())
a = 0
b = 0
for i in range(n):
	(aa, bb) = map(int, sys.stdin.readline().split(' '))
	a += aa
	b += bb
sys.stdout.write('{}\n'.format(min(abs(a), n - abs(a)) + min(abs(b), n - abs(b))))


n = int(input())
l = []
m = []
time = 0
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	l.append(a)
	m.append(b)
c = l.count(0)
d = l.count(1)
e = m.count(1)
f = m.count(0)
if c == d:
	time = time + c
if c > d:
	time = time + d
if c < d:
	time = time + c
if e == f:
	time = time + e
if e > f:
	time = time + f
if e < f:
	time = time + e
print(time)


n = int(input())
kas = 0
(A, B, ans) = (0, 0, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	A += a
	B += b
	kas += 1
mn = min(A, kas - A)
mx = min(B, kas - B)
ans = mn + mx
print(ans)


n = int(input())
k = list((list(map(int, input().split())) for _ in range(n)))
k = list(zip(*k))
l = sum(k[0])
r = sum(k[1])
c = 0
if l <= int(n / 2):
	c += l
else:
	c += n - l
if r <= int(n / 2):
	c += r
else:
	c += n - r
print(c)


n = int(input())
(L, R) = ([0] * 2, [0] * 2)
for i in range(n):
	(li, ri) = [int(c) for c in input().split()]
	L[li] += 1
	R[ri] += 1
print(min(L[0], L[1]) + min(R[0], R[1]))


(b, c, d, e) = (0, 0, 0, 0)
for i in range(int(input())):
	(x, y) = map(int, input().split())
	if x == 0:
		b += 1
	else:
		c += 1
	if y == 0:
		d += 1
	else:
		e += 1
print(min(b, c) + min(d, e))


def solve(l, r, n):
	return min(n - l, l) + min(n - r, r)

def main():
	n = int(input())
	(l, r) = (0, 0)
	for _ in range(n):
		(a, b) = input().split()
		if a == '0':
			l += 1
		if b == '0':
			r += 1
	print(solve(l, r, n))
main()


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())
(lsum, rsum) = (0, 0)
for i in range(n):
	(x, y) = map(int, input().split())
	lsum += x
	rsum += y
print(min(lsum, n - lsum) + min(rsum, n - rsum))


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
	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
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
threading.Thread(target=main).start()


import sys
import math
import bisect
import itertools
import random

def main():
	L = [0] * 2
	R = [0] * 2
	n = int(input())
	for i in range(n):
		(a, b) = map(int, input().split())
		L[a] += 1
		R[b] += 1
	print(min(L) + min(R))
main()


n = int(input())
l = []
r = []
for i in range(n):
	a = [int(x) for x in input().split()]
	l.append(a[0])
	r.append(a[1])
l0 = l.count(0)
l1 = l.count(1)
r0 = r.count(0)
r1 = r.count(1)
print(min(l0, l1) + min(r0, r1))


n = int(input())
A = [0] * n
B = [0] * n
for i in range(n):
	(A[i], B[i]) = map(int, input().split())
X = sum(A)
Y = sum(B)
print(min(X, n - X) + min(Y, n - Y))


f = lambda : map(int, input().split())
n = int(input())
(l, r) = zip(*(input().split() for i in range(n)))
print(2 * n - (max(l.count('0'), l.count('1')) + max(r.count('0'), r.count('1'))))


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))


n = int(input())
lo = 0
ro = 0
lc = 0
rc = 0
for i in range(0, n):
	(li, ri) = map(int, input().split())
	if li == 1:
		lo += 1
	else:
		lc += 1
	if ri == 1:
		ro += 1
	else:
		rc += 1
ans = min(lo, lc) + min(ro, rc)
print(ans)


l0 = 0
l1 = 0
r0 = 0
r1 = 0
for m in range(int(input())):
	lr = list(map(int, input().split()))
	if lr[0] == 0:
		l0 += 1
	else:
		l1 += 1
	if lr[1] == 0:
		r0 += 1
	else:
		r1 += 1
print(min(l0, l1) + min(r0, r1))


a = []
n = int(input())
for i in range(n):
	a.append(list(map(int, input().split())))
occ1 = occ2 = 0
for i in range(n):
	if a[i][0] == 1:
		occ1 += 1
	if a[i][1] == 1:
		occ2 += 1
print(min(n - occ1, occ1) + min(n - occ2, occ2))


n = int(input())
l = []
for x in range(0, n):
	(a, b) = [int(x) for x in input().split()]
	l.append(a)
	l.append(b)
i = int(0)
j = int(0)
left = l[0:len(l):2]
right = l[1:len(l):2]
i = right.count(1)
j = left.count(1)
print(min(left.count(1), left.count(0)) + min(right.count(1), right.count(0)))


alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
l_open = 0
l_lock = 0
r_open = 0
r_lock = 0
for i in range(n):
	(l, r) = map(int, input().split())
	l_open += l
	l_lock += 1 - l
	r_open += r
	r_lock += 1 - r
print(min(l_open, l_lock) + min(r_open, r_lock))


n = int(input())
sum_l = 0
sum_r = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l:
		sum_l += 1
	if r:
		sum_r += 1
print(min(sum_r + sum_l, min(n - sum_l + n - sum_r, min(n - sum_r + sum_l, sum_r + n - sum_l))))


n = int(input())
r1 = 0
l1 = 0
r0 = 0
l0 = 0
for i in range(0, n):
	(x, y) = map(int, input().split())
	if x == 1:
		l1 += 1
	else:
		l0 += 1
	if y == 1:
		r1 += 1
	else:
		r0 += 1
t = 0
lmax = max(l1, l0)
rmax = max(r1, r0)
themax = max(lmax, rmax)
if l1 == l0:
	t += n - l0
elif l1 > l0:
	t += n - l1
else:
	t += n - l0
if r1 == r0:
	t += n - r0
elif r1 > r0:
	t += n - r1
else:
	t += n - r0
print(t)


n = int(input())
i = 0
right = []
left = []
t = 0
while i < n:
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	left.append(l)
	right.append(r)
	i = i + 1
j = 0
o = 0
c = 0
while j < len(right):
	if right[j] == 1:
		o = o + 1
	else:
		c = c + 1
	j = j + 1
t = min(o, c)
j = 0
o = 0
c = 0
while j < len(left):
	if left[j] == 1:
		o = o + 1
	else:
		c = c + 1
	j = j + 1
t = t + min(o, c)
print(t)


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
print(min(n - sum(a), sum(a)) + min(n - sum(b), sum(b)))


count = 0
n_count = 0
ni_count = 0
nii_count = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1:
		count += 1
	if a == 0:
		n_count += 1
	if b == 0:
		ni_count += 1
	if b == 1:
		nii_count += 1
x = min(count, n_count)
x += min(ni_count, nii_count)
print(x)


n = int(input())
l = []
r = []
for i in range(n):
	x = list(map(int, input().split()))
	l.append(x[0])
	r.append(x[1])
zerol = l.count(0)
onel = l.count(1)
zeror = r.count(0)
oner = r.count(1)
count = 0
if onel > zerol:
	count += zerol
elif onel <= zerol:
	count += onel
if oner > zeror:
	count += zeror
elif oner <= zeror:
	count += oner
print(count)


c = []
d = []
for i in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	c.append(a)
	d.append(b)
if c.count(0) > c.count(1):
	p = c.count(1)
else:
	p = c.count(0)
if d.count(0) > d.count(1):
	q = d.count(1)
else:
	q = d.count(0)
print(p + q)


x = int(input())
d = {0: 0, 1: 0}
d1 = {0: 0, 1: 0}
for i in range(x):
	(a, b) = map(int, input().split())
	if a == 0:
		if 0 in d:
			d[0] = d[0] + 1
		else:
			d[0] = 1
	elif a == 1:
		if 1 in d:
			d[1] = d[1] + 1
		else:
			d[1] = 1
	if b == 0:
		if 0 in d1:
			d1[0] = d1[0] + 1
		else:
			d1[0] = 1
	elif b == 1:
		if 1 in d1:
			d1[1] = d1[1] + 1
		else:
			d1[1] = 1
if d[0] > d[1] and d1[0] > d1[1]:
	print(d[1] + d1[1])
elif d[0] < d[1] and d1[0] > d1[1]:
	print(d[0] + d1[1])
elif d[0] < d[1] and d1[0] < d1[1]:
	print(d[0] + d1[0])
else:
	print(d[1] + d1[0])


import os
import sys
from math import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
x = a.count(0)
y = a.count(1)
z = min(x, y)
p = b.count(0)
q = b.count(1)
r = min(p, q)
print(z + r)


n = int(input())
d = []
for i in range(n):
	d.append([int(i) for i in input().split(' ')])
l = sum([d[i][0] for i in range(n)])
r = sum([d[i][1] for i in range(n)])
time = 0
if l < n / 2:
	time += l
else:
	time += n - l
if r < n / 2:
	time += r
else:
	time += n - r
print(time)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
from math import *
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)
MAX = 10 ** 5

def solve():
	n = takein()
	dict_1 = {1: 0, 0: 0}
	dict_2 = {1: 0, 0: 0}
	for i in range(n):
		(a, b) = takeivr()
		dict_1[a] += 1
		dict_2[b] += 1
	print(min(dict_1.values()) + min(dict_2.values()))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def isprime(n):
	if n > 2 and (not n % 2) or n == 1:
		return False
	for i in range(3, int(n ** 0.5 + 1), 2):
		if not n % i:
			return False
	return True
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


a = int(input())
left = []
rigth = []
for i in range(a):
	(b, c) = list(map(int, input().split()))
	left.append(b)
	rigth.append(c)
ans = min(left.count(0), left.count(1)) + min(rigth.count(0), rigth.count(1))
print(ans)


n = int(input(''))
l = []
for i in range(n):
	s = str(input(''))
	l.append(s.split(' '))
c1 = 0
c2 = 0
for i in range(n):
	if l[i][0] == '0':
		c1 += 1
	if l[i][1] == '0':
		c2 += 1
t = min(c1, n - c1) + min(c2, n - c2)
print(t)


n = int(input())
left_opened = 0
right_opened = 0
for _ in range(n):
	(l, r) = map(int, input().split())
	left_opened += l
	right_opened += r
left = min(left_opened, n - left_opened)
right = min(right_opened, n - right_opened)
print(left + right)


n = int(input())
left = []
right = []
for i in range(n):
	(l, r) = (int(j) for j in input().split())
	left.append(l)
	right.append(r)
l_close = left.count(0)
l_open = left.count(1)
r_close = right.count(0)
r_open = right.count(1)
value = min(l_close, l_open) + min(r_close, r_open)
print(value)


n = int(input())
left = 0
right = 0
both = 0
data = []
for i in range(n):
	data.append(list(map(int, input().split())))

def time(goal, curr):
	ans = 0
	if goal[0] != curr[0]:
		ans += 1
	if goal[1] != curr[1]:
		ans += 1
	return ans

def sim(goal):
	global data
	ans = 0
	for i in data:
		ans += time(goal, i)
	return ans
v1 = sim([0, 0])
v2 = sim([0, 1])
v3 = sim([1, 0])
v4 = sim([1, 1])
print(min([v1, v2, v3, v4]))


from collections import Counter
n = int(input())
l = []
r = []
for _ in range(n):
	(x, y) = map(int, input().split())
	l.append(x)
	r.append(y)
res = 0
lc = Counter(l)
rc = Counter(r)
if lc[0] <= lc[1]:
	res += lc[0]
else:
	res += lc[1]
if rc[0] <= rc[1]:
	res += rc[0]
else:
	res += rc[1]
print(res)


n = int(input())
cl = 0
cr = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 1:
		cl += 1
	if b == 1:
		cr += 1
print(min(cl, n - cl) + min(cr, n - cr))


n = int(input())
c1 = c2 = c3 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 1:
		c1 += 1
	if b == 1:
		c2 += 1
if c1 >= n - c1:
	c3 += n - c1
else:
	c3 += c1
if c2 >= n - c2:
	c3 += n - c2
else:
	c3 += c2
print(c3)


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)


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


n = int(input())
left = []
right = []
for i in range(n):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
t = 0
if left.count(1) < left.count(0):
	t += left.count(1)
else:
	t += left.count(0)
if right.count(1) < right.count(0):
	t += right.count(1)
else:
	t += right.count(0)
print(t)


n = int(input())
L0 = 0
R1 = 0
for i in range(n):
	(l, r) = map(int, input().split())
	if l == 0:
		L0 += 1
	if r == 1:
		R1 += 1
print(min(L0, n - L0) + min(R1, n - R1))


n = int(input())
l = []
r = []
for i in range(n):
	a = list(map(int, input().rstrip().split()))
	l += [a[0]]
	r += [a[1]]
print(min(l.count(0), l.count(1)) + min(r.count(0), r.count(1)))


n = int(input())
a = []
b = []
c = []
for i in range(n):
	a = a + list(map(int, input().split()))
for j in range(2 * n):
	if j % 2 == 0:
		b.append(a[j])
	else:
		c.append(a[j])
x = b.count(0)
y = b.count(1)
z = c.count(1)
w = c.count(0)
print(min(x, y) + min(z, w))


nums = int(input())
list1 = []
list2 = []
list3 = []
for i in range(nums):
	list1.append([int(h) for h in input().split()])
for i in list1:
	list2.append(i[0])
	list3.append(i[1])
list4 = [list2.count(1), list2.count(0), list3.count(1), list3.count(0)]
print(sum(sorted(list4)[0:2]))


L = [0, 0]
R = [0, 0]
(lc, rc) = (0, 0)
n = int(input())
for i in range(n):
	(lc, rc) = map(int, input().split())
	L[lc] += 1
	R[rc] += 1
print(min(L) + min(R))


num = int(input())
lCount = 0
rCount = 0
total = 0
for i in range(num):
	(l, r) = input().split()
	lCount += int(l)
	rCount += int(r)
status = False
if lCount + rCount == num and (lCount == num or rCount == num):
	print(0)
	status = True
if lCount > num // 2:
	total += num - lCount
else:
	total += lCount
if rCount > num // 2:
	total += num - rCount
else:
	total += rCount
if not status:
	print(total)


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


n = int(input())
l = []
r = []
for i in range(n):
	(e1, e2) = map(int, input().split())
	l.append(e1)
	r.append(e2)
a = l.count(0)
b = l.count(1)
c = r.count(0)
d = r.count(1)
ans = 0
if a > b:
	ans += b
else:
	ans += a
if c > d:
	ans += d
else:
	ans += c
print(ans)


n = int(input())
left = []
right = []
for i in range(n):
	(l, r) = list(map(int, input().split()))
	left.append(l)
	right.append(r)
if left.count(1) > left.count(0):
	left_count = left.count(0)
else:
	left_count = left.count(1)
if right.count(1) > right.count(0):
	right_count = right.count(0)
else:
	right_count = right.count(1)
print(right_count + left_count)


n = int(input())
a = []
for i in range(n):
	k = list(map(int, input().split()))
	a.append(k)
(l, r) = (0, 0)
for i in a:
	if i[0] == 1:
		l += 1
	if i[1] == 1:
		r += 1
if l > n / 2:
	l = n - l
if r > n / 2:
	r = n - r
print(l + r)


left = []
right = []
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	left.append(l)
	right.append(r)
string = []
if left.count(0) > left.count(1):
	string.append(left.count(1))
else:
	string.append(left.count(0))
if right.count(0) > right.count(1):
	string.append(right.count(1))
else:
	string.append(right.count(0))
print(sum(string) if sum(string) > 0 else '0')


ll = 0
lr = 0
rl = 0
rr = 0
t = int(input())
while t > 0:
	a = input().split()
	if a[0] == '0':
		ll += 1
	else:
		lr += 1
	if a[1] == '0':
		rl += 1
	else:
		rr += 1
	t -= 1
a = min(ll, lr)
a += min(rl, rr)
print(a)


def solution(l1):
	(left_one, right_one, left_zero, right_zero) = (0, 0, 0, 0)
	for x in l1:
		if x[0] == 0:
			left_one += 1
		else:
			left_zero += 1
		if x[1] == 0:
			right_one += 1
		else:
			right_zero += 1
	return min(left_zero, left_one) + min(right_zero, right_one)

def answer():
	n = int(input())
	l1 = []
	while n:
		l1.append([int(x) for x in input().split()])
		n -= 1
	print(solution(l1))
answer()


n = int(input())
i = 0
lz = 0
l1 = 0
r1 = 0
rz = 0
while i < n:
	(l, r) = map(int, input().split())
	if l == 0:
		lz = lz + 1
	else:
		l1 = l1 + 1
	if r == 0:
		rz = rz + 1
	else:
		r1 = r1 + 1
	i = i + 1
ans = 0
if r1 < rz:
	ans = ans + r1
else:
	ans = ans + rz
if l1 < lz:
	ans = ans + l1
else:
	ans = ans + lz
print(ans)


n = int(input())
t = 0
arr = []
brr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append(a)
	brr.append(b)
a_0 = arr.count(0)
a_1 = arr.count(1)
if a_0 >= a_1:
	t += n - a_0
else:
	t += n - a_1
b_0 = brr.count(0)
b_1 = brr.count(1)
if b_0 >= b_1:
	t += n - b_0
else:
	t += n - b_1
print(t)


n = int(input())
l = []
r = []
for i in range(n):
	(k, j) = map(int, input().split())
	l.append(k)
	r.append(j)
(a, b) = (l.count(1), r.count(1))
if a == n:
	print(n - max(r.count(1), r.count(0)))
	exit()
if b == n:
	print(n - max(l.count(1), l.count(0)))
	exit()
x = 0
if l.count(1) >= l.count(0):
	x += l.count(0)
else:
	x += l.count(1)
if r.count(1) >= r.count(0):
	x += r.count(0)
else:
	x += r.count(1)
print(x)


r = []
l = []
for i in range(int(input())):
	(b, a) = map(int, input().split())
	r.append(a)
	l.append(b)
c = 0
if r.count(0) <= r.count(1):
	c += r.count(0)
else:
	c += r.count(1)
if l.count(0) <= l.count(1):
	c += l.count(0)
else:
	c += l.count(1)
print(c)


n = int(input())
left = 0
right = 0
for i in range(n):
	(l, r) = input().split()
	if l == '1':
		left += 1
	if r == '1':
		right += 1
print(min(n - left, left) + min(n - right, right))


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())
(nL, nR) = (0, 0)
for _ in range(n):
	(x, y) = map(int, input().split())
	nL += x
	nR += y
print(min(nL, n - nL) + min(nR, n - nR))


import sys
n = int(input())
c1 = 0
c2 = 0
for i in range(n):
	(x, y) = [int(i) for i in input().split(' ')]
	if x == 1:
		c1 += 1
	if y == 1:
		c2 += 1
print(min(c2, n - c2) + min(c1, n - c1))


n = int(input())
lo = 0
lc = 0
ro = 0
rc = 0
for i in range(n):
	(x, y) = map(int, input().split(' '))
	if x:
		lc += 1
	else:
		lo += 1
	if y:
		rc += 1
	else:
		ro += 1
print(min([lo + ro, lo + rc, lc + ro, lc + rc]))


a = input
left_close = 0
left_open = 0
right_close = 0
right_open = 0
for i in range(int(a())):
	b = [int(i) for i in input().split()]
	if b[0] == 0:
		left_close += 1
	elif b[0] == 1:
		left_open += 1
	if b[1] == 0:
		right_close += 1
	elif b[1] == 1:
		right_open += 1
print(min(left_close + right_open, left_open + right_close, left_close + right_close, right_open + left_open))


right = []
left = []
second = 0
for i in range(int(input())):
	m = input()
	left.append(m[0])
	right.append(m[2])
if right.count('0') <= right.count('1'):
	second += right.count('0')
else:
	second += right.count('1')
if left.count('0') <= left.count('1'):
	second += left.count('0')
else:
	second += left.count('1')
print(second)


n = int(input())
lcount = 0
rcount = 0
for i in range(0, n):
	ab = input().split()
	if ab[0] == '0':
		lcount += 1
	if ab[1] == '0':
		rcount += 1
print(min(lcount, n - lcount) + min(rcount, n - rcount))


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())
i = 0
c00 = c01 = c10 = c11 = 0
while i < n:
	l = [int(x) for x in input().split()]
	if l[0] == 0:
		c00 += 1
	else:
		c01 += 1
	if l[1] == 0:
		c10 += 1
	else:
		c11 += 1
	i += 1
print(min(c00, c01) + min(c10, c11))


q = w = e = r = 0
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == 0:
		q += 1
	else:
		w += 1
	if b == 0:
		e += 1
	else:
		r += 1
print(min(q, w) + min(e, r))


def Sol(arrl, arr):
	cl = min(arrl.count(0), arrl.count(1))
	cr = min(arr.count(1), arr.count(0))
	print(cl + cr)
	return
arrl = []
arr = []
for t in range(int(input())):
	test = list(map(int, input().split()))
	arrl.append(test[0])
	arr.append(test[1])
Sol(arrl, arr)


c = 0
d = 0
a = 0
z = int(input())
for i in range(z):
	x = list(map(int, input().split()))
	if x[0] == 0:
		c += 1
	if x[1] == 0:
		d += 1
if c >= z / 2:
	a = z - c
else:
	a += c
if d >= z / 2:
	a += z - d
else:
	a += d
print(a)


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)


n = int(input())
countL = [0, 0]
countR = [0, 0]
for i in range(n):
	a = input().split(' ')
	if a[0] == '0':
		countL[0] += 1
	else:
		countL[1] += 1
	if a[1] == '0':
		countR[0] += 1
	else:
		countR[1] += 1
print(min(countL) + min(countR))


n = int(input())
lst = list()
for i in range(n):
	lst.append(list(map(int, input().split())))
open_left = 0
open_right = 0
for i in range(n):
	if lst[i][0] == 1:
		open_left += 1
	if lst[i][1] == 1:
		open_right += 1
print(min(open_left, n - open_left) + min(open_right, n - open_right))


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	n = read_int()
	L = []
	R = []
	for i in range(n):
		(l, r) = read_ints()
		L.append(l)
		R.append(r)
	l1 = L.count(1)
	r1 = R.count(1)
	print(min(l1, n - l1) + min(r1, n - r1))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


from collections import defaultdict
left = defaultdict(int)
right = defaultdict(int)
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	left[l] += 1
	right[r] += 1
print(n - max(left.values()) + n - max(right.values()))


a = int(input())
cnt = 0
vnt = 0
for i in range(a):
	(b, c) = map(int, input().split())
	cnt += b
	vnt += c
	x = min(a - cnt, cnt)
	x += min(a - vnt, vnt)
print(x)


n = int(input())
l = []
r = []
lo = 0
ro = 0
for i in range(n):
	(L, R) = map(int, input().split())
	if L == 1:
		lo += 1
	if R == 1:
		ro += 1
	l.append(L)
	r.append(R)
secs = min(lo, n - lo)
secs += min(n - ro, ro)
print(secs)


n = int(input())
l = 0
r = 0
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == 1:
		l += 1
	if b == 1:
		r += 1
print(min(l, n - l) + min(r, n - r))


n = int(input())
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
lz = 0
rz = 0
for i in range(n):
	if arr[i][0] == 0:
		lz = lz + 1
	if arr[i][1] == 0:
		rz = rz + 1
print(min(lz, n - lz) + min(rz, n - rz))


n = int(input())
right = 0
left = 0
for i in range(n):
	cupboard = [int(x) for x in input().split(' ')]
	right += cupboard[1]
	left += cupboard[0]
print(min(left, n - left) + min(right, n - right))


n = int(input())
(sumA0, sumA1) = (0, 0)
(sumB0, sumB1) = (0, 0)
for i in range(n):
	(x, y) = map(int, input().split())
	if x == 0:
		sumA0 += 1
	else:
		sumA1 += 1
	if y == 0:
		sumB0 += 1
	else:
		sumB1 += 1
print(min(sumA0, sumA1) + min(sumB0, sumB1))


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))