Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
X,N = map(int,input().split())
if N!=0:
  plist =list(map(int,input().split()))
  print (plist)
  #maxN = max(plist)
  maxN = 100
  Anslist =[i for i in range(X+1)]
  #print (Anslist)
  for i in range(len(plist)):
    Anslist.remove(plist[i])
  Anslist.remove(0)
  #print(Anslist)

  ans = 0
  min=100
  for i in range(len(Anslist)):
    if min>abs(X-Anslist[i]):
      min = abs(X-Anslist[i])
      ans = Anslist[i]
  print(ans)
else :print(X)

Fixed submission:
X,N = map(int,input().split())

min = 100

if N !=0:
  Plist = list(map(int,input().split()))
  anslist = [i for i in range(201)]
  anslist.append(-1)
  #anslist.remove(0)
  Plist = sorted(Plist)
  for i in range(N):
    anslist.remove(Plist[i])
    temp =100
  for i in range(len(anslist)):
    if min >abs(anslist[i]-X) :
      min = abs(anslist[i]-X)
      temp = anslist[i]
  print (temp)
else :
  print (X)

Buggy python submission (verdict: Runtime Error):
X,N = map(int,input().split())
maxN = 100
if N!=0:
  plist =list(map(int,input().split()))
  #maxN = max(plist)
  Anslist =[i for i in range(100)]
  #print (Anslist)
  for i in range(len(plist)):
    Anslist.remove(plist[i])
  Anslist.remove(0)
  #print(Anslist)

  ans = 0
  min=100
  for i in range(len(Anslist)):
    if min>abs(X-Anslist[i]):
      min = abs(X-Anslist[i])
      ans = Anslist[i]
  print(ans)
else :print(X)

Fixed submission:
X,N = map(int,input().split())

min = 100

if N !=0:
  Plist = list(map(int,input().split()))
  anslist = [i for i in range(201)]
  anslist.append(-1)
  #anslist.remove(0)
  Plist = sorted(Plist)
  for i in range(N):
    anslist.remove(Plist[i])
    temp =100
  for i in range(len(anslist)):
    if min >abs(anslist[i]-X) :
      min = abs(anslist[i]-X)
      temp = anslist[i]
  print (temp)
else :
  print (X)
Buggy python submission (verdict: Runtime Error):
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Fixed submission:
a,b = map(int,input().split())
print (a*b)
Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np

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

#ans = np.prod(Alist)
Alist.sort()
ans = 1
for i in range(N):
  #print (Alist[i])
  ans*= Alist[i]
  if Alist[i]==0:
    break

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

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Buggy python submission (verdict: Runtime Error):
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
  	print (-1)
    break
if sum<=(10**18):
  print (sum)

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
if (sum>(10**18)):
  print (-1)
else :
  print (sum)

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
numbers = input().split()
sum = 1
for i in range(num):
  sum *=int(numbers[i])
if (sum>(10**18)):
  print (-1)
else :
  print (sum)

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
numbers = input().split()
sum = 1
for i in range(num):
  numbers[i] = int(numbers[i])
  sum = sum*numbers[i]
if (sum>(10**18)):
  print ('-1')
else :
  print (sum)

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)

Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
numbers = input().split()
n =[]
sum = 1
for i in range(num):
  numbers[i] = int(numbers[i])
  sum = sum*numbers[i]
if (sum>10**18):
	print (-1)
else :
  	print (sum)

Fixed submission:
num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,K = map(int,input().split())

sum = 0
for i in range(A+1):
  for j in range(B+1):
    for l in range(C+1):
      #print (i)
      #print (j)
      #print (l)
      #print("-----")
      if 1*i +0*j+(-1)*l>=sum and i+j+l ==K:
        sum = 1*i +0*j+(-1)*l
print (sum)

Fixed submission:
A,B,C,K = map(int,input().split())

koa = 0
if A<K:
  koa = A
else :
  koa = K
kob = 0
if B<K-koa:
  kob = B
else :
  kob = K-koa
#print (koa)
#print (kob)
sum = koa+0*kob+(K-(koa+kob))*-1
print (sum)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
K = int(input())

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      #print ("gcd({} {} {} )".format(i,j,k))
      sum += gcd(i,j,k)
print (sum)

Fixed submission:
import math

K = int(input())

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    temp = math.gcd(i,j)
    for k in range(1,K+1):
      sum+=math.gcd(temp,k)
print (sum)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())

min = N
while True:
  if min>abs(min-K):
    min = abs(min-K)
  elif min<=abs(min-K):
    break
print (min)

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

min = N%K
if min>abs(min-K):
  min = abs(min-K)

print (min)
Buggy python submission (verdict: Runtime Error):
str = input()
a,b,c = str.split()
if a == b:
  if b == c:
    print ('No')
  else print ('Yes')
else print ('Yes')

