Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    if i % 2 != n % 2:
        b.insert(0,a[i])
    else:
        b.append(a[i])

for _ in b:
    sys.stdout.write(str(_) + " ")
sys.stdout.write("\n")


Fixed submission:
import sys
from collections import deque

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

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

for _ in b:
    sys.stdout.write(str(_) + " ")
sys.stdout.write("\n")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    if i % 2 != n % 2:
        b.insert(0,a[i])
    else:
        b.append(a[i])

string = ""
for _ in b:
    string = string + str(_) + " "

print(string[:-1])


Fixed submission:
import sys
from collections import deque

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

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

for _ in b:
    sys.stdout.write(str(_) + " ")
sys.stdout.write("\n")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    b.append(a[i])
    b.reverse()

string = ""
for _ in b:
    string = string + str(_) + " "

print(string[:-1])

Fixed submission:
import sys
from collections import deque

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

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

for _ in b:
    sys.stdout.write(str(_) + " ")
sys.stdout.write("\n")
Buggy python submission (verdict: Runtime Error):
from math import log2

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

def f(n):
    return sum(n^i for i in A)

K += 1

if K == 1:
    print(f(0))
else:
    mb = int(log2(K))
    hN = N / 2

    s = 0
    A_ = A.copy()
    for i in range(mb+1):
        s += (0 if sum(i &0x01 for i in A_) >= hN else 1) * (1 << i)
        A_ = [i >> 1 for i in A_]

    if s >= K:
        def g(i, n, k):
            mask = (2**i) - 1
            s_ = (s & mask) | (k - (k & mask))
            s_ -= (s_ & (1 << i))
            return s_

        gl = [g(i, s, K) for i, b in enumerate(f"{K:b}"[::-1]) if b == "1"]
        fl = [f(i) for i in gl]
        print(max(fl))
    else:
        print(f(s))


Fixed submission:
from math import log2

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

def f(n):
    return sum(n^i for i in A)

K += 1

if K == 1:
    print(f(0))
else:
    mb = int(log2(K))
    hN = N / 2

    s = 0
    A_ = A.copy()
    for i in range(mb+1):
        s += (0 if sum(i &0x01 for i in A_) >= hN else 1) * (1 << i)
        A_ = [i >> 1 for i in A_]

    if s >= K:
        def g(i, n, k):
            mask = (2**i) - 1
            s_ = (s & mask) | (k - (k & mask))
            s_ -= (s_ & (1 << i))
            return s_

        gl = [g(i, s, K) for i, b in enumerate("{:b}".format(K)[::-1]) if b == "1"]
        fl = [f(i) for i in gl]
        print(max(fl))
    else:
        print(f(s))
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]

def f(n, h):
    g = {0: 0, 1: abs(h[1] - h[0])}
    def f_(n, h):
        if n in g:
            return g[n]

        g[n] = min(abs(h[n] - h[n-1]) + f_(n-1, h), abs(h[n] - h[n-2]) + f_(n-2, h))
        return g[n]
    return f_(n, h)

print(f(N-1, h))



Fixed submission:
N = int(input())
h = [int(i) for i in input().split()]

def g(n, h):
    g2 = 0
    g1 = abs(h[1] - h[0])
    for i in range(2, n+1):
        g = min(abs(h[i] - h[i-1]) + g1, abs(h[i] - h[i-2]) + g2)
        g2 = g1
        g1 = g
    return g1

print(g(N-1, h))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
A = sorted(int(i) for i in input().split())

k = 2**int(math.log(A[-1], 2) + 1)
c = 0
while A:
    v = A.pop()
    while k > 2*v:
        k //= 2
    w = k - v
    if w in A:
        c += 1
        A.remove(w)
print(c)



Fixed submission:
import math
from collections import defaultdict
N = int(input())
A = sorted(int(i) for i in input().split())

d = defaultdict(lambda: 0)
for i in A:
    d[i] += 1

c = 0
for k in sorted(d.keys(), reverse=True):
    l = 2**int(math.log(k, 2) + 1) - k
    v = d[k]
    if k == l:
        c += v // 2
    elif l in d:
        w = d[l]
        if v > w:
            c += w
            d[l] = 0
        else:
            c += v
            d[l] = w-v
