Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# ABC157b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    bing = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    for num in b:
        for i in bing:
            try:
                while True:
                    t = i.index(num)
                    i[t] = -1
            except:
                continue
    # print(bing)

    naname = [((0, 0), (1, 1), (2, 2)), (2, 0), (1, 1), (0, 2)]
    if sum(bing[0]) == -3 or sum(bing[1]) == -3 or sum(bing[2]) == -3 or bing[0][0]+bing[1][0]+bing[2][0] == -3 or bing[0][1]+bing[1][1]+bing[2][1] == -3 or bing[0][2]+bing[0][2]+bing[0][2] == -3 or bing[0][0]+bing[1][1]+bing[2][2] == -3 or bing[0][2]+bing[1][1]+bing[2][0] == -3:
        print('Yes')
        exit(0)

    print('No')

    d = [(1, 0), (1, 1), (0, 1)]
    for i in range(3):
        if sum(bing[i]) == -3:
            


if __name__ == '__main__':
    main()


Fixed submission:
# ABC157b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    bing = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    b = [int(input()) for _ in range(n)]
    for num in b:
        for i in bing:
            try:
                while True:
                    t = i.index(num)
                    i[t] = -1
            except:
                continue
    # print(bing)

    naname = [((0, 0), (1, 1), (2, 2)), (2, 0), (1, 1), (0, 2)]
    if sum(bing[0]) == -3 or sum(bing[1]) == -3 or sum(bing[2]) == -3 or bing[0][0]+bing[1][0]+bing[2][0] == -3 or bing[0][1]+bing[1][1]+bing[2][1] == -3 or bing[0][2]+bing[1][2]+bing[2][2] == -3 or bing[0][0]+bing[1][1]+bing[2][2] == -3 or bing[0][2]+bing[1][1]+bing[2][0] == -3:
        print('Yes')
        exit(0)

    print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    maxI = 0
    maxT = 0
    t = 0
    for i in range(n):
        t += p[i]
        if k <= i:
            t -= p[i-k]
        if maxT < t:
            maxT = t
            maxI = i
    ans = 0
     
     
    def calc(n):
        ans = 0
        for i in range(1, n+1):
            ans += i/n
        return ans
     
     
    for i in range(maxI-k+1, maxI+1):
        #print(i, p[i])
        ans += calc(p[i])
    # print(p)
    #print(maxT, maxI)
    print(ans)

Fixed submission:
# ABC154d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    pos = 0

    def cum(array):
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    def calc(N):
        t = 0
        for i in range(1, N+1):
            t += i / N
        return t

    p2 = cum(p)

    for i in range(n - k+1):
        if ans < p2[i+k]-p2[i]:
            ans = p2[i+k]-p2[i]
            pos = i

    ans = 0
    for i in range(pos, pos + k):
        ans += calc(p[i])
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
maxI = 0
maxT = 0
t = 0
for i in range(n):
    t += p[i]
    if k <= i:
        t -= p[i-k]
    if maxT < t:
        maxT = t
        maxI = i
ans = 0


def calc(n):
    ans = 0
    for i in range(1, n+1):
        ans += i/n
    return ans


for i in range(maxI-k+1, maxI+1):
    #print(i, p[i])
    ans += calc(p[i])
# print(p)
#print(maxT, maxI)
print(ans)