Fixed submission:
txt = input()
a,b,c = list(txt)
if a == b:
  if b == c:
    print('No')
  else:
    print('Yes')
else :
  print('Yes')
Buggy python submission (verdict: Runtime Error):
n = list(input())
x = 0
for i in n:
    x += int(i)
if i%9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = list(input())
x = 0
for i in n:
    x += int(i)
if x%9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())
print(a*b)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
ret = 1
for i in L:
    ret *= i
if ret > 10**18:
    print(-1)
else:
    print(ret)

Fixed submission:
n = int(input())
L = sorted(list(map(int, input().split())), reverse=True)
ret = 1
if L[-1] == 0:
    print(0)
else:
    for i in L:
        ret *= i
        if ret > 10**18:
            ret = -1
            break
    print(ret)
Buggy python submission (verdict: Runtime Error):
n = input()
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if int(n[-1]) in hon:
    print('hon')
elif int(n[:-1]) in pon:
    print('pon')
else:
    print('bon')

Fixed submission:
n = input()
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')
else:
    print('bon')

Buggy python submission (verdict: Runtime Error):
n = input()
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if int(n[:-1]) in hon:
    print('hon')
elif int(n[:-1]) in pon:
    print('pon')
else:
    print('bon')

Fixed submission:
n = input()
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')
else:
    print('bon')
Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
l = [1]*a
l.extend([0]*b)
l.extend([-1]*c)
print(sum(l[:k]))

Fixed submission:
a, b, c, k = map(int, input().split())
if a+b >= k:
    print(min(a, k))
else:
    print(a-(k-a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
l = [1]*a + [0]*b + [-1]*c
print(sum(l[:k]))

Fixed submission:
a, b, c, k = map(int, input().split())
if a+b >= k:
    print(min(a, k))
else:
    print(a-(k-a-b))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
K = int(input())
ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a, b), c)
print(ans)

Fixed submission:
from math import gcd
K = int(input())
ans = 0

#すべての要素が等しい場合
for i in range(1,K+1):
    ans += i

#2要素が等しい場合(3*2通り)
for i in range(1,K):
    for j in range(i+1,K+1):
        ans += 6*gcd(i,j)
        
#すべての要素が異なる場合(6通り)
for i in range(1,K-1):
    for j in range(i+1,K):
        for k in range(j+1,K+1):
            ans += 6*gcd(gcd(i,j),k)


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
R,G,B = [],[],[]
for i, char in enumerate(S):
    if char == 'R':
        R.append(i+1)
    if char == 'G':
        G.append(i+1)
    if char == 'B':
        B.append(i+1)
        
ans = len(R)*len(G)*len(B)

for j in R:
    for i in range(1,j):
        k = j*2 - i
        if i in G and k in B:
            ans -= 1
        elif i in B and k in G:
            ans -= 1

for j in G:
    for i in range(1,j):
        k = j*2 - i
        if i in R and k in B:
            ans -= 1
        elif i in B and k in R:
            ans -= 1

for j in B:
    for i in range(1,j):
        k = j*2 - i
        if i in G and k in R:
            ans -= 1
        elif i in R and k in G:
            ans -= 1
            
print(ans)

Fixed submission:
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for d in range(N):
        j = i + d
        k = i + 2*d
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
R,G,B = [],[],[]
for i, char in enumerate(S):
    if char == 'R':
        R.append(i+1)
    if char == 'G':
        G.append(i+1)
    if char == 'B':
        B.append(i+1)
        
ans = len(R)*len(G)*len(B)
for i in R:
    for j in G:
        for k in B:
            L = sorted([i,j,k])
            if L[0]+L[2]==2*L[1]:
                ans -= 1
            
print(ans)

Fixed submission:
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for d in range(N):
        j = i + d
        k = i + 2*d
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(int(input().split()))
ret = 'APPROVED'
for i in a:
    if i%2 == 0:
        if i%3 != 0 and i%5 != 0:
            ret = 'DENIED'
            break
print(ret)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ret = 'APPROVED'
for i in a:
    if i%2 == 0:
        if i%3 != 0 and i%5 != 0:
            ret = 'DENIED'
            break
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
comb = list(combinations(A, 2))
XOR = [(i ^ j)%mod for i, j in comb]
print(sum(XOR)%mod)

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

ans = 0
 
MOD = (10**9+7)
for i in range(62):
    c = 0
    for ai in a:
        if ai&(1<<i): c += 1
    
    r = c*(n-c)
    ans += (1<<i)*r
    ans %= MOD
 
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
comb = list(combinations(A, 2))
XOR = [(i ^ j)%mod for i, j in comb]
print(sum(XOR)%mod)

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

ans = 0
 
