Harryxun/stf_run huggingface dataset:
W,H,N = map(int,input().split())

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     balck_S += 0
     x1 = x1
    elif(x1 <= x <= x2):
     black_S += (x-x1)*(y2-y1)
     x1 = x
    elif(x2 < x):
     black_S = W*H
     break      
  elif(a == 2):
    if(x < x1):
     black_S = W*H
     break
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     x2 = x2   
  elif(a == 3):
    if(y < y1):
     balck_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     break     
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     break
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     y2 = y2
  #print(x1,x2,y1,y2,black_S)
  
print(rectangle_S - black_S)


### FIXED CODE ###

W,H,N = map(int,input().split())

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0
judge = 1 #1:黒部分全部でない,0:黒部分全部

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     black_S += 0
     x1 = x1
    elif(x1 <= x <= x2):
     black_S += (x-x1)*(y2-y1)
     x1 = x
    elif(x2 < x):
     black_S = W*H
     break      
  elif(a == 2):
    if(x < x1):
     black_S = W*H
     judge = 0 #黒全部
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     #x2 = x2   
  elif(a == 3):
    if(y < y1):
     black_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     judge = 0   
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     judge = 0 #黒全部
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     #y2 = y2

if(judge == 0):
  print(0)
else:
  print(rectangle_S - black_S)
n = int(input())
a = list(map(int, input().split()))
ra = []
for i in xrange(n):
    ra.append((i+1)*30000)
rb = []
for i in xrange(n):
    rb.append((n-i)*30000+a[i])
print ' '.join(map(str,ra))
print ' '.join(map(str,rb))


### FIXED CODE ###

N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
    i=int(i)
    b[i-1]+=c
    c+=1

for i in a:
    print(i,end=" ")
print("")
for i in b:
    print(i,end=" ")
def main():
    n = int(input())
    s = 0
    while n != 0:
        s += n%10
        n =int(n/10)
    if s%9==0:
        print('Yes')
    else:
        print('No')
        
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
    n = input()

    s = 0

    while n:
        s += int(n[-1])
        n = n[:-1]
    
    if s%9==0:
        print('Yes')
    else:
        print('No')
        
if __name__=='__main__':
    main()
x = input
print (x*x*x)


### FIXED CODE ###

x = input()
x = int(x)
print (x*x*x)
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    for i in range(pow(10,N-1)-1,pow(10,N)):
        f=True
        for j in range(M):
            if not(str(i)[s[j]-1]==str(c[j])):f=False
            if(not f):break
        if(f):
            print(i)
            return
    print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    if(pow(10,N-1)==1):x=0
    else:x=pow(10,N-1)
    for i in range(x,pow(10,N)):    
        f=True
        for j in range(M):
            if not(str(i)[s[j]-1]==str(c[j])):f=False
            if(not f):break
        if(f):
            print(i)
            return
    print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
import sys
line=[int(c) for c in sys.stdin.rstrip('/n')]
length=len(line)
while True:
  line2=[]
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
    elif line[i]!=2:
      line2.append(line[i])
  if len(line)!=0 and line[len(line)-1]!=2:
      line2.append(line[len(line)-1])
  if 2 in line:
    line=[i for i in line2]
  else:
    break
print(length-len(line))

### FIXED CODE ###

s=str(input())
if s.count('1')>s.count('0'):
    print(s.count('0')*2)
else:
    print(s.count('1')*2)
N,K = map(int, input().split())
p = list(map(int, input().split()))

st = 0
i = 0
sa = 0
while i+K < N:
    sa += p[i+K]-p[i]
    if sa > 0:
        st = i+1
        sa = 0
    i += 1

psum = p[st:st+K]
for i in range(K):
    psum[i] = (psum[i]+1)/2
