Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
from copy import deepcopy

def warshall_floyd(n,a):
    d = deepcopy(a)
    is_via = np.full((n,n), False)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                # 経由する場合
                if (d[i][k] != 0 and d[k][j] != 0) and (d[i][j] == d[i][k] + d[k][j]):
                    is_via[i][j] = True
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    flag = np.all(a == d)
    return flag, is_via

N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

flag, is_via = warshall_floyd(N,A)

if not flag:
    print(-1)
    exit()

ans = 0
for i in range(N):
    for j in range(i,N):
        if is_via[i][j]:
            continue
        ans += A[i][j]

print(ans)

### FIXED CODE ###

from copy import deepcopy

def warshall_floyd(n,a):
    d = deepcopy(a)
    is_via = [[False] * n for _ in range(n)]
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                # 経由する場合
                if (d[i][k] != 0 and d[k][j] != 0) and (d[i][j] == d[i][k] + d[k][j]):
                    is_via[i][j] = True
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    flag = a == d
    return flag, is_via

N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

flag, is_via = warshall_floyd(N,A)

if not flag:
    print(-1)
    exit()

ans = 0
for i in range(N):
    for j in range(i,N):
        if is_via[i][j]:
            continue
        ans += A[i][j]

print(ans)
### BUGGY CODE ###

n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*10**i)
        tmp%=p
        ans+=M[tmp%p]
        M[tmp%p]+=1
print(ans)

### FIXED CODE ###

n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*pow(10,i,p))
        tmp%=p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)
### BUGGY CODE ###

s = input()
start = now = len(s)
while True:
    s = s.replace('01','').replace('10','')
    if now == len(s):
        break
    now = len(s)
print(start - now)

### FIXED CODE ###

s = input()

print(2 * min(s.count('0'),s.count('1')))
### BUGGY CODE ###

from networkx import*
N = int(input())
G = MultiDiGraph()
k = 0
for i in range(N):
    x, y, c = map(int, input().split())
    for _ in range(c):
        G.add_node(k, demand = -1)
        G.add_weighted_edges_from([(k, -1, x + y)], capacity = 1)
        G.add_weighted_edges_from([(k, -2, x - y)], capacity = 1)
        G.add_weighted_edges_from([(k, -3, -x + y)], capacity = 1)
        G.add_weighted_edges_from([(k, -4, -x - y)], capacity = 1)
        k += 1

for i in range(N):
    x, y, c = map(int, input().split())
    for _ in range(c):
        G.add_node(k, demand = 1)
        G.add_weighted_edges_from([(-1, k, -x - y)], capacity = 1)
        G.add_weighted_edges_from([(-2, k, -x + y)], capacity = 1)
        G.add_weighted_edges_from([(-3, k, x - y)], capacity = 1)
        G.add_weighted_edges_from([(-4, k, x + y)], capacity = 1)
        k += 1

print(-min_cost_flow_cost(G))

### FIXED CODE ###

from networkx import*
N = int(input())
G = MultiDiGraph()
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(i, demand = -c)
    G.add_weighted_edges_from([(i, -1, x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -2, x - y)], capacity = c)
    G.add_weighted_edges_from([(i, -3, -x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -4, -x - y)], capacity = c)
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(N + i, demand = c)
    G.add_weighted_edges_from([(-1, N + i, -x - y)], capacity = c)
    G.add_weighted_edges_from([(-2, N + i, -x + y)], capacity = c)
    G.add_weighted_edges_from([(-3, N + i, x - y)], capacity = c)
    G.add_weighted_edges_from([(-4, N + i, x + y)], capacity = c)

print(-min_cost_flow_cost(G))
### BUGGY CODE ###

import sys
from pprint import pprint

mod = 10**9 + 7

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % mod
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % mod


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        binary = format(a_i, '060b')

        for j, b_j in enumerate(binary):
            zero_count[j] += int(b_j)

    ans = 0
    for i, count in enumerate(zero_count[::-1]):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

### FIXED CODE ###

import sys
from pprint import pprint

mod = 10**9 + 7

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % mod
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % mod


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        # binary = format(a_i, '060b')
        # for j, b_j in enumerate(binary):
        #    zero_count[j] += int(b_j)
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    # for i, count in enumerate(zero_count[::-1]):
    for i, count in enumerate(zero_count):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)
