Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    move = sum(B) - sum(A)
    # A行目が大きい場合は、B行目は+１ずつしかできないので追い越せない。
    if move < 0:
        print('No')
        return 0
    Amove = 0
    Bmove = 0
    # 3 4 2
    # 5 3 4
    for i in range(N):
        # A[i] = 4, B[i] = 3 -> Amove = 1
        if A[i] > B[i]:
            Amove += A[i] - B[i]
        # A[i] = 3, B[i] = 5 -> Bmove = 1
        # A[i] = 2, B[i] = 4 -> Bmove = 1
        elif A[i] < B[i]:
            Bmove += (B[i] - A[i]) // 2
    # Amove = 1, Bmove = 1
    if Amove > Bmove:
        print('No')
    else:
        print('Yes')

Fixed submission:
import sys
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    move = sum(B) - sum(A)
    # A行目が大きい場合は、B行目は+１ずつしかできないので追い越せない。
    if move < 0:
        print('No')
        sys.exit()
    Amove = 0
    Bmove = 0
    # 3 4 2
    # 5 3 4
    for i in range(N):
        # A[i] = 4, B[i] = 3 -> Amove = 1
        if A[i] > B[i]:
            Amove += A[i] - B[i]
        # A[i] = 3, B[i] = 5 -> Bmove = 1
        # A[i] = 2, B[i] = 4 -> Bmove = 1
        elif A[i] < B[i]:
            Bmove += (B[i] - A[i]) // 2
    # Amove = 1, Bmove = 1
    if Amove > Bmove:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

move = 0

if n >= m:
  print(move)
elif n==1:
  move = max(x) - min(x)
  print(move)
else:
  x_diff = [None]*(m-1)
  for i in range(m-1):
    x_diff[i] = [i+1, x[i+1] - x[i]]
  x_diff = sorted(x_diff, key=lambda x:-x[1])
  for j in range(n):
    if j==0:
      move += max(x[0:x_diff[j][0]])-min(x[0:x_diff[j][0]])
    elif j==n-1:
      move += max(x[x_diff[j-1][0]:])-min(x[x_diff[j-1][0]:])
    else:
      move += max(x[x_diff[j-1][0]:x_diff[j][0]])-min(x[x_diff[j-1][0]:x_diff[j][0]])
  print(move)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

move = 0

if n >= m:
  print(move)
elif n==1:
  move = max(x) - min(x)
  print(move)
else:
  x_diff = [None]*(m-1)
  for i in range(m-1):
    x_diff[i] = [i+1, x[i+1] - x[i]]
  x_diff = sorted(x_diff, key=lambda x:-x[1])
  sep = sorted(x_diff[:n-1])
  for j in range(n):
    if j==0:
      move += max(x[0:sep[j][0]])-min(x[0:sep[j][0]])
    elif j==n-1:
      move += max(x[sep[j-1][0]:])-min(x[sep[j-1][0]:])
    else:
      move += max(x[sep[j-1][0]:sep[j][0]])-min(x[sep[j-1][0]:sep[j][0]])
  print(move)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int,input().split()))
l = list()

for n in range(N):
    listA=list(map(int,input().split()))
    for i in range(listA[1]):
        l.append(int(listA[0]))

print(sorted(l)[K-1])

Fixed submission:
N, K = list(map(int,input().split()))
l = list()

c = 0
ans = 0
ab_list = list()

for n in range(N):
    a,b =list(map(int,input().split()))
    ab_list.append([a,b])

ab_list = sorted(ab_list, key=lambda x: x[0])

for a,b in ab_list:
    c += b
    if c >= K:
        ans = a    
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
def solve(n, m, a, b):
    islands = sets()

    for i in range(m):
        if(a[i] == 1):
            islands.append(b[i])
        if(b[i] == 1):
            islands.append(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))


Fixed submission:
def solve(n, m, a, b):
    islands = set()

    for i in range(m):
        if(a[i] == 1):
            islands.add(b[i])
        if(b[i] == 1):
            islands.add(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))

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

def solve(n, m, a, b):
    islands = []

    for i in range(m):
        if(a[i] == 1):
            islands.append(b[i])
        if(b[i] == 1):
            islands.append(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))


Fixed submission:
def solve(n, m, a, b):
    islands = set()

    for i in range(m):
        if(a[i] == 1):
            islands.add(b[i])
        if(b[i] == 1):
            islands.add(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))
