CodeEff/ECCO huggingface dataset:
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = I(),I()
ans = 10**6
for i in range(N+1):
    a = 2**i
    a += K*(N-i)
    ans = min(ans,a)

print(ans)


# Optimized solution
import sys
def I(): return int(sys.stdin.readline().rstrip())


N,K = I(),I()
print((min(2**i+K*(N-i) for i in range(N+1))))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
ans = 10**10
for i in range(2**n):
    m = 1
    for j in range(n):
        if (i>>j)&1 == 1:
            m *= 2
        else:
            m += k
    ans = min(m,ans)
print(ans)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
ans = 1
for i in range(n):
    ans = min(2*ans,ans+k)
print(ans)
# Original solution
N = int(eval(input()))
K = int(eval(input()))

ans = None
for i in range(2 ** N):
    tmp = 1
    for j in range(N):
        if ((i >> j) &1):
            tmp += K
        else:
            tmp *= 2
    if ans == None:
        ans = tmp
    else:
        ans = min(ans, tmp)

print (ans)



# Optimized solution
import itertools
N = int(eval(input()))
K = int(eval(input()))

ans = 10 ** 18
for i in itertools.product('AB', repeat = N):
    tmp = 1
    for j in i:
        if j == 'A':
            tmp *= 2
        else:
            tmp += K
    # print (i, tmp)
    ans = min(ans, tmp)

print (ans)
# Original solution
n = int(eval(input()))
k = int(eval(input()))
a = [1]
for i in range(n):
    if a[i] < k:
        a[i] = 2*a[i]
        a.append(a[i])
    else:
        a[i] = a[i] + k
        a.append(a[i])
print((a[n-1]))

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
s = 1
for i in range(n):
    s = min(s+k,s*2)
print(s)
# Original solution
N,K=int(eval(input())),int(eval(input()))

ans=10**10
for i in range(2**N):
  tmp=1
  for j in range(N):
    if (i>>(N-j-1)&1)==1:
      tmp*=2
    else:
      tmp+=K
  ans=min(ans,tmp)
print(ans)

# Optimized solution
N,K=int(eval(input())),int(eval(input()))

M=[0]*(N+1)
M[0]=1

for i in range(1,N+1):
  M[i]=min(M[i-1]*2,M[i-1]+K)
print((M[N]))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
i = 1
while i < k:
    i *= 2
    n -= 1
while n != 0:
    i += k
    n -= 1
print(i)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
num = 1
for i in range(n):
    if num + k < num * 2:
        num += k
    else:
        num *= 2
print(num)
# Original solution
N = int(eval(input()))
K = int(eval(input()))

ans = 10**18
for state in range(1 << N):
    now = 1
    for d in range(N):
        if (state & (1 << d)) == 0:
            now *= 2
        else:
            now += K
    ans = min(ans, now)
print(ans)


# Optimized solution
N = int(eval(input()))
K = int(eval(input()))

ans = 1
for _ in range(N):
    if ans < K:
        ans *= 2
    else:
        ans += K
print(ans)
# Original solution
N=int(eval(input()))
K=int(eval(input()))
n=1
for i in range(N):
    if n<K:
        n*=2
    else:
        n+=K
print(n)


# Optimized solution
def solve():
    n = int(eval(input()))
    k = int(eval(input()))
    ans = 1
    for i in range(n):
        if ans < k:
            ans *= 2
        else:
            ans += k

    print(ans)


if __name__ == "__main__":
    solve()
# Original solution
n = int(eval(input()))
k = int(eval(input()))

res = 1
for i in range(n):
    if res * 2 - res < k:
        res *= 2
    else:
        res += k
print(res)

# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(eval(input()))
    k = int(eval(input()))

    res = 1
    for _ in range(n):
        if res < k:
            res *= 2
        else:
            res += k

    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
N = int(eval(input()))
K = int(eval(input()))

min_m = 10 ** 10
for i in range(2 ** N):
    m = 1
    for n in range(N):
        if i & (1 << n):
            m *= 2
        else:
            m += K
    min_m = min(min_m, m)

print(min_m)


# Optimized solution
N = int(eval(input()))
K = int(eval(input()))

# min_m = 10 ** 10
# for i in range(2 ** N):
#     m = 1
#     for n in range(N):
#         if i & (1 << n):
#             m *= 2
#         else:
#             m += K
#     min_m = min(min_m, m)