Fixed submission:
# ABC154d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    pos = 0

    def cum(array):
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    def calc(N):
        t = 0
        for i in range(1, N+1):
            t += i / N
        return t

    p2 = cum(p)

    for i in range(n - k+1):
        if ans < p2[i+k]-p2[i]:
            ans = p2[i+k]-p2[i]
            pos = i

    ans = 0
    for i in range(pos, pos + k):
        ans += calc(p[i])
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC153e


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    h, n = map(int, input().split())
    maho = []
    for _ in range(n):
        maho.append(list(map(int, input().split())))

    # dp[i][j]=i番目までの魔法でモンスターの体力をj減らすためにつかう魔力の最小値
    # dp[i][j]=min(dp[i-1][j],dp[i][j-maho[i][0]])+maho[i][1]

    dp = [[10 ** 12] * (h + 1) for _ in range(3)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(h + 1):
            if j == 0:
                dp[(i + 1) % 3][0] = 0
            dp[(i + 1) % 3][j] = min(dp[i % 3][j],
                                     dp[(i + 1) % 3][max(0, j - maho[i][0])] + maho[i][1])
    print(dp[n % 3][h])


if __name__ == '__main__':
    main()


Fixed submission:
# ABC153e


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    h, n = map(int, input().split())
    maho = []
    for _ in range(n):
        maho.append(list(map(int, input().split())))

    # dp[i][j]=i番目までの魔法でモンスターの体力をj減らすためにつかう魔力の最小値
    # dp[i][j]=min(dp[i-1][j],dp[i][j-maho[i][0]])+maho[i][1]

    dp = [[10 ** 12] * (h + 1) for _ in range(3)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(h + 1):
            if j == 0:
                dp[(i + 1) % 3][0] = 0
            dp[(i + 1) % 3][j] = min(dp[i % 3][j],
                                     dp[(i + 1) % 3][max(0, j - maho[i][0])] + maho[i][1])
    print(dp[n % 3][h])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC153e


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    h, n = map(int, input().split())
    maho = []
    for _ in range(n):
        maho.append(list(map(int, input().split())))

    # dp[i][j]=i番目までの魔法でモンスターの体力をj減らすためにつかう魔力の最小値
    # dp[i][j]=min(dp[i-1][j],dp[i][j-maho[i][0]])+maho[i][1]

    dp = [[10 ** 12] * (h + 1) for _ in range(n+1)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(h + 1):
            if j == 0:
                dp[i + 1][0] = 0
            dp[i + 1][j] = min(dp[i][j],
                               dp[i + 1][max(0, j - maho[i][0])] + maho[i][1])
    print(dp[n][h])


if __name__ == '__main__':
    main()


Fixed submission:
# ABC153e


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    h, n = map(int, input().split())
    maho = []
    for _ in range(n):
        maho.append(list(map(int, input().split())))

    # dp[i][j]=i番目までの魔法でモンスターの体力をj減らすためにつかう魔力の最小値
    # dp[i][j]=min(dp[i-1][j],dp[i][j-maho[i][0]])+maho[i][1]

    dp = [[10 ** 12] * (h + 1) for _ in range(3)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(h + 1):
            if j == 0:
                dp[(i + 1) % 3][0] = 0
            dp[(i + 1) % 3][j] = min(dp[i % 3][j],
                                     dp[(i + 1) % 3][max(0, j - maho[i][0])] + maho[i][1])
    print(dp[n % 3][h])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC152c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    p = list(map(int, input().split()))

    cou = 0
    for i in range(n):
        for j in range(i):
            if p[j] < p[i]:
                cou += 1
                break
    print(n-cou)


if __name__ == '__main__':
    main()


Fixed submission:
# ABC152c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    p = list(map(int, input().split()))

    cou = 0
    m = 10**9
    for i in range(n):
        if m < p[i]:
            cou += 1
        m = min(m, p[i])
    print(n-cou)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC149c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

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

    if x == 2:
        print(2)
        exit(0)

    def prime_numbers(right):
        pn = [2]
        for L in range(3, right):
            chk = True
            for L2 in pn:
                if L % L2 == 0:
                    chk = False
            if chk == True:
                pn.append(L)
                if L >= x:
                    print(L)
                    exit(0)
        return pn

    l = prime_numbers(x*x)


if __name__ == '__main__':
    main()


Fixed submission:
# ABC149c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

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

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    for i in range(x, x * x):
        if len(prime_factorize(i)) < 2:
            print(i)
            exit(0)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations


def c_count(n, r):  # 組み合わせ
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
s = input()

ans = set()

for i in combinations(s, 3):
    ans.add(i)

print(len(ans))


Fixed submission:
from itertools import combinations


n = int(input())
s = input()
ans = 0
for i in range(1000):
    num = '{:0=3}'.format(i)
    inds = 0
    indnum = 0
    while inds < len(s) and indnum < 3:
        if s[inds] == num[indnum]:
            indnum += 1
        inds += 1
    if indnum == 3:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2==1:
  print(No)
  exit(0)
if s[:n//2]==s[n//2:]:
  print('Yes')
  exit(0)
print('No')

Fixed submission:
# ABC145b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    s = input()[:-1]
    print('Yes' if s[:n//2] == s[n//2:] else 'No')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2==1:
  print(No)
  exit(0)
if s[:i//2]==s[i//2:]:
  print('Yes')
  exit(0)
print('No')
  

Fixed submission:
# ABC145b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    s = input()[:-1]
    print('Yes' if s[:n//2] == s[n//2:] else 'No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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


ans = 0

for x, y, z in itertools.combinations(l, 3):
    if x < y + z and y < z + x and z < x + y:
        ans += 1

print(ans)

Fixed submission:
import bisect

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


ans = 0

l.sort()
# print(l)
for x in range(n):
    for y in range(x+1, n):
        t = bisect.bisect_left(l, max(l[x] - l[y], l[y] - l[x])+1, y+1)
        #print(l[x], l[y], max(l[x] - l[y], l[y] - l[x]), t, l[t])
        t2 = bisect.bisect_left(l, l[x] + l[y], y+1)
        #print(t2, l[t2] if t2 < n else None)
        #print(t2 - t)
        t3 = t2 - t
        if t3 > 0:
            ans += t3
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC141c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

sanka = [k]*n

for i in a:
    sanka[i-1] += 1
    for j in range(n):
        sanka[j] -= 1
# print(sanka)

for i in sanka:
    print('Yes' if i > 0 else 'No')

Fixed submission:
# ABC141c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

sanka = [0]*n

for i in a:
    sanka[i-1] += 1
# print(sanka)

for i in sanka:
    print('Yes' if i+k-q > 0 else 'No')
Buggy python submission (verdict: Runtime Error):
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())
print(max(a+b, a-b, a*b))

Fixed submission:
# ABC137a
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())
print(max(a+b, a-b, a*b))
Buggy python submission (verdict: Time Limit Exceeded):
# 最初に入れておくとinputが早くなる
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n

for i in range(0, a[0]*2+1, 2):
    ans[0] = i
    tempa = a.copy()
    for j in range(n):
        tempa[j % n] = ans[j % n] // 2
        if(j+1 != n):
            ans[(j+1) % n] = (a[j]-tempa[j])*2
    if (ans[0] == (a[n - 1] - tempa[n - 1]) * 2):
        break
# tempa[1 % 3] = ans[1 % 3]/2
# ans[2 % 3] = (a[1]-tempa[1])*2
# tempa[2 % 3] = ans[2 % 3]/2
# ans[3 % 3] = (a[2 % 3]-tempa[2 % 3])*2
# tempa[3 % 3] = ans[3 % 3] / 2
# print(a)
# print(tempa)
print(*ans)

Fixed submission:
# 最初に入れておくとinputが早くなる
import sys
import numpy as np
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
b = 0
for i in range(1, n-1, 2):
    b += a[i]
ans[0] = sum(a)-2*b

tempa = [0]*n
for j in range(n):
    tempa[j] = ans[j % n] // 2
    if(j+1 != n):
        ans[(j + 1) % n] = (a[j] - tempa[j]) * 2
    #print(a, tempa, ans)
print(*ans)
Buggy python submission (verdict: Runtime Error):
# 最初に入れておくとinputが早くなる
import sys
from math import gcd
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
a -= 1
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / gcd(c, d)

print(b-a-b//c+a//c-b//d+b//k+a//d-a//k)

Fixed submission:
from fractions import gcd

a,b,c,d=map(int,input().split())
lcm=int(c*d/gcd(c,d))
A=a-1
x1=A-A//c-A//d+A//lcm
x2=b-b//c-b//d+b//lcm
print(x2-x1)

Buggy python submission (verdict: Runtime Error):
# 最初に入れておくとinputが早くなる
import sys
import math
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / math.gcd(c, d)

print(b-a-b//c+a//c-b//d+b//k+a//d-a//k)

Fixed submission:
from fractions import gcd

a,b,c,d=map(int,input().split())
lcm=int(c*d/gcd(c,d))
A=a-1
x1=A-A//c-A//d+A//lcm
x2=b-b//c-b//d+b//lcm
print(x2-x1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = dict()

for i in range(n):
    for j in range(i+1, n):
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        if ans.get((p, q)) == None:
            ans[(p, q)] = 1
        else:
            ans[(p, q)] += 1
print(list(ans.values()).count(max(ans.values())))

Fixed submission:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = dict()

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

for i in range(n):
    for j in range(n):
        if (i == j):
            continue
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        if ans.get((p, q)) == None:
            ans[(p, q)] = 1
        else:
            ans[(p, q)] += 1
# print(ans)
print(n-max(ans.values()))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
k = []
for _ in range(m):
    k.append(list(map(int, input().split())))
p = list(map(int, input().split()))

denkyu = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
memo = []
memos = []


def erabu(i, n, c, d):
    if (i > len(k[d][1:])):
        if(c % 2 == p[d]):
            memo.append(n)
        return
    if(i+1 in k[d][1:]):
        erabu(i+1, n.append(i+1), c+1, d)
    erabu(i + 1, n, c, d)


print(memo)

for i in range(m):
    erabu(0, 0, 0, i)
    memos.append(memo)

# for i in range(len(memos[0])):

# def isOK(i, n):
 #   if (n ^ memos[i][j] not 0)


Fixed submission:
n, m = map(int, input().split())
switches = []
for _ in range(m):
    switches.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))

ans = 0
switchState = [0]*n


def dfs(i, tukeru):
    #print(i, tukeru)
    if(i == n):
        sumOfTento = 0
        for denkyu in range(m):
            sumOfswitch = 0
            for switch in switches[denkyu]:
                sumOfswitch += switchState[switch-1]
            if(sumOfswitch % 2 == p[denkyu]):
                sumOfTento += 1
        # print(switchState)
        if(sumOfTento == m):
            return 1
        else:
            return 0
    switchState[i] = tukeru
    return dfs(i+1, 0) + (dfs(i+1, 1) if i != n-1 else 0)


print(dfs(0, 0)+dfs(0, 1))
Buggy python submission (verdict: Runtime Error):
# Union-Find木
import sys
input = sys.stdin.readline

n = int(input())
tree = [0]
for i in range(1, n+1):
    tree.append(i)


def root(x):
    if(tree[x] == x):
        return x
    tree[x] = root(tree[x])
    return tree[x]  # 経路圧縮


def same(x, y):  # xとyが同じ木に属するか
    return root(x) == root(y)


def unite(x, y):
    x = root(x)
    y = root(y)
    if(x == y):
        return
    tree[x] = y


for _ in range(n-1):
    u, v, w = map(int, input().split())
    if(w % 2 == 0):
        unite(u, v)

for i in range(1, n+1):
    if (same(1, i)):
        print(0)
    else:
        print(1)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    edge = [dict() for _ in range(n)]
    dist = [0]*n
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edge[u-1].update({v-1: w})
        edge[v-1].update({u-1: w})

    def dfs(i, pre, d):
        dist[i] = d
        for v in edge[i].keys():
            if v == pre:
                continue
            dfs(v, i, d+edge[i][v])

    dfs(0, -1, 0)
    # print(dist)

    for i in dist:
        if i % 2 == 0:
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
tree = [0]
for i in range(1, n+1):
    tree.append(i)


def root(x):
    if(tree[x] == x):
        return x
    tree[x] = root(tree[x])
    return tree[x]  # 経路圧縮


def same(x, y):  # xとyが同じ木に属するか
    return root(x) == root(y)


def unite(x, y):
    x = root(x)
    y = root(y)
    if(x == y):
        return
    tree[x] = y


for _ in range(n-1):
    u, v, w = map(int, input().split())
    if(w % 2 == 0):
        unite(u, v)

for i in range(1, n+1):
    if (same(1, i)):
        print(0)
    else:
        print(1)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    edge = [dict() for _ in range(n)]
    dist = [0]*n
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edge[u-1].update({v-1: w})
        edge[v-1].update({u-1: w})

    def dfs(i, pre, d):
        dist[i] = d
        for v in edge[i].keys():
            if v == pre:
                continue
            dfs(v, i, d+edge[i][v])

    dfs(0, -1, 0)
    # print(dist)

    for i in dist:
        if i % 2 == 0:
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

slength = len(s)
for _ in range(5000):
    s = s.replace("01", "").replace("10", "")
print(slength-len(s))

Fixed submission:
s = input()
n0 = s.count("0")
print(2*min(n0, len(s)-n0))
Buggy python submission (verdict: Runtime Error):
# ABC118c
from fractions import gcd
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#from functools import reduce


def gcds(*numbers):
    return reduce(gcd, numbers)


print(gcds(a))
exit(0)


def solve(l):
    m = min(l)
    nl = list()
    for i in l:
        if i % m != 0:
            nl.append(i % m)
    nl.append(m)
    # print(nl)
    if len(nl) == 1:
        return m
    return solve(nl)


print(solve(a))


Fixed submission:
# ABC118c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def solve(l):
    m = min(l)
    nl = list()
    for i in l:
        if i % m != 0:
            nl.append(i % m)
    nl.append(m)
    # print(nl)
    if len(nl) == 1:
        return m
    return solve(nl)


print(solve(a))
Buggy python submission (verdict: Runtime Error):
# ABC111c
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def calc():
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != f:
                ans += 1
        else:
            if v[i] != f2:
                ans += 1
    return ans


n = int(input())
v = list(map(int, input().split()))
f = Counter(v[::2]).most_common()[0][0]
f2 = Counter(v[1::2]).most_common()[0][0]
if f == f2:
    f2 = Counter(v[1::2]).most_common()[1][0]
    a = calc()
    f = Counter(v[::2]).most_common()[1][0]
    f2 = Counter(v[1::2]).most_common()[0][0]
    print(min(a, calc()))
else:
    print(calc())


Fixed submission:
# ABC111c
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def calc():
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != f:
                ans += 1
        else:
            if v[i] != f2:
                ans += 1
    return ans


n = int(input())
v = list(map(int, input().split()))
V1 = Counter(v[::2]).most_common()
V2 = Counter(v[1::2]).most_common()
f = V1[0][0]
f2 = V2[0][0]
if f == f2:
    if len(V2) > 1:
        f2 = V2[1][0]
    else:
        f2 = 'x'
    a = calc()
    if len(V1) > 1:
        f = V1[1][0]
    else:
        f = 'x'
    f2 = V2[0][0]
    print(min(a, calc()))
else:
    print(calc())