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

n=int(input())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=[[0,0]for i in range(n)]
p=0
mod=10**9+7
for i in range(n,0,-1):
    if a[i-1]!=a[i]:
        c[i-1]=[1,a[i]]
    else:
        c[i-1]=[0,a[i]]
for i in range(n):
    if b[i]!=b[i+1]:
        if c[i][0]==1:
            if b[i]!=c[i][1]:
                print(0)
                break
        else:
            if b[i]<=c[i][1]:
                c[i]=[1,b[i]]
            else:
                print(0)
                break
    else:
        if c[i][0]!=1:
            c[i]=[0,min(b[i],c[i][1])]
        else:
            if c[i][1]>b[i]:
                print(0)
                break
else:
    d=1
    for i in range(n):
        if c[i][0]!=1:
            d*=c[i][1]%mod
    print(d%mod)

### FIXED CODE ###

n=int(input())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=[[0,0]for i in range(n)]
p=0
mod=10**9+7
d=1
for i in range(n,0,-1):
    if a[i-1]!=a[i]:
        c[i-1]=[1,a[i]]
    else:
        c[i-1]=[0,a[i]]
for i in range(n):
    if b[i]!=b[i+1]:
        if c[i][0]==1:
            if b[i]!=c[i][1]:
                print(0)
                break
        else:
            if b[i]<=c[i][1]:
                c[i]=[1,b[i]]
            else:
                print(0)
                break
    else:
        if c[i][0]!=1:
            c[i]=[0,min(b[i],c[i][1])]
        else:
            if c[i][1]>b[i]:
                print(0)
                break
    if c[i][0]!=1:
        d=d*c[i][1]%mod
else:
    print(d)
### BUGGY CODE ###

import math
N, M = map(int, input().split())
MOD = 10 ** 9 + 7

def factoring(k): #kを因数分解し、素因数とその個数を辞書に入れて返す。
    dic = dict()
    n = int(math.sqrt(k))+2
    for i in range(2, n):
        count = 0
        while k%i == 0:
            count += 1
            k = k//i
        if count != 0:
            dic[i] = count
    if k != 1:
        dic[k] = 1
    return dic

def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    import math
    return (math.factorial(n) //(math.factorial(r) * math.factorial(n-r)))%MOD
dic = factoring(M)
ans = 1
for i in dic:
    ans = (ans * conbination(dic[i]+N-1, dic[i]))%MOD
print (ans)

    



### FIXED CODE ###

import math
N, M = map(int, input().split())
MOD = 10 ** 9 + 7

def factoring(k): #kを因数分解し、素因数とその個数を辞書に入れて返す。
    dic = dict()
    n = int(math.sqrt(k))+2
    for i in range(2, n):
        count = 0
        while k%i == 0:
            count += 1
            k = k//i
        if count != 0:
            dic[i] = count
    if k != 1:
        dic[k] = 1
    return dic

def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    import math
    return (math.factorial(n) //(math.factorial(r) * math.factorial(n-r)))%MOD
dic = factoring(M)
ans = 1
for i in dic:
    ans = (ans * conbination(dic[i]+N-1, dic[i]))%MOD
print (ans)
### BUGGY CODE ###

import numpy as np

#1. input
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

#2. calculate the answer
ans = [0]*N 
for i in range(N):
    #2.1 delete the i-th element
    Awithout_i = np.r_[A[:i], A[i+1:]]  
    #2.2 make the difference list
    subted = np.r_[Awithout_i, 0]
    subting = np.r_[0, Awithout_i]
    difference = np.abs(subted - subting)

    #2.3 sum the difference and output
    ans[i] = np.sum(difference)
    print(ans[i])

### FIXED CODE ###

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

#2. make distance list
a.append(0)
a.insert(0,0)
costs = []

for i in range(n+1):
    costs.append(abs(a[i+1]-a[i]))

#3. calculate each cost
total = sum(costs)
for i in range(n):
    print(total - costs[i] - costs[i+1] + abs(a[i+2]-a[i]))
### BUGGY CODE ###

from functools import lru_cache


N, W = list(map(int, input().split(" ")))

l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)

print(dp(N-1, 0, W))

### FIXED CODE ###

N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])
### BUGGY CODE ###