### BUGGY CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,m=map(int,input().split())
u=[list(map(int,input().split())) for i in range(m)]
s,t=map(int,input().split())
dic=[[] for i in range(n+1)]
for i in range(m):
    a,b=u[i]
    dic[a].append(b)
# print(dic)
itta=[0]*(n+1)
d=deque([[s,0]])
itta[s]=1
itta[t]=2
while d:
    tmp=d.popleft()
    # print(tmp)

    for i in dic[tmp[0]]:
        if (tmp[1]+1)%3==0:
            if itta[i]==1:
                continue
            elif itta[i]==2:
                print((tmp[1]+1)//3)
                quit()
            else:
               itta[i]=1 
        d.append([i,tmp[1]+1])
    # print(itta)
print(-1)

### FIXED CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,m=map(int,input().split())
u=[list(map(int,input().split())) for i in range(m)]
s,t=map(int,input().split())
dic=[[] for i in range(n+1)]
for i in range(m):
    a,b=u[i]
    dic[a].append(b)
# print(dic)
itta=[[0]*3 for i in range(n+1)]
d=deque([[s,0]])
itta[s][0]=1
itta[t][0]=2
while d:
    tmp=d.popleft()
    
    # print(tmp)

    p,cnt=tmp
    for i in dic[p]:
        if itta[i][(cnt+1)%3]==1:
            continue
        elif itta[i][(cnt+1)%3]==2:
            print((cnt+1)//3)
            quit()
        else:
            itta[i][(cnt+1)%3]=1
            d.append([i,cnt+1])
    # print(itta)
print(-1)
### BUGGY CODE ###

def judge_prime(x):
    A = list(range(2,x+1))
    while A[-1]==x:
        if A[0]==x: return True
        A = list(filter(lambda y: y%A[0]!=0, A))
    return False

if __name__=='__main__':
    N=int(input())
    cnt=0
    for _ in range(N):
        if judge_prime(int(input())): cnt+=1
    print(cnt)

### FIXED CODE ###

def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x%2==0:
        return False
    i = 3
    while i <= x**(0.5):
        if x%i==0:
            return False
        i+=2
    return True

if __name__=='__main__':
    N=int(input())
    cnt=0
    for _ in range(N):
        if is_prime(int(input())): cnt+=1
    print(cnt)
### BUGGY CODE ###

N,K = map(int,input().split())
x=[N,abs(N-K)]
i=1
while x[i] < x[i-1]:
    x.append(abs(x[i]-K))
    i+=1
print(x[i-1])


### FIXED CODE ###

N,K = map(int,input().split())
print(min(N%K,-N%K))
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
    snk = sum(A[:i])
    arg = sum(A[i:])
    res.append(abs(snk-arg))
if N == 2:
    print(abs(A[0] - A[1]))
else:
    print(min(res))

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
res = []
for i in range(N-1):
    deltas.append(deltas[-1] - 2*A[i])
    res.append(abs(deltas[-1]))
print(min(res))
### BUGGY CODE ###

S = input()
S = S[::-1]
#print(S)

mod = 10**9+7

dp = [0]*13
dp[0] = 1
for i in range(len(S)-1,-1,-1):
	ch = int(S[i]) if S[i]!='?' else -1
	temp = [0]*13
	for d in range(10):
		if ch!=-1 and ch!=d:
			continue
		for m in range(13):
			temp[(d*10**i+m)%13] += dp[m]
	for m in range(13):
		temp[m] %= mod
	dp = temp
print(dp[5])


### FIXED CODE ###

S = input()
S = S[::-1]
#print(S)

mod = 10**9+7

tblpow = [1]
for i in range(1,len(S)+1):
	tblpow.append(10*tblpow[i-1]%13)

dp = [0]*13
dp[0] = 1
for i in range(len(S)-1,-1,-1):
	ch = int(S[i]) if S[i]!='?' else -1
	temp = [0]*13
	for d in range(10):
		if ch!=-1 and ch!=d:
			continue
		for m in range(13):
			temp[(d*tblpow[i]+m)%13] += dp[m]
	for m in range(13):
		temp[m] %= mod
	dp = temp
print(dp[5])
### BUGGY CODE ###

S = input()
N = len(S)
sosu = 10 ** 9 + 7
dp = [[0 for i in range(13)] for j in range(N)]
amarilist = dict()
amarilist[0] = 1
for i in range(1,N):
    amarilist[i] = amarilist[i-1] * 10 % 13
#print(amarilist)
if S[0] == '?':
    for k in range(10):
        amari =  k * amarilist[N-1] % 13
        dp[0][amari] += 1
else:
    amari = int(S[0]) * amarilist[N-1]  % 13
    dp[0][amari] = 1
#print(dp)
for j in range(1,N):
    if S[j] == '?':
        for k in range(10):
            amari = k * amarilist[N-j-1]  % 13
            for i in range(13):
                if i >= amari:
                    dp[j][i] += dp[j - 1][i - amari]
                    dp[j][i] = dp[j][i] % sosu
                else:
                    dp[j][i] += dp[j - 1][i + 13 - amari]
                    dp[j][i] = dp[j][i] % sosu
    else:
        amari = int(S[j]) * amarilist[N-j-1] % 13
        for i in range(13):
            if i >= amari:
                dp[j][i] = dp[j-1][i-amari]
            else:
                dp[j][i] = dp[j-1][i + 13 - amari]
print(dp[N-1][5])

### FIXED CODE ###

S = input()
N = len(S)
sosu = 10 ** 9 + 7
dp = [[0 for i in range(13)] for j in range(N)]
j = 0
if S[j] == '?':
    flag = -1
else:
    flag = int(S[j])
if flag == -1:
    for i in range(10):
        dp[j][i] += 1
else:
    dp[j][flag] = 1
#print(dp)
for j in range(1, N):
    if S[j] == '?':
        flag = -1
    else:
        flag = int(S[j])
    for k in range(10):
        if flag == -1:
            for i in range(13):
                dp[j][(i * 10 + k) % 13] += dp[j - 1][i]
            for i in range(13):
                dp[j][i] = dp[j][i] % sosu
        else:
            for i in range(13):
                dp[j][(i * 10 + flag) % 13] = dp[j-1][i]
 
print(dp[N-1][5])
### BUGGY CODE ###

n,p = map(int,input().split())
s = input()
num = 0
ans = 0
for i in range(n):
	num = int(s[i])
	if num % p == 0:ans+=1
	for j in range(i+1,n):
		num = 10 * num + int(s[j])
		if num % p == 0:
			ans += 1
print(ans)


### FIXED CODE ###

def main():
	N,P = map(int,input().split())
	S = [int(s) for s in list(input().strip())][::-1]
	num = 0
	ans = 0
	if P == 2 or P == 5:
		for i in range(N):
			if S[i]%P == 0:
				ans += N-i
		print(ans)
		return
	L = [0]*P
	L[0]=1
	t = 0
	s = 1
	for z in S:
		t = (z*s+t)%P	
		L[t]+=1
		s=s*10%P
	for l in L:
		ans += l * (l - 1) // 2
	print(ans)

if __name__ == '__main__':
	main()
### BUGGY CODE ###

N = int(input())
csf = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1] + csf[j][0]
            continue
        num = 0
        while True:
            if csf[j][1]+num*csf[j][2] < t <= csf[j][1]+(num+1)*csf[j][2]:
                t = csf[j][1]+(num+1)*csf[j][2] + csf[j][0]
                break
            num += 1
    print(t)

print(0)


### FIXED CODE ###

N = int(input())
csf = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1] + csf[j][0]
            continue
        if (t-csf[j][1]) % csf[j][2] == 0:
            t = csf[j][1] + csf[j][2]*((t-csf[j][1])//csf[j][2]) + csf[j][0]
        else:
            t = csf[j][1] + csf[j][2]*((t-csf[j][1])//csf[j][2]+1) + csf[j][0]
    print(t)

print(0)
### BUGGY CODE ###

#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
pairwise = True
setwise = True
acc = a[0]
for i in range(N):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

def factrial(N):
    ret = []
    n = N
    for i in range(2,math.floor(pow(N,0.5))+1):
      while n%i==0:
        ret.append(i)
        n = n//i
    if n != 1:
        ret.append(n)
    return ret

# facts = [set(factrial(e)) for e in a]
s = set()
for e in a:
    f = set(factrial(e))
    if f & s:
        print("setwise coprime")
        exit()
    s = s | f
print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")


### FIXED CODE ###

import math
from collections import defaultdict
pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
class Sieve_of_Eratosthenes:
    def __init__(self, N):
        self.sieve = [-1] * (N+1)
 
        for i in range(2,N+1):
            if self.sieve[i] == -1:
                for j in range(1,1+N//i):
                    self.sieve[i*j] = i
 
    def isprime(self, num):
        if num <= 1:
            return False
        else:
            return self.sieve[num] == num
 
    def factorization(self, num):
        ret = set([])
        while num != 1:
            div = self.sieve[num]
            ret.add(div)
            num //= div
        return ret
 
sofe = Sieve_of_Eratosthenes(M)
ddic = defaultdict()
judge = set([])
 
for i in a:
    if not pc:
        break
    asf = sofe.factorization(i)
    
    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)
    
    sum = 0
    for i in range(n):
        root = list(A[:])
        del root[i+1]
        for j in range(1, n+1):
            sum += abs(root[j]-root[j-1])
        print(sum)
        sum = 0


### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)

    sum = 0
    for i in range(1, n+2):
        sum += abs(A[i]-A[i-1])
    for i in range(1, n+1):
        print(sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
### BUGGY CODE ###

h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for i in range(m)]

num_h = [0] * (h+1)
num_w = [0] * (w+1)
for hi,wi in bomb:
  num_h[hi] += 1
  num_w[wi] += 1
  
max_hs = [k for k,v in enumerate(num_h) if v == max(num_h)]
max_ws = [k for k,v in enumerate(num_w) if v == max(num_w)]

result = max(num_h) + max(num_w)
for i in max_hs:
  for j in max_ws:
    if [i,j] not in bomb:
      print(result)
      exit(0)
print(result-1)


### FIXED CODE ###

h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for i in range(m)]

num_h = [0] * (h+1)
num_w = [0] * (w+1)
bomb_set = set()
for hi,wi in bomb:
  num_h[hi] += 1
  num_w[wi] += 1
  bomb_set.add((hi,wi))
  
max_h = max(num_h)
max_w = max(num_w)
max_hs = [k for k,v in enumerate(num_h) if v == max_h]
max_ws = [k for k,v in enumerate(num_w) if v == max_w]

result = max_h + max_w
for i in max_hs:
  for j in max_ws:
    if (i,j) not in bomb_set:
      print(result)
      exit(0)
print(result-1)
### BUGGY CODE ###

import numpy as np


S = input()
dp = np.zeros((int(1e5+1), 4), dtype=np.int64)
i = 0
mod = 1e9+7
dp[0][0] = 1
for s in S:
    if s == '?':
        dp[i+1] = dp[i]*3 % mod
        dp[i+1][1:] += dp[i][:3]
        dp[i+1] = np.remainder(dp[i+1], mod)
    else:
        dp[i+1] = dp[i]
        if s == 'A':
            dp[i+1][1] += dp[i][0]
            dp[i+1][1] = np.remainder(dp[i+1][1], mod)
        elif s == 'B':
            dp[i+1][2] += dp[i][1]
            dp[i+1][2] = np.remainder(dp[i+1][2], mod)
        elif s == 'C':
            dp[i+1][3] += dp[i][2]
            dp[i+1][3] = np.remainder(dp[i+1][3], mod)
    i += 1
print(dp[len(S)][3])

### FIXED CODE ###

import numpy as np


dp = np.zeros((2, 4), dtype=np.int64)
mod = 1e9+7
dp[0][0] = 1
for s in input():
    if s == '?':
        dp[1] = dp[0]*3
        dp[1][1:] += dp[0][:3]
        dp[1] = np.remainder(dp[1], mod)
    else:
        dp[1] = dp[0]
        if s == 'A':
            dp[1][1] += dp[0][0]
            dp[1][1] = np.remainder(dp[1][1], mod)
        elif s == 'B':
            dp[1][2] += dp[0][1]
            dp[1][2] = np.remainder(dp[1][2], mod)
        elif s == 'C':
            dp[1][3] += dp[0][2]
            dp[1][3] = np.remainder(dp[1][3], mod)
    dp[0] = dp[1]
print(dp[0][3])
### BUGGY CODE ###

import itertools

X, Y, Z, K  = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse = True)
ans = [ab + c for (ab, c) in list(itertools.product(AB[:K], C))]
ans.sort(reverse = True)