print(c)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
A = sorted((int(i) for i in input().split()), reverse=True)

k = 2**int(math.log(A[0], 2) + 1)

def f(A, k):
    if len(A) == 1:
        return 0

    v = A[0]

    while k >= 2*v:
        k //= 2
    w = k - v

    if w in A[1:]:
        print(k, "=", v, "+", w)
        A.remove(w)
        r = 1
    else:
        r = 0

    return r + f(A[1:], k)
print(f(A, k))

Fixed submission:
import math
from collections import defaultdict
N = int(input())
A = sorted(int(i) for i in input().split())

d = defaultdict(lambda: 0)
for i in A:
    d[i] += 1

c = 0
for k in sorted(d.keys(), reverse=True):
    l = 2**int(math.log(k, 2) + 1) - k
    v = d[k]
    if k == l:
        c += v // 2
    elif l in d:
        w = d[l]
        if v > w:
            c += w
            d[l] = 0
        else:
            c += v
            d[l] = w-v
print(c)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)
B = [2**int(math.log(i, 2)+1) - i for i in A]

c = 0
for i, v in enumerate(B[:-1]):
    print(i, v, A[i+1:])
    if v in A[i+1:]:
        c += 1
        A.remove(v)
print(c)


Fixed submission:
import math
from collections import defaultdict
N = int(input())
A = sorted(int(i) for i in input().split())

d = defaultdict(lambda: 0)
for i in A:
    d[i] += 1

c = 0
for k in sorted(d.keys(), reverse=True):
    l = 2**int(math.log(k, 2) + 1) - k
    v = d[k]
    if k == l:
        c += v // 2
    elif l in d:
        w = d[l]
        if v > w:
            c += w
            d[l] = 0
        else:
            c += v
            d[l] = w-v
print(c)
Buggy python submission (verdict: Runtime Error):
N = int(input())
xyh = [tuple(int(i) for i in input().split()) for i in range(N)]


def H(cx, cy, x, y, h):
    return h + abs(x - cx) + abs(y - cy)


def g(l, cx, cy):
    H_max_l = set(H(cx, cy, x, y, h) for x, y, h in xyh if h == 0)
    h_max = min(H_max_l) if any(H_max_l) else 10**9
    
    TH = set(H(cx, cy, x, y, h) for x, y, h in l if h > 0)
    if len(TH) == 1:
        high = TH.pop()
        if high <= h_max:
            return high
    return -1