MOD = (10**9+7)
for i in range(62):
    c = 0
    for ai in a:
        if ai&(1<<i): c += 1
    
    r = c*(n-c)
    ans += (1<<i)*r
    ans %= MOD
 
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split())) 

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for c in L[j+1:]:
            if a < b+c and b < a+c and c < a+b:
                ans += 1
print(ans)

Fixed submission:
import bisect
    
N = int(input())
L = sorted(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    for j in range(i+1, N):
        index = bisect.bisect_left(L, L[i]+L[j])
        ans += index - 1 - j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split())) 

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for k in range(j+1, N):
            c = L[k]
            if a < b+c and b < a+c and c < a+b:
                ans += 1
print(ans)

Fixed submission:
import bisect
    
N = int(input())
L = sorted(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    for j in range(i+1, N):
        index = bisect.bisect_left(L, L[i]+L[j])
        ans += index - 1 - j
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input())
h = list(map(int, input()))
ret = 0
for i in h:
    if i >= k:
        ret += 1
print(ret)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
ret = 0
for i in h:
    if i >= k:
        ret += 1
print(ret)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ans = 0

for i, j in s, t:
    if i == j:
        ans += 1
print(ans)

Fixed submission:
s = input()
t = input()
ans = 0

for i, j in zip(s, t):
    if i == j:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
p, q, r = map(int, input().split())
ans = min(a+b, b+c, c+a)
print(ans)

Fixed submission:
p, q, r = map(int, input().split())
ans = min(p+q, q+r, r+p)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)
d = []
while l and len(d) <= n:
    bc = l.pop(0)
    d.extend([bc[1]]*bc[0])
ret = 0
for i in range(n):
    if d and d[0] > a[0]:
        ret += d.pop(0)
    else:
        ret += a.pop(0)
print(ret)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)

res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
 
print(res)

# d = []
# while l and len(d) <= n:
#     bc = l.pop(0)
#     d.extend([bc[1]]*bc[0])
# ret = 0
# for i in range(n):
#     if d and d[0] > a[0]:
#         ret += d.pop(0)
#     else:
#         ret += a.pop(0)
# print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = []
for i in range(m):
    b, c = map(int, input().split())
    l.extend([c]*b)
l.sort(reverse=True)
ret = 0
for i in range(n):
    if l and l[0] > a[0]:
        ret += l.pop(0)
    else:
        ret += a.pop(0)
print(ret)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)

res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
 
print(res)

# d = []
# while l and len(d) <= n:
#     bc = l.pop(0)
#     d.extend([bc[1]]*bc[0])
# ret = 0
# for i in range(n):
#     if d and d[0] > a[0]:
#         ret += d.pop(0)
#     else:
#         ret += a.pop(0)
# print(ret)
Buggy python submission (verdict: Runtime Error):
import math

N, K=map(int,input().split())
ansA, ansB = 0, 0
for i in range(N):
    if K/(i+1) <= 1:
        ansA += 1/N
    else:
        x = math.ceil(K/(i+1))
        y = 0.5**math.ceil(math.log2(x))
        ansB += y/N

print(ansA + ansB)

Fixed submission:
import math

N, K=map(int,input().split())
ansA, ansB = 0, 0
for i in range(N):
    if K/(i+1) <= 1:
        ansA += 1/N
    else:
        x = math.ceil(K/(i+1))
        y = 0.5**math.ceil(math.log2(x))
        ansB += y/N

print(ansA + ansB)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = []
for i in range(1, min(a, b)):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[-k])

Fixed submission:
a, b, k = map(int, input().split())
l = []
for i in range(1, min(a, b)+1):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[-k])

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = []
for i in range(1, max(a, b)):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[-k])

Fixed submission:
a, b, k = map(int, input().split())
l = []
for i in range(1, min(a, b)+1):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[-k])
Buggy python submission (verdict: Runtime Error):
N=int(input())
li = [list(map(int,input().split())) for i in range(N)]

def solve(li):
    for i in range(101):
        for j in range(101):
            flag=1
            Cx,Cy=i,j
            H_prev=0
            for k in li:
                if k[2]!=0:
                    H_prev=k[2]+abs(k[0]-Cx)+abs(k[1]-Cy)
                    break
            for k in li:
                H=max(k[2]+abs(k[0]-Cx)+abs(k[1]-Cy),0)
                if H_prev != H:
                    flag=0
                    break
                H_prev=H
            if flag==1 and H>=1:
                A=[i,j,H]
                return A
A=solve(li)
print(' '.join(map(str,A)))

Fixed submission:
n=int(input())
p=[list(map(int,input().split()))for _ in range(n)] #[ax,ay,ah]をひとつの要素とする二重リスト
ax,ay,ah=list(filter(lambda x:x[2],p))[0] #x[2]がTrue、つまりahが0以外のリストの先頭の要素を取得
for x in range(101):
    for y in range(101):
        H=ah+abs(ax-x)+abs(ay-y) #Hの予測値
        if all([max(H-abs(t[0]-x)-abs(t[1]-y),0)==t[2]for t in p]): #ahのリストを生成し、予測したHから正しいかどうか判定
            print(x,y,H)