for i in range(K):
    print(ans[i])

### FIXED CODE ###

X, Y, Z, K  = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

l = []
for a in A:
    for b in B:
        l.append(a+b)
l = sorted(l, reverse = True)[:K]

ans = []
for c in C:
    for k in l:
        ans.append(c + k)
        
ans = sorted(ans, reverse = True)
print(*ans[:K], sep="\n")
### BUGGY CODE ###

import numpy as np

#a, b = map(int, input().split())
N = int(input())

#map(int, input().split())

P = list(map(int, input().split()))

cnt = 1

for i in range(1, N):
    if P[i] < min(P[:i]):
        cnt += 1
print(cnt)
        


### FIXED CODE ###

import numpy as np

#a, b = map(int, input().split())
N = int(input())

#map(int, input().split())

# def bubble_sort(lst):
#     cnt = 0
#     for i in range(len(lst)-1):
#         for j in range(len(lst)-1, i, -1):
#             if lst[j-1] > lst[j]:
#                 tmp = lst[j]
#                 lst[j] = lst[j-1]
#                 lst[j-1] = tmp
#                 cnt += 1
#     return cnt

P = list(map(int, input().split()))

cnt = 1

tmp = P[0]
for i in range(1, N):    
    if P[i] < tmp:
        tmp = P[i]
        cnt += 1
        
            