Buggy python submission (verdict: Runtime Error):
s = input()

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        return


Fixed submission:
s = input()

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = []
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.append(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())


Fixed submission:
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())

Buggy python submission (verdict: Runtime Error):

def f(l, a, hist):
    if(a in hist):
        return -1
    if(a == 1):
        return len(hist)
    hist.append(a)
    return f(l,l[a]-1,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0]-1,[0]))

if(__name__ == "__main__"):
    solve()


Fixed submission:
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())

Buggy python submission (verdict: Runtime Error):

def f(l, a, hist):
    if(a in hist):
        return -1
    if(a == 1):
        return len(hist)
    hist.append(a)
    return f(l,l[a]-1,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0]-1,[0]))

if(__name__ == "__main__"):
    solve()


Fixed submission:
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())

Buggy python submission (verdict: Runtime Error):

def f(l, a, hist):
    if(l[a] in hist):
        return -1
    if(l[a] == 1):
        return len(hist)
    hist.append(l[a])
    return f(l,a,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0],[]))

if(__name__ == "__main__"):
    solve()


Fixed submission:
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
def factorial(n) : 
    a = 1
    for i in range(1 , n+1):
        a *= i
    return a

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (factorial(n)**2 * 2) % 1000000007
    if(n > m):
        return (factorial(m)**2 * n) % 1000000007
    else:
        return (factorial(n)**2 * m) % 1000000007

if(__name__ == "__main__"):
    print(solve())

Fixed submission:
import math

mod = 1000000007

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (math.factorial(n)**2 * 2) % mod
    if(n > m):
        return (math.factorial(m)**2 * n) % mod
    else:
        return (math.factorial(n)**2 * m) % mod

if(__name__ == "__main__"):
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def factorial(integer) : 
    product = 1
    if integer == 0 : return 1
    for num in range(1 , integer + 1):
        product *= num
    return product

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (factorial(n) * factorial(m) * 2) % 1000000007
    return (factorial(n) * factorial(m)) % 1000000007

if(__name__ == "__main__"):
    print(solve())


Fixed submission:
import math

mod = 1000000007

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (math.factorial(n)**2 * 2) % mod
    if(n > m):
        return (math.factorial(m)**2 * n) % mod
    else:
        return (math.factorial(n)**2 * m) % mod

if(__name__ == "__main__"):
    print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def f(n):
    a = 1
    for i in range(1, n+1):
        a *= i
    return a

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (f(n) * f(m) * 2) % 1000000007
    return (f(n) * f(m)) % 1000000007

if(__name__ == "__main__"):
    print(solve())


Fixed submission:
import math

mod = 1000000007

def solve():
    (n,m) = map(int,input().split())
    if(abs(n-m)>1):
        return 0
    if(n==m):
        return (math.factorial(n)**2 * 2) % mod
    if(n > m):
        return (math.factorial(m)**2 * n) % mod
    else:
        return (math.factorial(n)**2 * m) % mod

if(__name__ == "__main__"):
    print(solve())
Buggy python submission (verdict: Runtime Error):
import numpy as np
import heapq


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    s = input()
    K = ii()

    sub = []
    for i in range(len(s)):
        sub.append(s[i:])

    heapq.heapify(sub)
    minsub = heapq.heappop(sub)

    if len(minsub) >= K:
        print(minsub[:K])
        return

    cand = []
    for i in range(1, len(minsub)+1):
        cand.append(minsub[:i])
    K -= len(minsub)
    assert K > 0

    min2sub = heapq.heappop(sub)
    for i in range(1, len(min2sub)+1):
        if not min2sub[:i] in cand:
            cand.append(min2sub[:i])
            K -= 1
            if K == 0:
                print(min2sub[:i])
                return

    min3sub = heapq.heappop(sub)
    for i in range(1, len(min3sub)+1):
        if not min3sub[:i] in cand:
            cand.append(min3sub[:i])
            K -= 1
            if K == 0:
                print(min3sub[:i])
                return

    print(minsub, min2sub, min3sub)

    raise ValueError


