Harryxun/stf_run huggingface dataset:
n, m = map(int,input().split())

a = [""]*3
rep = []
ans = 0

for i in range(m):
    s,c = input().split()
    if s in rep:
        if c != a[int(s)-1]:
            ans = -1
    rep.append(s)
    a[int(s)-1] = c

if ans == -1:
    print(ans)
else:
    if a[0] == "":
        if a[1] == "":
            print(int(a[2]))
        elif a[2]=="":
            a[2]="0"
            print("".join(a))
    else:
        if a[1] == "":
            print(0)
        elif a[2]=="":
            a[2]="0"
            print("".join(a))
            

### FIXED CODE ###

n, m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

ans = -1

for i in range(1000):
    s_i = str(i)
    if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc):
        ans = i
        break

print(ans)
from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = ( dx, dy) if ma[ty+dy][tx+dx] else (0,0)
                kdx, kdy = (-dx,-dy) if ma[ky-dy][kx-dx] else (0,0)
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                if c+1 > 100: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    prf = LineProfiler()
    prf.add_function(main)
    prf.runcall(main)
    prf.print_stats()
    # main()


### FIXED CODE ###

# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[False]+[bool(1-int(a)) for a in stdin.readline().split()]+[False] for i in range(H)]
        ma = [[False]*(W+2)] + ma + [[False]*(W+2)]
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            if c+1 > 100: continue
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = ( dx, dy) if ma[ty+dy][tx+dx] else (0,0)
                kdx, kdy = (-dx,-dy) if ma[ky-dy][kx-dx] else (0,0)
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()
N,i = map(int,input())
print(N-i+1)


### FIXED CODE ###

N,i = map(int,input().split())
print(N-i+1)
n = int(input())
xds = [tuple(map(int, input().split())) for _ in range(n)]
xds.sort()

xds.insert(0, (-1000000001, 2000000004))
n += 1

def make_blocks(i):
    x, d = xds[i]
    right = x + d
    res = []
    nexti = i + 1
    while(nexti < n):
        xn, dn = xds[nexti]
        if xn < right:
            l, lasti = make_blocks(nexti)
            res.append(l)
            nexti = lasti + 1
        else:
            return res, nexti - 1
    return res, n - 1

l, _ = make_blocks(0)

def count(l):
    ans = 1
    for ll in l:
        ans *= 1 + count(ll)
    return ans

print(count(l))


### FIXED CODE ###

# hmm...
from sys import setrecursionlimit
setrecursionlimit(10000000)

n = int(input())
xds = [tuple(map(int, input().split())) for _ in range(n)]
xds.sort()

xds.insert(0, (-1000000001, 2000000004))
n += 1

def make_blocks(i):
    x, d = xds[i]
    right = x + d
    res = []
    nexti = i + 1
    while(nexti < n):
        xn, dn = xds[nexti]
        if xn < right:
            l, lasti = make_blocks(nexti)
            res.append(l)
            nexti = lasti + 1
        else:
            return res, nexti - 1
    return res, n - 1

l, _ = make_blocks(0)

def count(l):
    ans = 1
    for ll in l:
        ans = ans * (1 + count(ll)) % 998244353
    return ans

print(count(l))
W, H, x, y = map(int,input().split())
buf_x = W-x
buf_y = H-y
if buf_x >= x:
  ver_area = H*x
else:
  ver_area = H*buf_x
if buf_y >= y:
  hori_area = W*y
else:
  hori_area = W*buf_y

if x*2 == W and y*2 ==H:
  print(float(W*H/2),1)
elif x*2 == W:
  print(float(W*H/2),0)
elif y*2 == H:
  print(float(W*H/2),0)
else:
  if W*y == H*x:
    print(float(W*H/2),0)
  elif x*H == W*(H-Y):
    print(float(W*H/2),0)
  else:
    if ver_area <= hori_area:
      print(float(hori_area),0)
    else:
      print(float(ver_area),0)


### FIXED CODE ###

W, H, x, y = map(int,input().split())
buf_x = W-x
buf_y = H-y
if buf_x >= x:
  ver_area = H*x
else:
  ver_area = H*buf_x
if buf_y >= y:
  hori_area = W*y
else:
  hori_area = W*buf_y

if x*2 == W and y*2 ==H:
  print(float(W*H/2),1)
else:
  print(float(W*H/2),0)
N = int(input())
H = map(int, input().split())

dp = [] * N
dp[0] = 0

for i in range(1, N):
  tmp1 = dp[i-1] + abs(H[i] - H[i-1])
  tmp2 = dp[i-2] + abs(H[i] - H[i-2]) if i > 1 else 2**64
  dp[i] = min(tmp1, tmp2)
  