print(cnt)
### BUGGY CODE ###

n=int(input())
v=list(map(int,input().split()))
odd=v[1::2]
even=v[0::2]
a=[]
b=[]
lodd=list(set(odd))
leven=list(set(even))
for i in range(len(lodd)):
    a.append([odd.count(lodd[i]),lodd[i]])
for i in range(len(leven)):
    b.append([even.count(leven[i]),leven[i]])
a.sort()
b.sort()
if a[-1][1]!=b[-1][1]:
    print(n-a[-1][0]-b[-1][0])
if a[-1][1]==b[-1][1]:
    if len(a)>1 and len(b)>1:
        print(min(n-a[-1][0]-b[-2][0],n-a[-2][0]-b[-1][0]))
    if len(a)>1 and len(b)==1:
        print(n-a[-2][0]-b[-1][0])
    if len(a)==1 and len(b)>1:
        print(n-a[-1][0]-b[-2][0])
    if len(a)==1 and len(b)==1:
        print(n//2)

### FIXED CODE ###

from collections import Counter
n=int(input())
v=list(map(int,input().split()))
odd=v[1::2]
even=v[0::2]
a=Counter(odd)
b=Counter(even)
if a.most_common()[0][0]!=b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
else:
    if len(a)>1 and len(b)>1:
        print(min(n-a.most_common()[0][1]-b.most_common()[1][1],n-a.most_common()[1][1]-b.most_common()[0][1]))
    elif len(a)>1 and len(b)==1:
        print(n-a.most_common()[1][1]-b.most_common()[0][1])
    elif len(a)==1 and len(b)>1:
        print(n-a.most_common()[0][1]-b.most_common()[1][1])
    elif len(a)==1 and len(b)==1:
        print(n//2)
### BUGGY CODE ###

k=int(input())
sum=0

def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
    
for i in range(1,k+1):
  for j in range(1,k+1):
    for z in range(1,k+1):
      sum+=gcd(i,gcd(j,z))
      
print(sum)

### FIXED CODE ###

k=int(input())
sum=0

def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
    
for i in range(1,k+1):
  for j in range(1,k+1):
    for z in range(1,k+1):
      sum+=gcd(i,gcd(j,z))
      
print(sum)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
M = N//2
if N % 2 == 1 and A.count(0) == 1 and all(A.count(i*2+2)==2 for i in range(N//2)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(A.count(i*2+1)==2 for i in range(N//2)):
    print((2 ** M) % (10**9+7))
else:
    print(0)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
M = N//2
c = Counter(A)
if N % 2 == 1 and A.count(0) == 1 and all(c[i*2+2] == 2 for i in range(M)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(c[i*2+1]==2 for i in range(M)):
    print((2 ** M) % (10**9+7))
else:
    print(0)
### BUGGY CODE ###

s = str(input())

num = [int(s[i:]) for i in range(len(s))]
mod = [1] + [0] * 2018

ans = 0
for i in num:
    m = i % 2019
    ans += mod[m]
    mod[m] += 1

print(ans)

### FIXED CODE ###

s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
    num.append(tmp % 2019)

mod = [1] + [0] * 2018
ans = 0
for i in num:
    m = i % 2019
    ans += mod[m]
    mod[m] += 1
print(ans)