m = 1
for i in range(N):
    m = min(m * 2, m + K)

print(m)
# Original solution
N = int(eval(input()))
K = int(eval(input()))
sum = 1
for i in range(N):
    if sum*2 <= sum+K:
        sum *= 2
    else:
        sum += K
print(sum)


# Optimized solution
n=int(eval(input()))
k=int(eval(input()))
ans=1
for i in range(n):
    ans=min(ans*2,ans+k)
print(ans)
# Original solution
N=int(eval(input()))
K=int(eval(input()))
ans=float('inf')
for i in range(2**N):
    bi=list(format(i,'b').zfill(N))
    now=1
    for b in bi:
        if b=='0':
            now*=2
        else:
            now+=K
    if now<ans:
        ans=now
print(ans)

# Optimized solution
N=int(eval(input()))
K=int(eval(input()))

ans=1
for i in range(N):
    ans=min(ans*2,ans+K)
print(ans)
# Original solution
n=int(eval(input()))
k=int(eval(input()))
s=1
for i in range(n):s=min(s*2,s+k)
print(s)

# Optimized solution
N=int(eval(input()))
K=int(eval(input()))
display=1
for i in range(N):
    display=min(display*2,display+K)
print(display)
# Original solution
num = 1
n = int(eval(input()))
k = int(eval(input()))
for i in range(n):
    if num < k:
        num = num*2
    else:
        num += k
        
print(num)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
start = 1
for i in range(n):
    start = min(start*2,start+k)
    
print(start)
# Original solution
a = int(eval(input()))
b = int(eval(input()))
i = 0
p= 1
while i < a:
 if p > b:
  p = p+b
  i = i+1
 else:
  p = 2*p
  i = i+1
print(p)

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
ans = 1
for i in range(a):
  ans = min(ans * 2,ans + b)
print(ans)
# Original solution
n = int(eval(input()))
k = int(eval(input()))

val = 1
for i in range(n):
  val = min(val + k, val * 2)
print(val)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
p = 1
for _ in range(n):
  if p * 2 < p + k:
    p *= 2
  else:
    p += k
print(p)
# Original solution
#!/usr/bin/env python3

N = int(eval(input()))
K = int(eval(input()))
num = 1

for i in range(N):
    if num <= K:
        num *= 2

    else:
        num += K

print(num)


# Optimized solution
N=int(eval(input()))
K=int(eval(input()))

count=1

for i in range(N):
    if(count*2<count+K):
        count*=2
    else:
        count+=K
print(count)
# Original solution
n = int(eval(input()))
k = int(eval(input()))

val = 1

for i in range(n):
	if val > k:
		val += k
	else:
		val *= 2

print(val)

# Optimized solution
x = int(input())
y = int(input())
d = 1
for i in range(0, x):
 if y > d:
  d += d
 else:
  d += y
print(d)
# Original solution
N = int(eval(input()))
K = int(eval(input()))
ans = 1
for i in range(N):
  if(ans*2 < ans+K):
    ans *= 2
  else:
    ans += K
print(ans)

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))

ans = 1
for i in range(N):
  ans = min(ans*2, ans+K)
print(ans)
# Original solution
ans=1
n=int(eval(input()))
k=int(eval(input()))
for i in range(n):
  ans=min(ans+k,ans*2)
print(ans)

# Optimized solution
n=int(eval(input()))
k=int(eval(input()))
ans=1
for i in range(n):
    if k>ans:
        ans*=2
    else : ans+=k
print(ans)
# Original solution
N = int(eval(input()))
K = int(eval(input()))
ans = float('inf')

for i in range(2**N):
  now = 1
  for j in range(N):
    if i>>j & 1:
      now *= 2
    else:
      now += K
  ans = min(ans, now)

print(ans)

# Optimized solution
N = int(eval(input()))
K = int(eval(input()))

now = 1
for i in range(N):
  now = min(now*2, now+K)

print(now)
# Original solution
n = int(eval(input()))
k = int(eval(input()))
ans = 1

for i in range(n):
    if ans*2 < ans + k:
        ans *= 2
    else:
        ans += k

print(ans)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
ans = 1

for i in range(n):
    ans = min(ans*2, ans + k)

print(ans)
# Original solution
s = input()
p = "ABC"
used = set()