print(dp[N-1])
  
    
             
  


### FIXED CODE ###


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

dp = [0] * N
dp[0] = 0

for i in range(1, N):
  tmp1 = dp[i-1] + abs(H[i] - H[i-1])
  tmp2 = dp[i-2] + abs(H[i] - H[i-2]) if i > 1 else 2**64
  dp[i] = min(tmp1, tmp2)
  
print(dp[N-1])
a, b, c, d = map(int, input().split())

if abs(c-a) <= d:
  print "Yes"
  exit(0)
elif abs(a-b) <= d and abs(c-b) <= d:
  print "Yes"
  exit(0)
else:
  print "No"
  exit(0)

exit(0)

### FIXED CODE ###

a, b, c, d = map(int, input().split())

if abs(c-a) <= d:
  print("Yes")
  exit(0)
elif abs(a-b) <= d and abs(c-b) <= d:
  print("Yes")
  exit(0)
else:
  print("No")
  exit(0)

exit(0)
import math

n, m, k = list(map(int, input().split()))

s = 0

for i in range(k+1):
    s += (math.factorial(n-i) // (math.factorial(n-2*i) * math.factorial(i)) ) * m * ((m-1) ** (n-i-1))

print(s % 998244353)


### FIXED CODE ###

import math

n, m, k = list(map(int, input().split()))

MOD=998244353

fact = [0] * (n+1)
inv = [0] * (n+1)
factinv = [0] * (n+1)

fact[0]=fact[1]=1
inv[1]=1
factinv[0]=factinv[1]=1

for i in range(2,n+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
    factinv[i] = factinv[i-1] * inv[i] % MOD

def cbn(n, k, fact, factinv, MOD):
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power(x * x % MOD, n // 2, MOD) % MOD

s = 0
for i in range(k+1):
    s += cbn(n-1, i, fact, factinv, MOD) * m * power(m-1, n-1-i, MOD)

print(s % MOD)
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 文字列の入力
s = input()
   if a*b%2==0
# 出力
   print("Even")
   else:
    print("Odd")
    
  


### FIXED CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
if a*b%2 == 0:
# 出力
   print("Even")
else:
   print("Odd")
# coding: utf-8
# Your code here!
# from collections import Counter
# from functools import *

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

n,k=LI()
a=LI()
b=[]
visited=[-1]*n


now=1
for i in range(k):
    nxt=a[now-1]
    b.append(nxt)
    if visited[nxt-1]==-1:
        visited[nxt-1]=i+1
    else:
        mod=(visited[nxt-1],i+1)
        break
    now=nxt
    # visited[now]
    # print(i,now)
# print(now,mod)

ml,mr=mod
k=(k-ml)%(mr-ml)
if k==0:
    k+=(mr-ml)
k+=ml
# print(k)

now=1
for i in range(k):
    now=a[now-1]
print(now)


### FIXED CODE ###

n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))

MAX_N=2*10**5
b=[1]
visited=[-1]*(n+10)
for i in range(1,2*MAX_N+1):
    nxt=a[b[-1]]
    b.append(nxt)
        
if k<=n:
    print(b[k])
    exit()
# print(b)  
for i,bi in enumerate(b):
    if visited[bi]==-1:
        visited[bi]=i
    else:
        m=i-visited[bi]
        l=visited[bi]
        break
k=k%m

while k<n:
    k+=m
print(b[k])
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "Yes"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i != 0 and S[i-1][j] == "#"):
        continue
      if(i != H and S[i+1][j] == "#"):
        continue
      if(j != 0 and S[i][j-1] == "#"):
        continue
      if(j+1 < W and S[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

### FIXED CODE ###

H, W = map(int,input().split())
HW = [input() for _ in range(H)]

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(HW[i][j] == "."):
      continue
    if(i != 0 and HW[i-1][j] == "#"):
      continue
    if(j != 0 and HW[i][j-1] == "#"):
      continue
    if(j != H and HW[i+1][j] == "#"):
      continue
    if(j != W and HW[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)
n=int(input())
h=list(map(int,input().split()))
ans=0
kari=0
inde=0
if n==1:
    print(0)
else:
    while 1:
        suuzi=h[inde]
        if h[inde+1]<=suuzi:
            kari+=1
        elif ans<kari:
            ans=kari
            kari=0
        inde+=1
        if inde==n-1:
            if ans<kari:
            ans=kari

            break
    print(ans)

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
ans=0
kari=0
for i in range(n-1):
        if h[i+1]<=h[i]:
            kari+=1
        else:
            if ans<kari:
                ans=kari
            kari=0
        
       
print(max(ans,kari))
import math
A,B,C,D = list(map(int, input().split()))
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
lcm = lcm(C,D)
nbc = B//C
nbd = B//D
nbl = B//lcm 

nac = (A-1)//C
nad = (A-1)//D
nal = (A-1)//lcm 
ans = B - A + 1-((nbc+nbd-nbl)-(nac+nad-nal))
print(ans)

### FIXED CODE ###

from fractions import gcd
A,B,C,D = list(map(int, input().split()))
def lcm(x, y):
    return (x * y) // gcd(x, y)
lcm = lcm(C,D)
nbc = B//C
nbd = B//D
nbl = B//lcm 
nac = (A-1)//C
nad = (A-1)//D
nal = (A-1)//lcm 
ans = B - A + 1-((nbc+nbd-nbl)-(nac+nad-nal))
print(int(ans))
def func():
    input_num = int(input(''))
    a_i = [int(input('')) for i in range(input_num) ]
    frag, count = True, 0
    for i in range(input_num):
        if a_i[0] == a_i[i]:
            count += 1
    if count == input_num:
         frag = False
    if frag == True:
        value = [[a_i[i] if a_i[i] != a_i[j] else 0 for i in range(input_num )] for j in range(input_num)]
    else:
        value = [[a_i[i]for i in range(input_num )] for j in range(input_num)]
    for i in range(input_num):
        print(max(value[i]))
if __name__ == '__main__':
    func()

### FIXED CODE ###

def func():
    input_num = int(input(''))
    return 3*input_num**2


if __name__ == "__main__":
    print(func())
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
def c(j):
    if j==1:
        return 1
    else:
        return a[c(j-1)-1]
j=1
if 2 not in a:
    print(-1)
else:
    while a[c(j)-1] not in b:
        b.append(a[c(j)-1])
        j += 1
    if 2 not in b:
        print(-1)
    else:
        print(b.index(2)+1)

### FIXED CODE ###

N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
c=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
         c += 1
         if a[k-1]==1:
                 print(-1)
                 break
         elif a[k-1]==2:
                 print(c-1)
                 break
         else:
            j += 1
            k = a[k-1]
    if c>=(N+1):
        print(-1)
n,m = map(int, input().split());

A = []*m;
B = []*m;

for i in range(m):
  a, b = input().split();
  A[i] = int(a));
  B[i] = b;
  
#ACの数
AC_list = list(set(A));

AC_count = len(AC_list);

#WAの数
WA_count = 0;

for j in AC_list:
  indexes = [i for i, x in enumerate(A) if x == j];
  for k in indexes:
    if B[k] == "WA":
      WA_count += 1;
      continue;
    else:
      break;
      
print(AC_count, WA_count);


### FIXED CODE ###

n,m = map(int,input().split())
#ac,wa列を作成（pi問題がACならac[i]がTRUE、AC,WAに問わずwa[i]はwaの数）
ac, wa=[False]*n,[0]*n
for i in range(m):
  p,s = input().split()
  p=int(p)
  if s=='AC':
    ac[p-1]=True
  elif (s=='WA') and (ac[p-1]==False):
    wa[p-1]+=1

penalty, clear=0,0
for i,tf in enumerate(ac): #iはインデックス、tfはac[i]
  if tf:
    penalty += wa[i] #piがACされているとき、ペナルティ値を増やす
    clear += 1
print(clear, penalty)
N = int(input())
H = list(map(int, input().split()))

for i in range(N-1, 0, -1):
    #print(H[i-1], H[i])
    if H[i-1] <= H[i]:
        #print("@")
        continue
    elif (H[i-1] - 1) == H[i]:
        #print("#")
        H[i-1] = H[i]
    else:
        #print("=")
        break

if i == 1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

if N == 1:
    print("Yes")
else:
    for i in range(N-1, 0, -1):
        #print(H[i-1], H[i])
        if H[i-1] <= H[i]:
            #print("@")
            continue
        elif (H[i-1] - 1) == H[i]:
            #print("#")
            H[i-1] = H[i]
        else:
            #print("=")
            break
    
    if i == 1:
        print("Yes")
    else:
        print("No")
l = input().split()
N = int(l[0])
M = int(l[1])

A = []
B = []
C = [[] for i in range(N)]

for i in range(M):
    l = input().split()
    a = int(l[0]) - 1
    b = int(l[1]) - 1
    A.append(a)
    B.append(b)
    C[a].append(b)
    C[b].append(a)

# print(N, M, A, B, C)

def visit(cur, ans, visited):
    # print('cur={}, ans={}'.format(cur, ans))
    visited.append(cur)
    if cur == N - 1:
        # print('goal')
        return ans + 1
    for next in C[cur]:
        if next not in visited:
            return visit(next, ans, visited)

ans = 0
for next in C[0]:
    visited = []
    ans += visit(0, 0, visited)

print(ans)


### FIXED CODE ###

l = input().split()
N = int(l[0])
M = int(l[1])

C = [[] for i in range(N)]

for i in range(M):
    l = input().split()
    a = int(l[0]) - 1
    b = int(l[1]) - 1
    C[a].append(b)
    C[b].append(a)

# print(N, M, C)

def visit(cur, visited, ans, depth):
    depth += 1
    # print('depth={}, cur={}, visited={}, ans={}, C[cur]={}'.format(
    #     depth, cur, visited, ans, C[cur]))
    visited.append(cur)
    if len(visited) == N:
        # print('goal')
        return ans + 1
    for n in C[cur]:
        # print('n={}'.format(n))
        if n not in visited:
            v = [x for x in visited]
            ans = visit(n, v, ans, depth)
    return ans

ans = 0
for n in C[0]:
    visited = [0]
    ans += visit(n, visited, 0, 0)

print(ans)
num = int(input())
year = 0
cash = 100
while(True){
	cash += int(cash/100)
  	year++
	if(num < cash):
  		print(year)
  		break
	}

### FIXED CODE ###

num = int(input())
year = 0
cash = 100
while(True):
  cash += int(cash/100)
  year+=1
  if(num <= cash):
    print(year)
    break
print (int(input)**2)


### FIXED CODE ###

print(int(input())**2)
n,m=map(int,input().split())
if m==0:
  dp=[0]*(n+1)
  dp[1]=dp[2]=1
  for i in range(n+1):
    dp[i]=(dp[i-1]+dp[i-2])%mod
  print(dp[n])
  exit()
a=[int(input()) for i in range(m)]
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if n==1:
  print(1)
  exit()
if a[0]==1:
  dp[1]=0
else:
  dp[1]=1
a=set(a)
for i in range(2,n+1):
  if i in a:
    dp[i]=0
  else:
    dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[n])


### FIXED CODE ###

n,m=map(int,input().split())
a=set()
for i in range(m):
  a.add(int(input()))
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
  dp[1]=0
else:
  dp[1]=1
if n==1:
  print(dp[1])
  exit()
if 2 in a:
  dp[2]=0
else:
  dp[2]=dp[1]+1
for i in range(3,n+1):
  if i in a:
    dp[i]=0
  else:
    dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[n])