def f(l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            h = g(l, cx, cy)
            if h > 0:
                return cx, cy, h

cx, cy, h = f(xyh)
print(cx, cy, h)


Fixed submission:
N = int(input())
xyh = [tuple(int(i) for i in input().split()) for i in range(N)]


def H(cx, cy, x, y, h):
    return h + abs(x - cx) + abs(y - cy)


def g(l, cx, cy):
    H_max_l = set(H(cx, cy, x, y, h) for x, y, h in l if h == 0)
    h_max = min(H_max_l) if any(H_max_l) else -1
    
    TH = set(H(cx, cy, x, y, h) for x, y, h in l if h > 0)
    if len(TH) == 1:
        high = TH.pop()
        if h_max == -1 or high <= h_max:
            return high
    return -1


def f(l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            h = g(l, cx, cy)
            if h > 0:
                return cx, cy, h

cx, cy, h = f(xyh)
print(cx, cy, h)

Buggy python submission (verdict: Runtime Error):
N = int(input())
xyh = [tuple(int(i) for i in input().split()) for i in range(N)]


def H(cx, cy, x, y, h):
    return h + abs(x - cx) + abs(y - cy)


def g(l, cx, cy):
    H_max_l = set(H(cx, cy, x, y, h) for x, y, h in xyh if h == 0)
    h_max = min(H_max_l) if any(H_max_l) else 10**9
    
    TH = set(H(cx, cy, x, y, h) for x, y, h in l if h > 0)
    if len(TH) == 1:
        high = TH.pop()
        if high <= h_max:
            return high
    return -1



def f(l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            h = g(l, cx, cy)
            if h >= 0:
                return cx, cy, h

cx, cy, h = f(xyh)
print(cx, cy, h)


Fixed submission:
N = int(input())
xyh = [tuple(int(i) for i in input().split()) for i in range(N)]


def H(cx, cy, x, y, h):
    return h + abs(x - cx) + abs(y - cy)


def g(l, cx, cy):
    H_max_l = set(H(cx, cy, x, y, h) for x, y, h in l if h == 0)
    h_max = min(H_max_l) if any(H_max_l) else -1
    
    TH = set(H(cx, cy, x, y, h) for x, y, h in l if h > 0)
    if len(TH) == 1:
        high = TH.pop()
        if h_max == -1 or high <= h_max:
            return high
    return -1


def f(l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            h = g(l, cx, cy)
            if h > 0:
                return cx, cy, h

cx, cy, h = f(xyh)
print(cx, cy, h)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = tuple(int(i) for i in input().split())
x = [int(i) for i in input().split()]

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(math.gcd, dx)

print(mdx)


Fixed submission:
from fractions import gcd
from functools import reduce

N, X = tuple(int(i) for i in input().split())
x = [int(i) for i in input().split()]

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(gcd, dx)

print(mdx)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools as itr

N, K = tuple(int(i) for i in input().split())

n = int(N/K)
c1 = list(itr.product(range(n), repeat=3))
c1 = len(c1)

k_2 = K/2

if N < k_2:
    print(0)
elif K%2 != 0:
    print(c1)
else:

    if N < n*K + k_2:
        c2 = list(itr.product(range(n), repeat=3))
    else:
        c2 = list(itr.product(range(n+1), repeat=3))

    c2 = len(c2)
    print(c1 + c2)

Fixed submission:
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, K = tuple(int(i) for i in input().split())

n = int(N/K)
c1 = n**3

k_2 = K/2

if N < k_2:
    print(0)
elif K%2 != 0:
    print(c1)
else:

    if N < n*K + k_2:
        c2 = n**3
    else:
        c2 = (n+1)**3
    print(c1 + c2)
Buggy python submission (verdict: Runtime Error):
H, W = input().split()
H = int(H)
W = int(W)

a = [input() for i in range(W)]

a = [i for i in a if "#" in i]
b = ["".join([for a[i]]) for i in range(H) for j in a]
b = [i for i in b if "#" in i]

a = ["".join([for a[i]]) for i in range(len(b)) for j in b]

for i in a:
  print(i)

Fixed submission:
H, W = tuple(int(i) for i in input().split())
As = [input() for i in range(H)]

a = [i for i in As if "#" in i]
b = ["".join(j[i] for j in a) for i in range(W)]
b_ = [i for i in b if "#" in i]
a_ = ["".join(j[i] for j in b_) for i in range(len(b_[0]))]

for i in a_:
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
def g(l, n, v):
    for i in n:
        for j in range(i[0], i[1]):
            l[j] += v

def f(n, m, A):
    global D
    max_n = max(enumerate(D[n:m], n), key=lambda x:x[1])[0]
    dA = {i for i in A if i[0] <= max_n < i[1]}
    g(D, dA, -1)
    return max_n, A - dA

def ff(n, m, A):
    i, A_ = f(n, m, A)
    A_1 = set(j for j in A_ if j[1] <= i)
    A_2 = A_ - A_1

    a1 = ff(n, i, A_1) if A_1 else 0
    a2 = ff(i+1, m, A_2) if A_2 else 0

    return a1 + a2 + 1


w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

D = [0] * N
g(D, A, 1)

print(ff(1, N, A))



Fixed submission:
w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

A_ = sorted(A, key=lambda x: x[1])
bridge = 0
c = 0
for i in A_:
    if i[0] > bridge:
        bridge = i[1]-1
        c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
def f(n, m, A):
    w = {i: {j for j in A if j[0]<= i < j[1]} for i in range(n, m)}
    # print(w)
    max_n = max(w.items(), key=lambda x:len(x[1]))[0]
    # print("w", A, w[max_n], A- w[max_n])
    return max_n, A - w[max_n]

def ff(n, m, A):
    # print(n ,m ,A)

    i, A_ = f(n, m, A)
    A_1 = set(j for j in A_ if j[1] <= i)
    A_2 = A_ - A_1

    # print(" ", i, A_1, A_2)

    a1 = ff(n, i, A_1) if A_1 else 0
    a2 = ff(i+1, m, A_2) if A_2 else 0

    return a1 + a2 + 1

w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

print(ff(1, N, A))


Fixed submission:
w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

A_ = sorted(A, key=lambda x: x[1])
bridge = 0
c = 0
for i in A_:
    if i[0] > bridge:
        bridge = i[1]-1
        c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
def f(n, m, A):
    w = {i: len([j for j in A if (j[0]<= i < j[1])]) for i in range(n, m)}
    max_n = max(w.items(), key=lambda x:x[1])[0]
    return max_n, [i for i in A if not i[0] <= max_n < i[1]]

def ff(n, m, A):
    i, A_ = f(n, m, A)
    A_1 = [j for j in A_ if j[1] <= i]
    A_2 = [j for j in A_ if not j[1] <= i]

    a1 = ff(n, i, A_1) if A_1 else 0
    a2 = ff(i+1, m, A_2) if A_2 else 0

    return a1 + a2 + 1

w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = [tuple([int(j) for j in input().split()]) for i in range(M)]

print(ff(1, N, A))


Fixed submission:
w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

A_ = sorted(A, key=lambda x: x[1])
bridge = 0
c = 0
for i in A_:
    if i[0] > bridge:
        bridge = i[1]-1
        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
def median(l):
    n = len(l)
    ls = sorted(l)
    if n == 1: return ls[0]
    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)-1]

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

A_ = [A[i] - i - 1 for i in range(N)]

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))