n = input()
a = list(map(int, input().split()))
b= []
for i in range(len(a)):
    b.append(a[i]%(10**9+7))
sum = 0

for i in range(len(b)):
    for j in range(i,len(b)):
        if i<j:
            sum += (b[i]) * (b[j])
    sum %= (10**9+7)
       
    
print(sum)


### FIXED CODE ###

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

for i in range(len(a)):
    b -= a[i]
    sum += a[i]*b   

print(sum%(10**9+7))
### BUGGY CODE ###

N = int(input())
c = 0
if (N % 2) == 0:
    for i in range(N,2,-2):
        for j in range(1,10):
            if i % 5**j == 0:
                c += 1
            else:
                break
    print(c)
else:
    print(0)

### FIXED CODE ###

N = int(input())
count = 0
mul = 10

if (N % 2) == 0:
    while True:
        count += N // mul
        mul *= 5
        if mul > N: break
    print(count)
else:
    print(0)
### BUGGY CODE ###

A,B = map(int, input().split())
tmp = B ^ B
for i in range(A,B+1)[::-1]:
    tmp = tmp ^ i
print(tmp)

### FIXED CODE ###

a,b = map(int, input().split())
get = lambda x:[x,1,x+1,0][x%4]
print(get(a-1)^get(b))
### BUGGY CODE ###

#http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
from fractions import *
from math import *
import sys
input = sys.stdin.readline

# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        #data[k] = min(data[2*k+1], data[2*k+2])
        data[k] = gcd(data[2 * k + 1], data[2 * k + 2])