import numpy as np
N = int(input())
S = input()

def z_arr(s):
    Z = [0] * len(s)
    Z[0] = len(s)

    rt = 0
    lt = 0

    for k in range(1, len(s)):
        if k > rt:
            # If k is outside the current Z-box, do naive computation.
            n = 0
            while n + k < len(s) and s[n] == s[n+k]:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k+n-1
        else:
            # If k is inside the current Z-box, consider two cases.

            p = k - lt  # Pair index.
            right_part_len = rt - k + 1

            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k]:
                    i += 1
                Z[k] = i - k

                lt = k
                rt = i - 1
    return Z

ans = 0
for i in range(len(S)):
    x = z_arr(S[i:])
    for j,e in enumerate(x):
        remain_length = len(S[i:])-e
        if remain_length >= e:
            if e > ans:
                ans = e

print(ans)



### FIXED CODE ###

n = int(input())
s = input()
def output():
    left, right = 0, n//2+1
    while left < right-1:
        mid = (left+right)//2
        if check(mid):
            left = mid
        else:
            right = mid
    return left
def check(x):
    hashes = set()
    for i in range(n - 2*x + 1):
        hashes.add(s[i: i+x])
        if s[i+x: i+2*x] in hashes:
            return True
    return False
print(output())
def dps(no, fno, d, hen, D, MD, P):
    D[no] = d
    P[no] = fno
    maxd = d
    for h in hen[no]:
        if h == fno:
            continue
        maxd = max(maxd, dps(h, no, d + 1, hen, D, MD, P))
    MD[no] = maxd
    return maxd