Fixed submission:
import math

def median(l):
    n = len(l)
    ls = sorted(l)
    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)]

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

A_ = [A[i] - i - 1 for i in range(N)]

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

A_ = [A[i] - i for i in range(N)]

A_max = max(A_) + 1
A_min = min(A_) - 1

A_b = [sum([abs(a - i) for a in A_]) for i in range(A_min, A_max+1)]

print(min(A_b))


Fixed submission:
import math

def median(l):
    n = len(l)
    ls = sorted(l)
    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)]

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

A_ = [A[i] - i - 1 for i in range(N)]

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

a = {}
for i in range(m):
    l,r = map(int,input().split())

    for j in range(l,r+1):
        if not j in a:
            a[j] = 1
        else:
            a[j] += 1

count = 0
for key in a.keys():
    if a[key] == m:  
        count +=1                

print(count)

Fixed submission:
n,m = map(int,input().split())
 
min,max  = map(int,input().split())
for i in range(m-1):
    l,r = map(int,input().split())

    if l > max:
        print(0)
        exit(0)

    if r < min:
        print(0)
        exit(0)
 
    if l > min:
        min = l
    
    if r < max:
        max = r
  
 
print(max-min+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

a = []
for i in range(m):
    l,r = map(int,input().split())
    
    if i == 0:
        for j in range(l,r+1):
            a.append(j)
    else:        
        b = []
        for j in range(l,r+1):
            b.append(j)

        c = a.copy()
        for j in c:
            if not j in b:
                a.remove(j)
       
print(len(a))

Fixed submission:
n,m = map(int,input().split())
 
min,max  = map(int,input().split())
for i in range(m-1):
    l,r = map(int,input().split())

    if l > max:
        print(0)
        exit(0)

    if r < min:
        print(0)
        exit(0)
 
    if l > min:
        min = l
    
    if r < max:
        max = r
  
 
print(max-min+1)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(str(input()))

sum = 0
i = 0
flag = 0
while  i < len(s) :

    if s[i] == 'B':
        flag +=1
        i = i+1
    else:
        sum += flag
        s[i] = 'B'
        s[i-flag] = 'W'
        i = i - flag + 1
        flag = 0           

print(sum)

Fixed submission:
s = list(str(input()))

sum = 0
bcount = 0
for i in range(len(s)):
    if s[i] == 'B' :
        bcount += 1
    else :
        sum += bcount

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(str(input()))

sum = 0
i = 0
while True:
    if s[i] == 'B' and s[i+1] == 'W':
        s[i] = 'W'
        s[i+1] = 'B'
        sum += 1
        if i > 0:
            i = i - 1
        else:
            i += 1
    else:
        i += 1
    
    if i >= len(s) - 1:
        break

print(sum)


Fixed submission:
s = list(str(input()))

sum = 0
bcount = 0
for i in range(len(s)):
    if s[i] == 'B' :
        bcount += 1
    else :
        sum += bcount

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())