print(sum(psum)

### FIXED CODE ###

N,K = map(int, input().split())
p = list(map(int, input().split()))

st = 0
i = 0
sa = 0
while i+K < N:
    sa += p[i+K]-p[i]
    if sa > 0:
        st = i+1
        sa = 0
    i += 1

psum = p[st:st+K]
for i in range(K):
    psum[i] = (psum[i]+1)/2
print(sum(psum))
a = input.split()
print(''.join(a))

### FIXED CODE ###

a = input().split()
print(a[1] + a[0])
a,b=map(int,input().split())
c=a*b
if c%2==0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

r,g,b=map(int,input().split())
if (100*r+10*g+b)%4==0:
    print('YES')
else:
    print('NO')
import functools
import math
n = int(input())
a = list(map(int,input().split()))
gcd = []
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcd.append(functools.reduce(math.gcd, b))
print(max(gcd))

### FIXED CODE ###


import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
r = [0]
l = [0]
for N in range(n):
	r.append(fractions.gcd(r[N],a[N]))
	l.append(fractions.gcd(l[N],a[n - N - 1]))
for i in range(n):
	gcds = max(gcds,(fractions.gcd(r[i],l[n - i - 1])))
print(gcds)
a, b = map(int, input().split())
c = 0
c　= (a * b) % 2
if c == 0:
  print('Even')
else:
  print('Odd')


### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = (a * b) % 2
if c == 0:
  print("Even")
else :
  print("Odd")
import heapq

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sub1 = 0
li = []

for i in range(n):
    if a[i] > b[i]:
        sub1 += a[i] - b[i]
    else:
        heapq.heappush(li, a[i] - b[i])

for i in range(sub1):
    x = -heapq.heappop(li)
    if x >= 2:
        heapq.heappush(li, x-2)
    else:
        print('No')
        exit()

print('Yes')


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

sub1 = 0
sub2 = 0

for i in range(n):
    if a[i] > b[i]:
        sub1 += a[i] - b[i]
    else:
        sub2 += (b[i] - a[i]) // 2

if sub1 <= sub2:
    print('Yes')
else:
    print('No')
a,b = map(int ,input().split())
l=[1,2,3]
l.pop(l.index(a))
l.pop(l.index(b))
print(l[0])

### FIXED CODE ###

a = int(input())
b = int(input())

l=[1,2,3]
l.pop(l.index(a))
l.pop(l.index(b))
print(l[0])
import time
from bisect import *
from random import randint
start = time.time()
def solve():
  D = int(input())
  C = list(map(int, input().split()))
  S = [list(map(int, input().split())) for _ in range(D)]

  ans = [0]*D
  points = [0]*26
  dates = [[-1] for _ in range(26)]
  last = [-1]*26
  for d in range(D):
    for i in range(26):
      points[i] = S[d][i]+C[i]*(d-last[i])*(d-last[i]+1)//2
    maxi = 0
    for i in range(26):
        if points[i]>maxi:
            con = i
            maxi = points[i]
    ans[d] = con+1
    last[con] = d
  score = 0
  for d in range(D):
    dates[ans[d]].append(d)
    score += S[d][ans[d]]
    last[ans[d]] = d
    for j in range(26):
        score -= C[j]*(d-last[j])
  for i in range(26):
    dates[i].append(D)
  while time.time()-start<1.8:
    d = randint(0,D-1)
    after = randint(0,25)
    before = ans[d]
    ans[d] = after
    insort_right(dates[after],d)
    new_score = score
    new_score += S[d][after]-S[d][before]
    ind_bef = bisect_right(dates[before],d)-1
    new_score -= C[before]*(dates[before][ind_bef]-dates[before][ind_bef-1])*(dates[before][ind_bef+1]-dates[before][ind_bef])
    ind_aft = bisect_right(dates[after],d)-1
    new_score += C[after]*(dates[after][ind_aft]-dates[after][ind_aft-1])*(dates[after][ind_aft+1]-dates[after][ind_aft])
    dates[before].pop(ind_bef)
    if new_score>score:
      score = new_score
    else:
      ans[d] = before
  return ans
print(*solve(),sep='\n')

### FIXED CODE ###

def solve():
  D = int(input())
  C = list(map(int, input().split()))
  S = [list(map(int, input().split())) for _ in range(D)]

  ans = [1]*D
  
  return ans
print(*solve(),sep='\n')
S = input()
S[3] = 8
print(S)

### FIXED CODE ###

S = input()
print(S[:3] + "8" + S[4:])
print s if int(raw_input()) >= 3200 else "red" 

### FIXED CODE ###

n = int(raw_input())
s = raw_input().rstrip()
print s if n >= 3200 else "red"
S = input()
T = input()

for i in reversed(range(len(S) - len(T) + 1)):
    if checker(S[i:(i + len(T)), T]):
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        exit()
print('UNRESTORABLE')
exit()
def checker(s, t):
	for i in range(len(s)):
		if s[i] != "?" and s[i] != t[i]:
			return False
	return True

### FIXED CODE ###

def main():
	s = input()
	t = input()
 
	for i in reversed(range(len(s) - len(t) + 1)):
		if checker(s[i:(i + len(t))], t):
			s = s.replace("?", "a")
			print(s[:i] + t + s[i+len(t):])
			return
	print("UNRESTORABLE")
 
def checker(s, t):
	for i in range(len(s)):
		if s[i] != "?" and s[i] != t[i]:
			return False
	return True
 
if __name__ == '__main__':
	main()
a. b = map(int, input().split())
print((a + b) % 24)

### FIXED CODE ###

a, b = map(int, input().split())
print((a + b) % 24)
input1 = input()
print 1000 - int(input1) % 1000

### FIXED CODE ###

input1 = input()
result = 1000 - int(input1) % 1000
if result == 1000:
    print(0)
else:
    print(result)
N=int(input)
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for i in range(x,N):
      ans_can+=A[1][i]
    max_candidate.append(ans_can)
print(max(max_candidate))


### FIXED CODE ###

N=int(input())
A=[]
for i in range(2):
    A_ = list(map(int, input().split()))
    A.append(A_)
    A[i].append(0)
A.append([0]*(N+1))
# A=[[0]*(N+1),[0]*(N+1),[0]*(N+1)]
# A[0]=list(map(int,input().split()))
# A[1]=list(map(int,input().split()))

max_candidate=[]
x=0
y=0
ans=A[0][0]
for i in range(N):
  if A[y][x+1]>=A[y+1][x]:
    ans+=A[0][x+1]
    x+=1
  #下方向移動の方が値が大きい場合、最大値の候補としてリストに追加
  else:
    ans_can=ans
    for j in range(x,N):
      ans_can+=A[1][j]
    max_candidate.append(ans_can)
    ans+=A[0][x+1]
    x+=1
print(max(max_candidate))
S, T = input().split()
A, B = map(int, input().split())
U = input()

data = {
    str(S): A,
    str(T): B,
}

data[f'{U}'] -= 1

s = data[str(S)]
t = data[str(T)]
print(f'{s} {t}')

### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()

data = {
    str(S): A,
    str(T): B,
}

data[str(U)] -= 1

s = data[str(S)]
t = data[str(T)]
print('{} {}'.format(s, t))
#f
N = int(input())
X = [0] * N
ans = 0
for i in range(N-1):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    if x > y: x, y = y, x
    ans += (y - x) * (N - y + x + 1)
    X[x] += 1
    X[y] += 1
for i, x in enumerate(X):
    ans += (i + 1) * (N - i) * (2 - x)
print(ans // 2)0

### FIXED CODE ###

#f problem
import math
import re
import os
import sys
N = int(input())
X = [0] * N
ans = 0
for i in range(N-1):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    #take +1 if...
    if x > y: x, y = y, x
    ans += (y - x) * (N - y + x + 1)
    X[x] += 1
    X[y] += 1
    #the pivot off
for i, x in enumerate(X):
    ans += (i + 1) * (N - i) * (2 - x)
print(ans // 2)#//2 -1 possible.  # solution master
def prime(i):
    if i == 1:
        return False
    if (i > 2) & (i % 2 == 0):
        return False
    for j in range(3, int(i**(0.5)) + 1, 2):
        if i % j == 0:
            return False
    return True



q = int(input())
for _ in range(q):
    ans = 0
    l, r = map(int, input().split())
    while (i <= r):
        if prime(i) & prime(int(i+1)//2):
            ans += 1
            i += 4
        else:
            i += 2
    print(ans)

### FIXED CODE ###

def Eratosthenes(n):
    prime_list = [True for _ in range(n + 1)]
    prime_list[0] = False
    prime_list[1] = False
    for j in range(4, n + 1, 2):
        prime_list[j] = False
    prime_list[2] = True
    for i in range(3, int(n ** 0.5) + 1, 2):
        if prime_list[i]:
            for j in range(i * 2, n + 1, i):
                prime_list[j] = False
    return prime_list


def prime_2017(prime_list):
    prime_2017_list = [True for _ in range(len(prime_list))]
    for i in range(len(prime_list)):
        if i <= 2:
            prime_2017_list[i] = False
        elif prime_list[i]:
            if not prime_list[(i + 1) // 2]:
                prime_2017_list[i] = False
        else:
            prime_2017_list[i] = False
    return prime_2017_list

q = int(input())
num_list = []
num_max = 0
for _ in range(q):
    l, r = map(int, input().split())
    num_list.append([l, r])
    num_max = max(r, num_max)
prime_list = Eratosthenes(num_max)
prime_2017_list = prime_2017(prime_list)
prime_num = [0 for _ in range(num_max + 1)]
for i in range(num_max):
    prime_num[i + 1] = prime_num[i] + prime_2017_list[i + 1]

for l, r in num_list:
    print(prime_num[r] - prime_num[l - 1])
def prod(li, MOD):
    ret = 1
    for a in li:
        ret *= a
        ret %= MOD
    return ret

N, K = map(int, input().split())
MOD = 1_000_000_007
aaa = list(map(int, input().split()))
if N == K:
    print(prod(aaa, MOD))
    exit()
if K == 1:
    print(max(aaa) % MOD)
    exit()
aaa.sort(key=lambda x : abs(x))
if sum(a < 0 for a in aaa[-K:]) % 2 == 0:
    print(prod(aaa[-K:], MOD))
else:
    if all(a <= 0 for a in aaa):
        print(prod(aaa[:K], MOD))
    elif all(a <= 0 for a in aaa[:-K]):
        for a in aaa[-K:][::-1]:
            if a > 0:
                break
        bbb = aaa[-K:].remove(a)
        bbb.append(aaa[-(K + 1)])
        print(prod(bbb, MOD))
    elif all(a > 0 for a in aaa[:-K]):
        for a in aaa[-K:][::-1]:
            if a < 0:
                break
        bbb = aaa[-K:].remove(a)
        bbb.append(aaa[-(K + 1)])
        print(prod(bbb, MOD))
    else:
        bbb = aaa[-(K-1):]
        for a in aaa[:-K][::-1]:
            if a * aaa[-K] <= 0:
                bbb.append(a)
                break
        print(prod(bbb, MOD))


### FIXED CODE ###

def prod(li, MOD):
    ret = 1
    for a in li:
        ret *= a
        ret %= MOD
    return ret

N, K = map(int, input().split())
MOD = 1_000_000_007
aaa = list(map(int, input().split()))
if N == K:
    print(prod(aaa, MOD))
    exit()
aaa.sort(key=lambda x : abs(x))
if sum(a < 0 for a in aaa[-K:]) % 2 == 0:
    print(prod(aaa[-K:], MOD))
else:
    if all(a <= 0 for a in aaa):
        bbb = aaa[:K]
    else:
        try:
            x1, y1 = min([a for a in aaa[-K:] if a > 0]), min([a for a in aaa[:-K] if a < 0])
        except:
            x1, y1 = 1, 0
        try:
            x2, y2 = max([a for a in aaa[-K:] if a < 0]), max([a for a in aaa[:-K] if a >= 0])
        except:
            x2, y2 = 1, 0
        bbb = aaa[-K:]
        if abs(x2 * y1) > abs(x1 * y2):
            bbb.remove(x1)
            bbb.append(y1)
        else:
            bbb.remove(x2)
            bbb.append(y2)
    print(prod(bbb, MOD))
n,ans = str(input()).split()
if int(n)<10:
    ans = int(ans) - (100*(10-int(n)))
if ans<0:
    ans=0
print(int(ans))

### FIXED CODE ###

n,ans = str(input()).split()
if int(n)<10:
    ans = int(ans) + (100*(10-int(n)))
print(int(ans))
n, k = map(int, input().split())
k += 1
s = "01" + input().rstrip()
ans = 0
i = 0
left = 2
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)

### FIXED CODE ###

A, B = map(int, input().split())

AB = []
AB += [A, B]

def push(AB):
  if AB[0] >= AB[1]:
    i = 0
  else:
    i = 1
  ret = AB[i]
  AB[i] -= 1
  return ret

s = 0
for _ in range(2):
	s += push(AB)

print(s)
n = int(raw_input())
    ls = []
    try:
        ls = map(int,raw_input().split())
        mi = min(ls)
        ma = max(ls)
        su = sum(ls)
        print "%d %d %d" % (mi,ma,su)

### FIXED CODE ###

n = int(raw_input())

ls = map(int,raw_input().split())
mi = min(ls)
ma = max(ls)
su = sum(ls)
print "%d %d %d" % (mi,ma,su)
from operator import mul
from functools import reduce
from collections import Counter
from copy import deepcopy
import sys
sys.setrecursionlimit(100000)

def main():
    nCr = {}
    def cmb(n, r):
        if r == 0 or r == n: return 1
        if r == 1: return n
        if (n,r) in nCr: return nCr[(n,r)]
        nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
        return nCr[(n,r)]

    n = int(input())
    A = [int(x) for x in input().split()]
    a_c= Counter(A)
    cnt = 0
    for a in A:
        a_c_c = deepcopy(a_c)
        a_c_c[a] = a_c_c[a] - 1
        values = a_c_c.values()
        val_cnt = Counter(values)
        cnt = {cmb(k, 2) * v  if k > 1 else 0 for k, v in val_cnt.items()}
        print(sum(cnt))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
 
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        ans = (cnt - (a_c[a]-1))
        print(ans)
 
if __name__ == '__main__':
    main()
import math
n = input()
a = list(map(int, input().split( )))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

### FIXED CODE ###

print(input().count("1"))
import sys
import heapq

sys.setrecursionlimit(10 ** 6)

n = int(input())
a, b = [], []
used = [False] * (n + 1)
used[n] = True
for i in range(n):
    a_i, b_i = map(int, input().split())
    heapq.heappush(a, (-a_i, -b_i, i))
    heapq.heappush(b, (-b_i, -a_i, i))

flag = True
ans = 0
for _ in range(n):
    i, j = n, n
    while used[i]:
        a_i, b_i, i = heapq.heappop(a)
    while used[j]:
        b_j, a_j, j = heapq.heappop(b)
    if abs(a_i - a_j) > abs(b_i - b_j):
        if flag:
            ans -= a_i
        else:
            ans += b_i
        used[i] = True
        heapq.heappush(b, (b_j, a_j, j))
    else:
        if flag:
            ans -= a_j
        else:
            ans += b_j
        used[j] = True
        heapq.heappush(b, (b_i, a_i, i))
    flag = not flag
print(ans)

### FIXED CODE ###

n = int(input())
happy, a, b = [], [], []
for i in range(n):
    happy.append(tuple(map(int, input().split())))
happy.sort(key=lambda x: x[0] + x[1], reverse=True)
ans = 0
for i, (a, b) in enumerate(happy):
    if i % 2 == 0:
        ans += a
    else:
        ans -= b
print(ans)
N = int(input())
S = list(input())

middle = S[1:-1]
white = middle.count('.')
black = middle.count('#')

if (S.count('.') == 0 or S.count('#') == 0) or ((S.count('.') == 1 and S[0] == '.') or (S.count('#') == 1 and S[-1] == '#')):
  print('0')
else:
  if white < black:
    if S[-1] == '.':
      print(white+1)
    else:
      print(white)
  else:
    if S[0] == '#':
      print(black+1)
    else:
      print(black)


### FIXED CODE ###

S = [ i for i in input()]

if len(S) <= 1:
  print(0)
  exit()

zerone = ['0', '1']
a = 0
b = 0

def is_even(num):
  return 0  if num % 2 == 0 else 1

for i in range(len(S)):
  if S[i] != zerone[is_even(i)]:
    a += 1
  else:
    b += 1

print(a if a < b else b)
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0) #数合わせ
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
        
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
        
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
half=n//2
count_odd=[]
count_even=[]

for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        count_odd.append([rensa_odd,now_odd])
        now_odd=odd2[i]
        rensa_odd=1
count_odd.append([rensa_odd,now_odd])

for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        count_even.append([rensa_even,now_even])
        now_even=even2[i]
        rensa_even=1
count_even.append([rensa_even,now_even])
count_odd2=sorted(count_odd,reverse=True)
count_even2=sorted(count_odd,reverse=True)

if check==0:
    print(half)
else:
    if count_odd2[0][1]!=count_even2[0][1]: #最頻値が違う
        print((half-count_odd2[0][0])+(half-count_even2[0][0]))
    else:
        if len(count_odd2)==1:
            print((half-count_odd2[0][0])+(half-count_even2[1][0]))
        elif len(count_even2)==1:
            print((half-count_odd2[1][0])+(half-count_even2[0][0]))
        else:
            print(min((half-count_odd2[0][0])+(half-count_even2[1][0]),(half-count_odd2[1][0])+(half-count_even2[0][0])))

### FIXED CODE ###

n=int(input())
v=list(map(int,input().split()))
v.insert(0,0) #数合わせ
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
        
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
        
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
half=n//2
count_odd=[]
count_even=[]

for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        count_odd.append([rensa_odd,now_odd])
        now_odd=odd2[i]
        rensa_odd=1
count_odd.append([rensa_odd,now_odd])

for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        count_even.append([rensa_even,now_even])
        now_even=even2[i]
        rensa_even=1
count_even.append([rensa_even,now_even])
count_odd2=sorted(count_odd,reverse=True)
count_even2=sorted(count_even,reverse=True)
#print(count_even2)

if check==0:
    print(half)
else:
    if count_odd2[0][1]!=count_even2[0][1]: #最頻値が違う
        print((half-count_odd2[0][0])+(half-count_even2[0][0]))
    else:
        if len(count_odd2)==1:
            print((half-count_odd2[0][0])+(half-count_even2[1][0]))
        elif len(count_even2)==1:
            print((half-count_odd2[1][0])+(half-count_even2[0][0]))
        else:
            print(min((half-count_odd2[0][0])+(half-count_even2[1][0]),(half-count_odd2[1][0])+(half-count_even2[0][0])))