Buggy python submission (verdict: Runtime Error):
N=int(input())
li = [list(map(int,input().split())) for i in range(N)]

def solve(li):
    for i in range(101):
        for j in range(101):
            flag=1
            Cx,Cy=i,j
            H_prev=li[0][2]+abs(li[0][0]-Cx)+abs(li[0][1]-Cy)
            for k in li:
                H=k[2]+abs(k[0]-Cx)+abs(k[1]-Cy)
                if H_prev != H:
                    flag=0
                    break
                H_prev=H
            if flag==1 and H>=1:
                A=[i,j,H]
                return A
A=solve(li)
print(' '.join(map(str,A)))

Fixed submission:
n=int(input())
p=[list(map(int,input().split()))for _ in range(n)] #[ax,ay,ah]をひとつの要素とする二重リスト
ax,ay,ah=list(filter(lambda x:x[2],p))[0] #x[2]がTrue、つまりahが0以外のリストの先頭の要素を取得
for x in range(101):
    for y in range(101):
        H=ah+abs(ax-x)+abs(ay-y) #Hの予測値
        if all([max(H-abs(t[0]-x)-abs(t[1]-y),0)==t[2]for t in p]): #ahのリストを生成し、予測したHから正しいかどうか判定
            print(x,y,H)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0)) #vが[1,1,1,1]のようなケースへの対応
ce.append((-2, 0)) #頻度の降順に並んでいるのでこの書き方で十分
if co[0][0] != ce[0][0]: #偶奇の最頻の要素が異なる場合
    print(n - co[0][1] - ce[0][1])
else:
    res1 = n - co[0][1] - ce[1][1] #偶数側を書き換える場合
    res2 = n - co[1][1] - ce[0][1] #奇数側を書き換える場合
print(min(res1, res2))

Fixed submission:
from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0)) #vが[1,1,1,1]のようなケースへの対応
ce.append((-2, 0)) #頻度の降順に並んでいるのでこの書き方で十分
if co[0][0] != ce[0][0]: #偶奇の最頻の要素が異なる場合
    print(n - co[0][1] - ce[0][1])
else:
    res1 = n - co[0][1] - ce[1][1] #偶数側を書き換える場合
    res2 = n - co[1][1] - ce[0][1] #奇数側を書き換える場合
    print(min(res1, res2))
Buggy python submission (verdict: Runtime Error):
import functools
import math

def gcd(values):
    x=functools.reduce(math.gcd, values)
    return x

N,X=map(int,input().split())
li=list(map(int,input().split()))
if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])
answer=gcd(distance)
print(answer)

Fixed submission:
N,X=map(int,input().split())
li=list(map(int,input().split()))

def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)

if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])

answer=1
if N==1:
    answer=distance[0]
else:
    element = gcd(distance[0], distance[1])
    if N==2:answer=element
    else:
        for i in range(2,N):
            element=gcd(element,distance[i])
        answer=element

print(answer)

Buggy python submission (verdict: Runtime Error):
import functools
import math

def gcd(values):
    x=functools.reduce(math.gcd, values)
    return x

N,X=map(int,input().split())
li=list(map(int,input().split()))
if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])
answer=gcd(distance)
print(answer)

Fixed submission:
N,X=map(int,input().split())
li=list(map(int,input().split()))

def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)

if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])

answer=1
if N==1:
    answer=distance[0]
else:
    element = gcd(distance[0], distance[1])
    if N==2:answer=element
    else:
        for i in range(2,N):
            element=gcd(element,distance[i])
        answer=element

print(answer)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
B=[A[i]-i for i in range(N)]
B=sorted(B)

center=B[N//2] if N%2==0 else round((B[(N-1)//2]+B[(N+1)//2])/2)
ans=0
for i in B:
    ans+=abs(i-center)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
B=[A[i]-i-1 for i in range(N)]
B=sorted(B)

center=B[N//2] if N%2==1 else round((B[(N-1)//2]+B[(N+1)//2])/2)
ans=0
for i in B:
    ans+=abs(i-center)
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())

if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")

Fixed submission:
a, b = map(int, input().split())

if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
left_count=0
right_count=0
ans=N
for i in range(N):
    right_count=S[i+1:].count('E')
    ans=min(ans, right_count+left_count)
    if S[i]=='W':
        left_count+=1
print(ans)

Fixed submission:
N=int(input())
S=input()
L=[]
w=0
e_count=0
ans=N

for i in range(N):
    L.append(w)
    if S[i]=='W':
        w+=1

for i in range(N):
    ans=min(L[N-i-1]+e_count,ans)
    if S[N-i-1]=='E':
            e_count+=1

print(ans)