while s != p:
    idx = 0
    c = [0]*3
    while idx < len(s):
        if idx+3 <= len(s) and s[idx:idx+3] == p:
            idx += 3
        else:
            c[p.index(s[idx])] += 1
            idx += 1
    if sum(e == 0 for e in c) != 1 or sum(c) == s:
        print("No")
        exit(0)
    s = s.replace("ABC", p[[i for i in [0,1,2] if c[i]==0][0]])
print("Yes")

# Optimized solution
s = input()
p = "ABC"
used = set()

while s != p:
    idx = 0
    c = [0]*3
    while idx < len(s):
        if idx+3 <= len(s) and s[idx:idx+3] == p:
            idx += 3
        else:
            c[p.index(s[idx])] += 1
            idx += 1
    if sum(e == 0 for e in c) != 1 or sum(c) == len(s):
        print("No")
        exit(0)
    s = s.replace("ABC", p[[i for i in [0,1,2] if c[i]==0][0]])
print("Yes")
# Original solution
#!/usr/bin/python

if __name__ == "__main__":
	S = input()
	c = ['A','B','C']
	
	while True:
		if S == "ABC":
			print("Yes")
			break
		
		T = S.strip().split("ABC")
		P = ''.join(T)
		
		cnt = 0
		for x in c:
			if x in P:
				cnt += 1
			else:
				S = x.join(T)
		
		if cnt != 2:
			print("No")
			break

# Optimized solution
#!/usr/bin/python

if __name__ == "__main__":
	S = input()
	c = ['A','B','C']
	
	while True:
		if len(S) <= 3:
			print("Yes" if S == "ABC" else "No")
			break
		
		T = S.strip().split("ABC")
		if len(T) == 1:
			print("No")
			break
			
		P = ''.join(T)
		cnt = 0
		for x in c:
			if x in P:
				cnt += 1
			else:
				S = x.join(T)
		
		if cnt != 2:
			print("No")
			break
# Original solution
#!/usr/bin/python

if __name__ == "__main__":
	S = input()
	c = ['A','B','C']
	
	while True:
		if len(S) <= 3:
			print("Yes" if S == "ABC" else "No")
			break
		
		T = S.strip().split("ABC")
		if len(T) == 1:
			print("No")
			break
			
		P = ''.join(T)
		cnt = 0
		for x in c:
			if x in P:
				cnt += 1
			else:
				S = x.join(T)
		
		if cnt != 2:
			print("No")
			break

# Optimized solution
#!/usr/bin/python

if __name__ == "__main__":
	S = input()
	c = ['A','B','C']
	
	while True:
		if len(S) <= 3:
			print("Yes" if S == "ABC" else "No")
			break
		
		T = S.strip().split("ABC")			
		P = ''.join(T)
		
		cnt = 0
		for x in c:
			if x in P:
				cnt += 1
			else:
				S = x.join(T)
		
		if len(T) == 1 or cnt != 2:
			print("No")
			break
# Original solution
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,H,W = list(map(int,readline().split()))
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = lambda x: -x[2])

RCA

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)



# Optimized solution
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N,H,W = list(map(int,readline().split()))
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = lambda x: -x[2])

RCA

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)
# Original solution
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N,H,W = list(map(int,readline().split()))
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = lambda x: -x[2])

RCA

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)



# Optimized solution
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
import operator

N,H,W = list(map(int,readline().split()))
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = operator.itemgetter(2), reverse=True)

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def par(a):
    if P[a] == a: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) != par(b): C[par(a)] += C[par(b)]
    P[par(b)] = par(a)

N, H, W = list(map(int, input().split()))
P = [i for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = list(map(int, input().split()))
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def par(a):
    if P[a] < 0: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) == par(b): return 0
    C[par(a)], C[par(b)] = C[par(a)] + C[par(b)], C[par(a)] + C[par(b)]
    if P[par(b)] == P[par(a)]:
        P[par(b)] = par(a)
        P[par(a)] -= 1
    elif P[par(b)] > P[par(a)]:
        P[par(b)] = par(a)
    else:
        P[par(a)] = par(b)
N, H, W = list(map(int, input().split()))
P = [-1 for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = list(map(int, input().split()))
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)
# Original solution
n = int(eval(input()))
list_V = list(map(int, input().split()))

list_Vx = []
list_Vy = []

for i, s in enumerate(list_V):
    if i % 2 == 0:
        list_Vx.append(s)
    else:
        list_Vy.append(s)