def check(k, x):
    k += N0-1
    data2 = data[:]
    data2[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data2[k] = gcd(data2[2 * k + 1], data2[2 * k + 2])
    #print(data2)
    return data2[0]

N = int(input())
a = [int(i) for i in input().split()]

# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = a[0]
data = [INF]*(2*N0)
#print(data)
for i in range(N):
    update(i, a[i])

#元のセグ木
ans = 1
for i in range(N-1):
    ans = max(ans, check(i+1, a[i]))
else:
    if N % 2 == 1:
        update(N, a[1])
    ans = max(ans, check(0, a[1]))

print(ans)
#print(data)

### FIXED CODE ###

from fractions import *
from math import *

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(n-1):
        gcd_left += [gcd(gcd_left[-1], a[i+1])]
        gcd_right += [gcd(gcd_right[-1], a[-i-2])]
    gcd_right = gcd_right[::-1]
    ans = 1
    for i in range(n):
        if i == 0:
            ans = max(ans, gcd_right[i+1])
        elif i == n-1:
            ans = max(ans, gcd_left[i-1])
        else:
            ans = max(ans, gcd(gcd_left[i-1], gcd_right[i+1]))

    print(ans)

main()
### BUGGY CODE ###

import sys

N,Q = [int(i) for i in sys.stdin.readline().split()]
D=[10**10]*N
D[0]=0
A=[[0]*3 for i in range(N-1)]
Ans=[0]*N
P=[[0]*2 for i in range(Q)]

for i in range(N-1):
    A[i][0],A[i][1] = [int(i) for i in sys.stdin.readline().split()]
    if(A[i][0]==1):
        D[A[i][1]-1]=1
    else:
        D[A[i][1]-1]=D[A[i][0]-1]+1
    A[i][2]=D[A[i][1]-1]
while(max(D)>(10**10)):
    for i in range(N-1):
        if(D[i]>(10**10)):
            D[A[i][1]-1]=D[A[i][0]-1]+1
        A[i][2]=D[A[i][1]-1]

for i in range(Q):
    P[i][0],P[i][1] = [int(i) for i in sys.stdin.readline().split()]
    Ans[P[i][0]-1]+=P[i][1]
A=sorted(A,key=lambda x: x[2])

for i in range (N-1):
    Ans[A[i][1]-1]+=Ans[A[i][0]-1]
print(*Ans)


### FIXED CODE ###

import sys

n, q = [int(i) for i in sys.stdin.readline().split()]
graph = {i: [] for i in range(n)}
ct = [0 for i in range(n)]
for i in range(n - 1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

for i in range(q):
    p, x = [int(i) for i in sys.stdin.readline().split()]
    p -= 1
    ct[p] += x
already = {0}
stack = [(0, ct[0], -1)]
res = [0 for i in range(n)]
while len(stack) > 0:
    cur, cost, _from = stack.pop(-1)
    res[cur] = cost
    for _next in graph[cur]:
        if _next == _from:
            continue
        next_cost = ct[_next]
        stack.append((_next, cost + next_cost, cur))
        already.add(cur)
print(" ".join([str(r) for r in res]))
### BUGGY CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while(e[0] > d):
			if cont == True:
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			else:
				mini = min(kouho)
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			cont = True
			if q < Q-1:
				q = q + 1
				d = int(inputs())
			else:
				flag = True
				q = q + 1
				break
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			cont = False
	for t in [None]*(Q-q):
		print(-1)
main()

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(n):
    if n < 2:
        return []
    if n == 2:
        return [2]
    L = list(range(2, n + 1))
    PL = []
    while True:
        PL.append(L[0])
        L = [i for i in L if i % PL[-1] != 0]
        if L[-1] < PL[-1] ** 2:
            return PL + L

for line in stdin:
    print(len(enum_prime(int(line))))

### FIXED CODE ###

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(n):
    if n < 2:
        return []
    if n == 2:
        return [2]
    L = list(range(2, n + 1))
    PL = []
    while True:
        PL.append(L[0])
        L = [i for i in L if i % PL[-1] != 0]
        if L[-1] < PL[-1] ** 2:
            return PL + L

primelist = enum_prime(999999)
for line in stdin:
    n = int(line)
    cnt = 0
    for p in primelist:
        if n < p:
            break
        cnt += 1
    print(cnt)
### BUGGY CODE ###

#N,W = map(int, input().split())
S=list(map(int,input().split()))
N=S[0]
W=S[1]

C=[[0]*(W+1) for i in range(N+1)]

for i in range(N):
    w,v=map(int, input().split())
    for j in range(W+1):
        if(j>=w):
            C[i+1][j]=max(C[i][j],C[i][j-w]+v)
        else:
            C[i+1][j]=C[i][j]
print(C[N][W])


### FIXED CODE ###

#N,W = map(int, input().split())
S=list(map(int,input().split()))
N=S[0]
W=S[1]

C=[[0]*(W+1) for i in range(N+1)]

for i in range(N):
    w,v=map(int, input().split())
    for j in range(W+1):
        if(j>=w):
            C[i+1][j]=max(C[i][j],C[i][j-w]+v)
        else:
            C[i+1][j]=C[i][j]
print(C[N][W])
### BUGGY CODE ###

import collections
import math
n = int(input())
ls = list(input() for i in range(n))
a = []
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(ls[j])
    t.sort()
    m = " ".join(t)
    a.append(m)
c = collections.Counter(a)
for k in range(len(c)):
    if c.most_common()[k][1] > 1:
        b += combinations_count(c.most_common()[k][1], 2)
    else:
        continue
print(b)

### FIXED CODE ###

import collections
import math
n = int(input())
a = [0]*n
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(input())
    t.sort()
    m = " ".join(t)
    a[j] = m
c = collections.Counter(a)
d = list(c)
for k in range(len(d)):
    if c[d[k]] > 1:
        b += combinations_count(c[d[k]], 2)
    else:
        continue
print(b)
### BUGGY CODE ###

N = int(input())
nums = map(int, input().split())

ans = 1
for n in nums:
  ans *= n

if ans == 0:
  print(0)
elif ans > 10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

ans = 1
if 0 in nums:
  print(0)
else:
  for n in nums:
    ans *= n
    if ans > 10**18:
      print(-1)
      break
  if ans <= 10**18: print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

from functools import lru_cache
@lru_cache(maxsize=None)
def fibo(n):
    if n in A:
        return 0
    elif n == 0 or n == 1:
        return 1
    return fibo(n-2) + fibo(n-1)

print(fibo(N) % 1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
A = set([int(input()) for i in range(M)])
t = 10**9+7
import sys
sys.setrecursionlimit(500000)
from functools import lru_cache
@lru_cache(maxsize=None)
def fibo(n):
    if n in A:
        return 0
    elif n == 0 or n == 1:
        return 1
    return (fibo(n-2) + fibo(n-1)) % t
print(fibo(N) % t)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
al = list(map(int,input().split()))

#a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

#a,bの最小公倍数
def lcm(a, b):
   return a * b // gcd (a, b)


tmp = 1
for a in al:
    tmp = lcm(tmp, a)

ans = 0
for a in al:
    ans += tmp // a
    ans %= 10**9 + 7

print(ans)

### FIXED CODE ###

import fractions
n = int(input())
al = list(map(int,input().split()))
al = sorted(al)
p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a

print(ans % (10**9 + 7))
### BUGGY CODE ###

import fractions
n = int(input())
a = list(map(int, input().split()))
l = a[0]
for i in range(1, n): l = l // fractions.gcd(l, a[i]) * a[i]
print(sum([l // a[i] for i in range(n)]) % 1000000007)

### FIXED CODE ###

import fractions
n = int(input())
a = list(map(int, input().split()))
l = a[0]
for i in range(1, n): l = l // fractions.gcd(l, a[i]) * a[i]
s = 0
for i in range(n): s += l // a[i]
print(s % 1000000007)
### BUGGY CODE ###

from functools import lru_cache

T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())

    def dist(n):
        if n == 0:
            return 0
        if n == 1:
            return D

        ret = min(
            D * n,
            D * abs(n - n // 5 * 5) + C + dist(n // 5),
            D * abs(n - (n + 4) // 5 * 5) + C + dist((n + 4) // 5),
            D * abs(n - n // 3 * 3) + B + dist(n // 3),
            D * abs(n - (n + 2) // 3 * 3) + B + dist((n + 2) // 3),
            D * abs(n - n // 2 * 2) + A + dist(n // 2),
            D * abs(n - (n + 1) // 2 * 2) + A + dist((n + 1) // 2),
        )

        return ret

    print(dist(N))

### FIXED CODE ###

from functools import lru_cache

T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())

    @lru_cache(maxsize=None)
    def dist(n):
        if n == 0:
            return 0
        if n == 1:
            return D

        ret = min(
            D * n,
            D * abs(n - n // 5 * 5) + C + dist(n // 5),
            D * abs(n - (n + 4) // 5 * 5) + C + dist((n + 4) // 5),
            D * abs(n - n // 3 * 3) + B + dist(n // 3),
            D * abs(n - (n + 2) // 3 * 3) + B + dist((n + 2) // 3),
            D * abs(n - n // 2 * 2) + A + dist(n // 2),
            D * abs(n - (n + 1) // 2 * 2) + A + dist((n + 1) // 2),
        )

        return ret

    print(dist(N))
### BUGGY CODE ###

N,M=map(int,input().split())
a=[int(input())-1 for i in range(M)]

mod=10**9+7

if N==1:
    print(1)
    exit()

f=[0]*(N+1)

if 0 in a:
    f[0]=0
else:
    f[0]=1

if 1 in a:
    f[1]=0
else:
    f[1]=f[0]+1

for i in range(2,N):
    if i in a:
        f[i]=0
    else:
        f[i]=f[i-2]+f[i-1]

    f[i]=f[i]%mod

print(f[N-1])

### FIXED CODE ###

N,M=map(int,input().split())

chk=[True]*(10**5+1)
for i in range(M):
    a=int(input())
    chk[a]=False

mod=10**9+7

if N==1:
    print(1)
    exit()

f=[0]*(N+1)
f[0]=1
if chk[1]:
    f[1]=1
else:
    f[1]=0


for i in range(2,N+1):
    if chk[i-2]:
        f[i]+=f[i-2]
    if chk[i-1]:
        f[i]+=f[i-1]
    f[i]=f[i]%mod

print(f[N])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import defaultdict

N,K = map(int,input().split())
A = [int(x) for x in input().split()]

AA = A + A # 2周分
next_same = [None] * (2*N)
last_pos = defaultdict(lambda: None)

for i,a in enumerate(AA):
    j = last_pos[a]
    if j is None:
        last_pos[a] = i
    else:
        next_same[j] = i
        last_pos[a] = i

next_cycle_start = [None] * N

for i,a in enumerate(A[::-1],1):
    i = N - i
    j = next_same[i] + 1
    k = j if j >= N else next_cycle_start[j]
    next_cycle_start[i] = k

x = 0
while True:
    n = next_cycle_start[x]
    q,r = n//N, n%N
    if K > q:
        x = r
        K -= q
    else:
        break

if K == 2:
    answer = []
else:
    answer = []
    while x < N:
        y = next_same[x]
        if y < N:
            x = y + 1
            continue
        else:
            answer.append(str(A[x]))
            x += 1

print(' '.join(answer))

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import defaultdict

N,K = map(int,input().split())
A = [int(x) for x in input().split()]

AA = A + A # 2周分
next_same = [None] * (2*N)
last_pos = defaultdict(lambda: None)

for i,a in enumerate(AA):
    j = last_pos[a]
    if j is None:
        last_pos[a] = i
    else:
        next_same[j] = i
        last_pos[a] = i

# Xの添字で、最後にvisitしたときを持つ。visit = （そこからスタート！）

NK = N * K
visited = [None] * N
x = 0
visited[0] = 0
while True:
    y = next_same[x % N] + (x//N) * N + 1
    if y >= NK:
        break
    if visited[y % N] is not None:
        # 周期が見つかった！
        P = y - visited[y % N]
        y += (NK - y) // P * P
        x = y
        break
    else:
        visited[y % N] = y
        x = y

answer = []
while x < NK:
    y = next_same[x % N] + (x//N) * N + 1
    if y > NK:
        answer.append(A[x%N])
        x += 1
        continue
    x = y

print(' '.join(map(str,answer)))
### BUGGY CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if x + y + z == S:
                ans += 1

print(ans)

### FIXED CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if 0 <= z and z <= K:
            ans += 1

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

import copy
n = int(input())
l=[int(input()) for x in range(n)]
for i in range(n):
    ll=[]
    ll=copy.copy(l)
    ll.remove(l[i])
    print(max(ll))

### FIXED CODE ###

import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=ll[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)
### BUGGY CODE ###

import sys
import re
readline = sys.stdin.readline
def MAIN():
    T = readline().strip()
    P = readline().strip()
    pat = re.compile(P)
    t = 0
    ans = []
    while True:
        t = pat.search(T, t)
        if t is None:
            break
        ans.append(t.start())
        t = t.start() + 1
    if ans:
        print("\n".join(map(str, ans)))
MAIN()



### FIXED CODE ###

def kmpTable(w):
    lw = len(w)
    nx = [-1] * (lw + 1)
    j = -1
    for i in range(lw):
        while j >= 0 and w[i] != w[j]:
            j = nx[j]
        j += 1
        nx[i + 1] = j
    return tuple(nx)
def kmpSearch(s, w):
    ls = len(s)
    start = 0
    w_idx = 0
    ret = []
    nx = kmpTable(w)
    while start + w_idx < ls:
        if s[start + w_idx] == w[w_idx]:
            w_idx += 1
            if w_idx == len(w):
                ret.append(start)
                start = start + w_idx - nx[w_idx]
                w_idx = nx[w_idx]
        else:
            if w_idx == 0:
                start += 1
            else:
                start = start + w_idx - nx[w_idx]
                w_idx = nx[w_idx]
    return ret
T = input()
P = input()
ans = kmpSearch(T, P)

if ans:
    print(*ans, sep="\n")
#    print("\n".join(map(str, ans)))
### BUGGY CODE ###

import heapq
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]))
if max(a)[1]!=max(b)[1]:
    print(n-max(a)[0]-max(b)[0])
elif max(a)[1]==max(b)[1]:
    if len(a)>1 and len(b)>1:
        print(min(n-max(a)[0]-heapq.nlargest(2,b)[1][0],n-heapq.nlargest(2,a)[1][0]-max(b)[0]))
    elif len(a)>1 and len(b)==1:
        print(n-heapq.nlargest(2,a)[1][0]-max(b)[0])
    elif len(a)==1 and len(b)>1:
        print(n-max(a)[0]-heapq.nlargest(2,b)[1][0])
    elif 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)