if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import heapq


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    s = input()
    K = ii()

    sub = []
    for i in range(len(s)):
        sub.append(s[i:])

    heapq.heapify(sub)
    minsub = heapq.heappop(sub)

    if len(minsub) >= K:
        print(minsub[:K])
        return

    cand = []
    for i in range(1, len(minsub)+1):
        cand.append(minsub[:i])
    K -= len(minsub)
    assert K > 0

    while K > 0:
        minsub_ = heapq.heappop(sub)
        for i in range(1, len(minsub_)+1):
            if not minsub_[:i] in cand:
                cand.append(minsub_[:i])
                K -= 1
                if K == 0:
                    print(minsub_[:i])
                    return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
try:
    from functools import lru_cache
except ImportError:
    # For Python2
    # pip install backports.functools_lru_cache
    from backports.functools_lru_cache import lru_cache

class Knapsack(object):
    """
    Maximize sum of selected weight.
    Sum of selected size is les than capacity.
    Algorithm: Dynamic Optimization
    ----
    import knapsack
    size = [21, 11, 15, 9, 34, 25, 41, 52]
    weight = [22, 12, 16, 10, 35, 26, 42, 53]
    capacity = 100
    knapsack.knapsack(size, weight).solve(capacity)
    """
    def __init__(self, size, weight):
        self.size = size
        self.weight = weight

    @lru_cache()
    def solve(self, cap, i=0):
        if cap < 0: return -sum(self.weight), []
        if i == len(self.size): return 0, []
        res1 = self.solve(cap,  i + 1)
        res2 = self.solve(cap - self.size[i], i + 1)
        res2 = (res2[0] + self.weight[i], [i] + res2[1])
        return res1 if res1[0] >= res2[0] else res2


def E():
    N = int(input())
    A, B = [], []

    C = 0
    s = []
    w = []
    ans = 0

    for _ in range(N):
        a, b = list(map(int, input().split(' ')))
        if a <= b:
            C += (b - a)
            ans += b
        else:
            s.append(a - b + 1)
            w.append(b)

        A.append(a)
        B.append(b)

    # print(C, s, w)

    if A == B:
        print(0)

    else:
        _ans, _ = Knapsack(s, w).solve(C)
        print(ans + _ans)


if __name__ == '__main__':
    E()

Fixed submission:
def E():
    N = int(input())

    sum_ = 0
    c = -1

    for _ in range(N):
        a, b = list(map(int, input().split(' ')))
        if a > b:
            if c == -1:
                c = b
            elif b < c:
                c = b
            
        sum_ += a

    if c == -1:
        print(0)
    else:
        print(sum_ - c)
        
if __name__ == '__main__':
    E()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

N, T = map(int, raw_input().split(' '))
t = map(int, raw_input().split(' '))
assert len(t) == N

begin = t[0]
end = t[0] + T
for i in range(N):
    if t[i] <= end:
        end = t[i] + T
    else:
        sum += (end - begin)
        begin = t[i]
        end = t[i] + T

sum += (end - begin)
print sum


Fixed submission:
#!/usr/bin/env python
# coding: utf-8

N, T = map(int, raw_input().split(' '))
t = map(int, raw_input().split(' '))
assert len(t) == N

sum_ = 0
begin = t[0]
end = t[0] + T
for i in range(N):
    if t[i] <= end:
        end = t[i] + T
    else:
        sum_ += (end - begin)
        begin = t[i]
        end = t[i] + T

sum_ += (end - begin)
print sum_
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [int(i) for i in input().split()]

def solve(n):
    if n==0:
        return 0
    elif n==1:
        return abs(h[1]-h[0])
    else:
        return min(abs(h[n]-h[n-1])+solve(n-1),abs(h[n]-h[n-2])+solve(n-2))

print(solve(N-1))

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

c[0]=0
c[1]=abs(h[1]-h[0])
for i in range(2,N):
    c[i] = min(abs(h[i]-h[i-1])+c[i-1],abs(h[i]-h[i-2])+c[i-2])

print(c[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,K=(int(i) for i in input().split())
    h = [int(i) for i in input().split()]
    c = [0]*N
    for i in range(1,N):
        jumpmax = min(i,K)
        c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
    print(c[N-1])

main()

Fixed submission:
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Fixed submission:
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Buggy python submission (verdict: Runtime Error):
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,K+1):
    jumpmax = i
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
for i in range(K+1,N):
    jumpmax = K
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Fixed submission:
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Buggy python submission (verdict: Runtime Error):
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,K+1):
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,i+1)])
for i in range(K+1,N):
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,K+1)])
print(c[N-1])