list_Vx_Count = [0 for _ in range(pow(10, 5))]
list_Vy_Count = [0 for _ in range(pow(10, 5))]

for i in list_Vx:
    list_Vx_Count[i-1] += 1
for i in list_Vy:
    list_Vy_Count[i-1] += 1

ans = n - max(list_Vx_Count) - max(list_Vy_Count)

if list_Vx_Count.count(max(list_Vx_Count)) == 1 and list_Vy_Count.count(max(list_Vy_Count)):
    if list_Vx_Count.index(max(list_Vx_Count)) == list_Vy_Count.index(max(list_Vy_Count)):
        ans = n - max(max(list_Vx_Count)+sorted(list_Vx_Count)[-2], max(list_Vy_Count)+sorted(list_Vy_Count)[-2])

print(ans)

# Optimized solution
from collections import Counter

n = int(eval(input()))
list_A = list(map(int, input().split()))
L, R = [], []

for i in range(n):
    if i % 2 == 0:
        L.append(list_A[i])
    else:
        R.append(list_A[i])

A = Counter(L)
A = sorted(list(A.items()), key=lambda x:x[1], reverse=True)
A.append((-1, 0))

B = Counter(R)
B = sorted(list(B.items()), key=lambda x:x[1], reverse=True)
B.append((-1, 0))

if A[0][0] != B[0][0]:
    print((n - A[0][1] - B[0][1]))
else:
    print((min(n - A[1][1] - B[0][1], n - A[0][1] - B[1][1])))
# Original solution
import collections

N = int(eval(input()))

even = collections.defaultdict(lambda: 0)
odd = collections.defaultdict(lambda: 0)

for i, a in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even[a] += 1
    else:
        odd[a] += 1