sum = 0
while True:
    count = s.count('BW')
    if count > 0:
        sum += count
        s = s.replace('BW','WB')
    else:
        break
print(sum)

Fixed submission:
s = list(str(input()))

sum = 0
bcount = 0
for i in range(len(s)):
    if s[i] == 'B' :
        bcount += 1
    else :
        sum += bcount

print(sum)
Buggy python submission (verdict: Runtime Error):
#import time as time

#s = time.time()

n,m = map(int,input().split())
py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):
    p,y = map(int,input().split())
    py.append([p,y])
       
    odlen = len(od[p-1])
    if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen//2

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1

        od[p-1].insert(low,y)

    else:
        od[p-1].append(y)

#print ("sort: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):
    r = od[py[i][0]-1].index(py[i][1])

    tmp = py[i][0]
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(py[i][0],end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    for j in range(6-digit):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Fixed submission:
x,y = map(int,input().split())
print(str(x+(y>>1)))
Buggy python submission (verdict: Runtime Error):
n = int(input())

l = []
for i in range(n):
    x,y,h = map(int,input().split())
    if h > 0 :
        l.append([x,y,h])

for cx in range(100+1):
    for cy in range(100+1):
              
        count = 0
        preheight = abs(l[0][0]-cx) + abs(l[0][1]-cy) + l[0][2]

        for i in range(n):            
            height = abs(l[i][0]-cx) + abs(l[i][1]-cy) + l[i][2] 
            if preheight != height:
                break

            count = count + 1

        if count >= len(l) :
            print(cx,cy,preheight)
            exit(0)


Fixed submission:
n = int(input())

l = []
a = {}
b = {}

for i in range(n):
    x,y,h = map(int,input().split())
    if h > 0 :
        l.append([x,y,h])

for cx in range(100+1):
    for cy in range(100+1):
              
        count = 0
        preheight = abs(l[0][0]-cx) + abs(l[0][1]-cy) + l[0][2]

        for ll in l :
            height = abs(ll[0]-cx) + abs(ll[1]-cy) + ll[2] 
            if preheight != height:
                break
            count = count + 1

        if count >= len(l) :
            if preheight in a:
                a[preheight] += 1
                b[preheight] = [cx,cy]
            else:
                a[preheight] = 1
                b[preheight] = [cx,cy]

for ans in a.keys() :
    if a[ans] == 1 :
        print(b[ans][0],b[ans][1],ans)
        exit(0)
Buggy python submission (verdict: Runtime Error):
n = input()
v = list(map(int,input().split()))

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

print(ev)
print(ov)

sorted(ev.items(),key=lambda x : x[1],reverse=True)
sorted(ov.items(),key=lambda x : x[1],reverse=True)

eidx = 0
oidx = 0
et = list(ev.values())[eidx]
ot = list(ov.values())[oidx]

if et == ot :
    if ev[et] > ov[ot] :
        if len(ot) > 1:
            ot = list(ov.values())[oidx+1]
    else:
        if len(et) > 1:
            et = list(ov.values())[eidx+1]

ans = len(e) - et + len(o) - ot
print(ans)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

ev = sorted(ev.items(),key=lambda x : x[1],reverse=True)
ov = sorted(ov.items(),key=lambda x : x[1],reverse=True)

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
    #li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

ee  = ev[0][0]
oo  = ov[0][0]

es0 = ev[0][1]
os0 = ov[0][1]
ans = n - es0 - os0

if ee == oo:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = ev[1][1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = ov[1][1]
        tmp2 = n  - es0  - os1

    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)