Fixed submission:
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

Fixed submission:
N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=(int(i) for i in input().split())
h=[int(input()) for i in range(N)]
h.sort()
m = max(h[0:K]) - min(h[0:K])
for i in range(N-K+1):
    d = max(h[i:i+K]) - min(h[i:i+K])
    if m>d:
        m = d
print(m)

Fixed submission:
N,K=(int(i) for i in input().split())
h=[int(input()) for i in range(N)]
h.sort()
m = h[K-1] - h[0] 
for i in range(N-K+1):
    d = h[i+K-1] -h[i]
    if m>d:
        m = d
print(m)
Buggy python submission (verdict: Runtime Error):
N = int(input())
x,y,h=[],[],[]
for i in range(N):
    tmpx, tmpy, tmph = (int(i) for i in input().split())
    x.append(tmpx)
    y.append(tmpy)
    h.append(tmph)

def solve(N,x,y,h):
    for cx in range(101):
        for cy in range(101):
            H = [h[i]+abs(x[i]-cx)+abs(y[i]-cy) for i in range(N)]
            if all([i==H[0] for i in H]):
                return [cx,cy,H[0]]
ans = solve(N,x,y,h)
print(ans[0],ans[1],ans[2])

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

tmpx,tmpy,tmph=0,0,0
for x,y,h in xyh:
    if h>0:
        tmpx,tmpy,tmph=x,y,h
        break

truecx,truecy,trueh=0,0,0
for cx in range(101):
    for cy in range(101):
        largeh=tmph+abs(tmpx-cx)+abs(tmpy-cy)
        flag=True
        for x,y,h in xyh:
            if h != max(largeh-abs(x-cx)-abs(y-cy),0):
                flag = False
                break
        if flag:
            truecx,truecy,trueh=cx,cy,largeh
            break
print(truecx,truecy,trueh)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
V=[int(i) for i in input().split()]

def separate(a):
    b,c=[],[]
    for i in range(len(a)):
        if i%2==1:
            b.append(a[i])
        else:
            c.append(a[i])
    return [b,c]

def appearGetter(a):
    b = list(set(a))
    c=[]
    for i in b:
        c.append([i,a.count(i)])
    return c
    
sep = separate(V)
oddApp=appearGetter(sep[0])
evenApp=appearGetter(sep[1])

oddApp.sort(key=lambda x:x[1])
evenApp.sort(key=lambda x:x[1])

ans=0
if oddApp[-1][0]!=evenApp[-1][0]:
    ans = len(V)-oddApp[-1][1]-evenApp[-1][1]
else:
    if len(oddApp)==1:
        oddApp.append([0,0])
    if len(evenApp)==1:
        evenApp.append([0,0])
    ans1 = len(V)-oddApp[-1][1]-evenApp[-2][1]
    ans2 = len(V)-oddApp[-2][1]-evenApp[-1][1]
    ans = min(ans1,ans2)

print(ans)

Fixed submission:
import collections

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

oddSeq,evenSeq=[],[]
for i in range(N//2):
    oddSeq.append(V[i*2])
    evenSeq.append(V[i*2+1])

oddCounter = collections.Counter(oddSeq)
evenCounter = collections.Counter(evenSeq)

oddMostCommonNumber = oddCounter.most_common()[0][0]
evenMostCommonNumber = evenCounter.most_common()[0][0]

oddMostCommonTimes = oddCounter.most_common()[0][1]
evenMostCommonTimes = evenCounter.most_common()[0][1]

odd2ndCommonNumber = 0
even2ndCommonNumber = 0

odd2ndCommonTimes = 0
even2ndCommonTimes = 0

if len(oddCounter.most_common())!=1:
    odd2ndCommonNumber = oddCounter.most_common()[1][0]
    odd2ndCommonTimes = oddCounter.most_common()[1][1]
if len(evenCounter.most_common())!=1:
    even2ndCommonNumber = evenCounter.most_common()[1][0]
    even2ndCommonTimes = evenCounter.most_common()[1][1]

ans=-1
if evenMostCommonNumber!=oddMostCommonNumber:
    ans = N-oddMostCommonTimes-evenMostCommonTimes
else:
    ans1 = N-oddMostCommonTimes-even2ndCommonTimes
    ans2 = N-odd2ndCommonTimes-evenMostCommonTimes
    ans = min(ans1,ans2)
print(ans)