if len(list(even.keys())) == 1 and len(list(odd.keys())) == 1 and list(even.keys())[0] == list(odd.keys())[0]:
    print((N // 2))
else:
    m = 0
    for e_k, e_v in list(even.items()):
        for o_k, o_v in list(odd.items()):
            if e_k == o_k:
                continue
            m = max(m, e_v + o_v)

    print((N - m))


# Optimized solution
import collections

N = int(eval(input()))

even = collections.defaultdict(lambda: 0)
odd = collections.defaultdict(lambda: 0)

for i, a in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even[a] += 1
    else:
        odd[a] += 1

if len(list(even.keys())) == 1 and len(list(odd.keys())) == 1 and list(even.keys())[0] == list(odd.keys())[0]:
    print((N // 2))
else:
    m = 0
    for e_k, e_v in sorted(list(even.items()), key=lambda x: x[1], reverse=True)[:2]:
        for o_k, o_v in sorted(list(odd.items()), key=lambda x: x[1], reverse=True)[:2]:
            if e_k == o_k:
                continue
            m = max(m, e_v + o_v)

    print((N - m))
# Original solution
import collections

N = int(eval(input()))
VV = list(map(int, input().split()))
v_even = VV[::2]
v_odd = VV[1::2]

e = collections.Counter(v_even)
o = collections.Counter(v_odd)
e_common = e.most_common()
o_common = o.most_common()


if (e_common[0] != o_common[0]):
    tmp = e_common[0][1] + o_common[0][1]
    answer = N - tmp

elif (len(e_common) == 1 or len(o_common) == 1): # case one type
    if (len(e_common) == 1 and len(o_common) == 1):
        answer = N // 2
    elif (len(e_common) == 1):
        answer = N // 2 - o_common[1][1]
    elif (len(o_common) == 1):
        answer = N // 2 - e_common[1][1]

else:
    tmp1 = e_common[0][1] + o_common[1][1]
    tmp2 = e_common[1][1] + o_common[0][1]
    tmp = max(tmp1, tmp2)
    answer = N - tmp

print(answer)

# Optimized solution
import collections

N = int(eval(input()))
VV = list(map(int, input().split()))
v_even = VV[::2]
v_odd = VV[1::2]

e = collections.Counter(v_even).most_common() + [(0, 0)]
o = collections.Counter(v_odd).most_common() + [(0, 0)]

if (e[0][0] == o[0][0]):
    tmp1 = e[0][1] + o[1][1]
    tmp2 = e[1][1] + o[0][1]
    answer = N - max(tmp1, tmp2)
else:
    tmp = e[0][1] + o[0][1]
    answer = N - tmp

print(answer)
# Original solution
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
v1 = [v[i*2+1] for i in range(n//2)]
v2 = [v[i*2] for i in range(n//2)]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if len(set(v1)) == len(set(v2)) == 1:
  if c1[0][0] != c2[0][0]:
    print((0))
  else:
    print((min(len(v1), len(v2))))
elif len(set(v1))==1:
  if c1[0][0] != c2[0][0]:
    print((sum([i[1] for i in c2])-c2[0][1]))
  else:
    print((sum([i[1] for i in c2])-c2[1][1]))
elif len(set(v2))==1:
  if c1[0][0] != c2[0][0]:
    print((sum([i[1] for i in c1])-c1[0][1]))
  else:
    print((sum([i[1] for i in c1])-c1[1][1]))
else:
  if c1[0][0] != c2[0][0]:
    print(((sum([i[1] for i in c1])-c1[0][1]) + (sum([i[1] for i in c2])-c2[0][1])))
  else:
    print((min((sum([i[1] for i in c1])-c1[0][1])+(sum([i[1] for i in c2])-c2[1][1]),
              (sum([i[1] for i in c1])-c1[1][1])+(sum([i[1] for i in c2])-c2[0][1]))))

# Optimized solution
import collections
n = int(eval(input()))
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if c1[0][0] != c2[0][0]:
  print((len(v1)-c1[0][1] + len(v2)-c2[0][1]))
else:
  if len(c1) == len(c2) == 1:
    print((n // 2))
  elif len(c1) == 1:
    print((len(v2)-c2[1][1]))
  elif len(c2) == 1:
    print((len(v1)-c1[1][1]))
  else:
    print((min(len(v1)-c1[0][1]+len(v2)-c2[1][1], len(v1)-c1[1][1]+len(v2)-c2[0][1])))
# Original solution
_ = eval(input())
seq = list(map(int,input().split()))
 
seq1 = seq[::2]
seq2 = seq[1::2]
 
if len(set(seq)) == 1:
    print((min(len(seq1),len(seq2))))
    exit()
    
def count_dictonary(seq):
    ret_dict={}
    for item in seq:
        if item not in ret_dict:
            ret_dict[item] = 1
        else:
            ret_dict[item]+=1
    return ret_dict
 
seq_dict1 = sorted(list(count_dictonary(seq1).items()),key=lambda x:x[1],reverse=True)
seq_dict2 = sorted(list(count_dictonary(seq2).items()),key=lambda x:x[1],reverse=True)
 
min_change=len(seq)
for i1, count1 in seq_dict1:
    ch1 = len(seq1) - count1
    if ch1 > min_change:
        continue
    for i2, count2 in seq_dict2:
      ch2 = len(seq2) - count2
      #print(i1,i2,ch1,ch2,ch1+ch2)
      change_ = ch1+ch2
      if(min_change > ch1+ch2):
        min_change = ch1+ch2
            
print(min_change)

# Optimized solution
_ = eval(input())
seq = list(map(int,input().split()))
 
seq1 = seq[::2]
seq2 = seq[1::2]
 
if len(set(seq)) == 1:
    print((len(seq2)))
    exit()
    
def count_dictonary(seq):
    ret_dict={}
    for item in seq:
        if item not in ret_dict:
            ret_dict[item] = 1
        else:
            ret_dict[item]+=1
    return ret_dict
 
def modes(counting_dict):
    #(11,2),(2,1),(3,3)
    ret={}
    for item in list(counting_dict.items()):
        no, count = item
        if counting_dict[no] in ret:
            ret[count].append(no)
        else:
            ret[count]=[no]
            
    return ret
 
 
counting1 = count_dictonary(seq1)
counting2 = count_dictonary(seq2)
 
modes1 = sorted(list(modes(counting1).items()),reverse=True)
modes2 = sorted(list(modes(counting2).items()),reverse=True)
 
min_change=len(seq)
if modes1[0][1] != modes2[0][1] or len(modes1[0][1]) >=2 or len(modes2[0][1]) >=2:
    min_change = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[0][0])
else:
    m01=len(seq)
    m10=len(seq)
    if len(modes2) !=1:
        m01 =  (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[1][0])
    if len(modes1) !=1:
        m10 =  (len(seq1) - modes1[1][0]) + (len(seq2) - modes2[0][0])
    min_change = min(m01,m10)
    
print(min_change)