def main():
    N, u, v = map(int, input().split())
    hen = {}
    for i in range(N - 1):
        A, B = map(int, input().split())
        if A in hen.keys():
            hen[A].append(B)
        else:
            hen[A] = [B]
        if B in hen.keys():
            hen[B].append(A)
        else:
            hen[B] = [A]
    DEPTH = [-1 for i in range(N + 1)]
    MAX_DEPTH = [-1 for i in range(N + 1)]
    Parent = [-1 for i in range(N + 1)]
    dps(v, -1, 0, hen, DEPTH, MAX_DEPTH, Parent)
    ans = DEPTH[u]
    p = u
    for i in range((DEPTH[u] + 1) // 2 - 1):
        p = Parent[p]
        ans = max(ans, MAX_DEPTH[p])
    print(ans - 1)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def dps_rec(no, fno, d, hen, D, MD, P):
    D[no] = d
    P[no] = fno
    maxd = d
    for h in hen[no]:
        if h == fno:
            continue
        maxd = max(maxd, dps_rec(h, no, d + 1, hen, D, MD, P))
    MD[no] = maxd
    return maxd

def dps_stc(no, fno, d, hen, D):
    stack = [(no, fno, d)]
    while not stack == []:
        t = stack.pop()
        D[t[0]] = t[2]
        for h in hen[t[0]]:
            if h == t[1]:
                continue
            stack.append((h, t[0], t[2] + 1))

def main():
    N, u, v = map(int, input().split())
    hen = {}
    for i in range(N - 1):
        A, B = map(int, input().split())
        if A in hen.keys():
            hen[A].append(B)
        else:
            hen[A] = [B]
        if B in hen.keys():
            hen[B].append(A)
        else:
            hen[B] = [A]
    DEPTH_A = [-1 for i in range(N + 1)]
    DEPTH_T = [-1 for i in range(N + 1)]
    dps_stc(v, -1, 0, hen, DEPTH_A)
    dps_stc(u, -1, 0, hen, DEPTH_T)
    ans = 0
    for a, t in zip(DEPTH_A, DEPTH_T):
        if a > t:
            ans = max(ans, a - 1)

    print(ans)


if __name__ == '__main__':
    main()
n = int(input())
h = list(map(int,input().split()))

for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  else:
    j = 0
    p = 3

if j == 0:
  print("Yes")
else:  
  if min(h[j:]) + 2 <= h[j] or p == 2:
  print("No")
  else:
  print("Yes")

### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa = 0
    if sa < sb:
        print(n - sa - vb)
    else:
        print(n - va - sb)
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa = 0
    if sa < sb:
        print(n - sa - vb)
    else:
        print(n - va - sb)

### FIXED CODE ###

from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa, sb = 0, 0
    print(n - max(sa + vb, va + sb))
import numpy as np
a, b, c, n = map(int, input().split())
aa =[a,b,c]
r = max(aa)
b = min(aa)
g = int(np.median(aa))
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int(n/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):

            count +=1

print(count)


### FIXED CODE ###

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[2]
g = aa[1]
b = aa[0]
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count = count + 1
 
print(count)
a = input()
ok = 1
for i in range(1, 4):
	if a[i] == a[i - 1]:
      ok = 0
if ok:
  print("Good")
else:
	print("Bad")

### FIXED CODE ###

a = input()
ok = 1
for i in range(1, 4):
    if a[i] == a[i - 1]:
        ok = 0
if ok:
    print("Good")
else:
    print("Bad")
S = input()

S = S[::-1]

l = ['dream','dreamer','erase','eraser']
L = []
for i in l:
    L.append(i[::-1])
num=0
def rec(s):
    flag=False
    for ii in L:
        leng = len(ii)
        if len(s)<leng:
            continue
        else:
            if s[num:leng]==ii:
                if len(s)==leng:
                    flag=True
                    break
                else:
                    return rec(s[leng:])
            else:
                continue
    return flag
f = rec(S)
if f:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

S = input()
S = S[::-1]
l = ['dream','dreamer','erase','eraser']
L = []
pos = 0
f=True

for i in l:
    L.append(i[::-1])

while pos < len(S):
    no_match = True
    for candidate in L:
        if S[pos:pos+len(candidate)]==candidate:
            pos+=len(candidate)
            no_match =False
            break
    if no_match:
        f =False
        break


if f:
    print('YES')
else:
    print('NO')
# coding: utf-8

N = input()
N_list = list(N)
N_len = len(N_list)
N_count = N_list("1")

if N_count ==0:
	print("0")
elif N_count == 1:
	print("1")
elif N_count == 2:
	print("2")
elif N_count == 3:
	print("3")

### FIXED CODE ###

# coding: utf-8

N = input()
N_list = list(N)
N_count = N_list.count("1")

if N_count == 0:
	print("0")
elif N_count == 1:
	print("1")
elif N_count == 2:
	print("2")
elif N_count == 3:
	print("3")