Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03489 (python)

Fixed submission:
N = int(input())
A = [int(n) for n in input().split()]

from collections import Counter

cnt = Counter(A)

res = 0
for k, v in cnt.items():
    if k <= v:
        res += v-k
    else:
        res += v

print(res)

Buggy submission (verdict: Runtime Error):
s = input() + "T"
x, y = map(int, input().split())
N = len(s)



for i in range(N):
    if s[i] == "F":
        x -= 1
    else:
        cnt_Y = True
        index = i + 1
        break

steps_X = []
steps_Y = []

while index < N:
    cnt = 0
    for j in range(index, N):
        if s[j] == "F":
            cnt += 1
        else:
            if cnt_Y and cnt != 0:
                steps_Y.append(cnt)
            elif not cnt_Y and cnt != 0:
                steps_X.append(cnt)
            cnt_Y = not cnt_Y
            index = j
            break
    index += 1
    
K = 10000
dp = [set() for _ in range(K)]
dp[0].add(0)

for i, t in enumerate(steps_X):
    for tmp in dp[i]:
        dp[i+1].add(tmp+t)
        dp[i+1].add(tmp-t)

# print(dp[len(steps_X)])
if x not in dp[len(steps_X)]:
    print("No")
    import sys
    sys.exit()

dp = [set() for _ in range(K)]
dp[0].add(0)
for i, t in enumerate(steps_Y):
    for tmp in dp[i]:
        dp[i+1].add(tmp+t)
        dp[i+1].add(tmp-t)

if y not in dp[len(steps_Y)]:
    print("No")
    import sys
    sys.exit()


print("Yes")
Problem p03551 (python)

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

one = 100 * (N-M) + 1900 * M
count = 2 ** M
print(one * count)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(n) for n in input().split()]
infty = 10**15
res = 0
edge = [[0]*(N+2) for _ in range(N+2)]

for i, t in enumerate(a):
    if t > 0:
        edge[i][N+1] = t
        res += t
    else:
        edge[N][i] = -t

for i in range(1, N+1):
    for j in range(2, N//i + 1):
        edge[i-1][i*j-1] = infty


def dfs(now):
    checked[now] = True
    if now == N+1:
        return 1
    for nx in range(N+2):
        if nx != now and edge[now][nx] > 0 and checked[nx] == False:
            if dfs(nx) > 0:
                edge[now][nx] -= 1
                edge[nx][now] += 1
                return 1
    return 0



# print(res)
while(True):
    checked = [False] * (N+2)
    checked[N] = True
    if dfs(N) > 0:
        res -= 1
    else:
        break

print(res)
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, F = [int(n) for n in input().split()]

max_ratio = -1
for cnt_A in [n for n in range(30) if 100*A*n <= F]:
  for cnt_B in [n for n in range(30) if 100*A*cnt_A * 100*B*n <= F]:
    for cnt_C in [n for n in range(1500) if n*C <= E*(A*cnt_A+B*cnt_B) and 100*A*cnt_A + 100*B*cnt_B + n*C <= F]:
      for cnt_D in [n for n in range(1500) if n*D + C*cnt_C <= E*(A*cnt_A + B*cnt_B)and 100*A*cnt_A + 100*B*cnt_B + C*cnt_C + D*n <= F]:
        if (cnt_A!=0 or cnt_B !=0)and max_ratio < (C*cnt_C+D*cnt_D)/(100*A*cnt_A+100*B*cnt_B):
          max_ratio = (C*cnt_C + D*cnt_D)/(100*A*cnt_A+100*B*cnt_B)
          a = 100*A*cnt_A + 100*B*cnt_B
          b = C*cnt_C + D*cnt_D
print(a+b, b)

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F = [int(n) for n in input().split()]

max_ratio = 0
for cnt_A in [n for n in range(30) if 100*A*n <= F]:
  for cnt_B in [n for n in range(30) if 100*A*cnt_A * 100*B*n <= F]:
    for cnt_C in [n for n in range(1500) if n*C <= E*(A*cnt_A+B*cnt_B) and 100*A*cnt_A + 100*B*cnt_B + n*C <= F]:
      for cnt_D in [n for n in range(1500) if n*D + C*cnt_C <= E*(A*cnt_A + B*cnt_B)and 100*A*cnt_A + 100*B*cnt_B + C*cnt_C + D*n <= F]:
        if (cnt_A!=0 or cnt_B !=0)and max_ratio < (C*cnt_C+D*cnt_D)/(100*A*cnt_A+100*B*cnt_B):
          max_ratio = (C*cnt_C + D*cnt_D)/(100*A*cnt_A+100*B*cnt_B)
          a = 100*A*cnt_A + 100*B*cnt_B
          b = C*cnt_C + D*cnt_D
print(a+b, b)
Problem p03633 (python)

Fixed submission:
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = res // gcd(res, t) * t
print(res)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res/(gcd(res, t))) * t
print(res)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res * t /(gcd(res, t)))
print(res)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(long(input()))

res = 1L
for t in T:
  res = long(res * t /(gcd(res, t)))
print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd

N = int(input())
T = []
for i in range(N):
  T.append(long(input()))

res = 1L
for t in T:
  res = long(res * t /(gcd(res, t)))
print(res)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res * t /(gcd(res, t)))
print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res * t /(gcd(res, t)))
print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res * t /(gcd(res, t)))
print(res)
Problem p03657 (python)

Fixed submission:
A, B = [int(n) for n in input().split()]
if A%3==0 or B%3==0 or (A+B)%3==0:
  print("Possible")
else:
  print("Impossible")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")
Problem p03659 (python)

Fixed submission:
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)

Buggy submission (verdict: Runtime Error):
~
"arc078_a.py" 13L, 193C                                       1,1          全て
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)

Buggy submission (verdict: Runtime Error):
 ~
"arc078_a.py" 13L, 193C                                       1,1          全て
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt > N-f_cnt:
  print("Fennec")
else:
  print("Snuke")

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
  a, b = [int(n)-1 for n in input().split()]
  adj[a].append(b)
  adj[b].append(a)



def dfs(now, cost, dic):
  dic[now] = cost
  for nx in adj[now]:
    if nx not in dic:
      dfs(nx, cost+1, dic)

dist_f = {}
dist_s = {}

dfs(0, 0, dist_f)
dfs(N-1, 0, dist_s)


f_cnt = 0
for  i in range(N):
  if dist_f[i] <= dist_s[i]:
    f_cnt += 1

if f_cnt >= N-f_cnt:
  print("Fennec")
else:
  print("Snuke")
Problem p03671 (python)

Fixed submission:
l = [int(n) for n in input().split()]
print(sum(sorted(l)[:2]))

Buggy submission (verdict: Runtime Error):
l = [int(n) for n in input().split()]
print(sum(l.sort()[:2]))

Buggy submission (verdict: Runtime Error):
l = [int(n) for n in input().split()]
print(sum(l.sort()[:2])
Problem p03682 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())

P = [n for n in range(N)]
points = []

def root(a):
  if P[a] == a:
    return a
  P[a] = root(P[a])
  return P[a]

def is_same_set(a, b):
  return root(a) == root(b)

def unite(a, b):
  P[root(a)] = root(b)


for i in range(N):
  x, y = [int(n) for n in input().split()]
  points.append((i, x, y))

xs = sorted([(x, i) for i, x, y in points], key=lambda p: p[0])
xedges = [(xs[n][1], xs[n+1][1], xs[n+1][0]-xs[n][0] ) for n in range(N-1)]
ys = sorted([(y, i) for i, x, y in points], key=lambda p:p[0])
yedges = [(ys[n][1], ys[n+1][1], ys[n+1][0]-ys[n][0]) for n in range(N-1)]

edges = xedges + yedges
edges.sort(key=lambda x: x[2])
res = 0
for edge in edges:
  i, j, cost = edge
  if not is_same_set(i, j):
    unite(i, j)
    res += cost

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())

P = [n for n in range(N)]
points = []

def root(a):
  if P[a] == a:
    return a
  P[a] = root(P[a])
  return P[a]

def is_same_set(a, b):
  return root(a) == root(b)

def unite(a, b):
  P[root(a)] = root(b)


for i in range(N):
  x, y = [int(n) for n in input().split()]
  points.append((i, x, y))

xs = sorted([(x, i) for i, x, y in points], key=lambda p: p[0])
xedges = [(xs[n][1], xs[n+1][1], xs[n+1][0]-xs[n][0] ) for n in range(N-1)]
ys = sorted([(y, i) for i, x, y in points], key=lambda p:p[0])
yedges = [(ys[n][1], ys[n+1][1], ys[n+1][0]-ys[n][0]) for n in range(N-1)]

edges = xedges + yedges
edges.sort(key=lambda x: x[2])
res = 0
for edge in edges:
  i, j, cost = edge
  if not is_same_set(i, j):
    unite(i, j)
    res += cost

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())

P = [n for n in range(N)]
points = []

def root(a):
  if P[a] == a:
    return a
  P[a] = root(P[a])
  return P[a]

def is_same_set(a, b):
  return root(a) == root(b)

def unite(a, b):
  P[root(a)] = root(b)


for i in range(N):
  x, y = [int(n) for n in input().split()]
  points.append((i, x, y))

xs = sorted([(x, i) for i, x, y in points], key=lambda p: p[0])
xedges = [(xs[n][1], xs[n+1][1], xs[n+1][0]-xs[n][0] ) for n in range(N-1)]
ys = sorted([(y, i) for i, x, y in points], key=lambda p:p[0])
yedges = [(ys[n][1], ys[n+1][1], ys[n+1][0]-ys[n][0]) for n in range(N-1)]

edges = xedges + yedges
edges.sort(key=lambda x: x[2])
res = 0
for edge in edges:
  i, j, cost = edge
  if not is_same_set(i, j):
    unite(i, j)
    res += cost

print(res)
Problem p03693 (python)

Fixed submission:
r, g, b = [int(n) for n in input().split()]

if (10*g+b) % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
r, g, b = [int(n) for n in input().split()]

if 10*g+b % 4 == 0:
    print('YES')
else:
    print('NO')
Problem p03697 (python)

Fixed submission:
A, B = [int(n) for n in input().split()]
if A+B < 10:
  print(A+B)
else:
  print("error")

Buggy submission (verdict: Runtime Error):
    A, B = [int(n) for n in input().split()]
    if A+B < 10:
      print(A+B)
    else:
      print("error")
Problem p03729 (python)

Fixed submission:
A, B, C = input().split()
     
if A[len(A)-1] == B[0] and B[len(B)-1] == C[0]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A, B, C = input().split()]

if A[len(A)-1] == B[0] and B[len(B)-1] == C[0]:
  print("YES")
else:
  print("NO")
Problem p03777 (python)

Fixed submission:
a, b = input().split()
if a =='H':
  a = True
else:
  a = False
if b == 'H':
  b = True
else:
  b = False

res = not a^b

if res:
  print('H')
else:
  print('D')

Buggy submission (verdict: Runtime Error):
N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

A.sort()

res = []

for n_ex in range(N):
  dp = [[False] * K for n in range(N+1)]
  dp[0][0] = True
  for n in range(N):
    for k in range(0, K):
      dp[n+1][k] = dp[n][k]
    if n != n_ex:
      for k in range(0, K - A[n]):
        if dp[n][k] == True:
          dp[n+1][k+A[n]] = True
  for k in range(K-A[n_ex], K):
    if dp[N][k] == True:
      res.append(n_ex)
      break
print(N-len(res))
Problem p03807 (python)

Fixed submission:
N = int(input())
A = [int(n) for n in input().split()]

cnt = 0
for i in range(N):
    if A[i] % 2 == 1:
        cnt += 1

if cnt % 2 == 0:
    print ('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(n) for n in input().split()]

cnt = 0
for in range(N):
    if A[i] % 2 == 1:
        cnt += 1

if cnt % 2 == 0:
    print ('YES')
else:
    print('NO')
Problem p03826 (python)

Fixed submission:
#! /usr/bin/python3

A,B,C,D= list(map(int,input().split()))

print(max(A*B, C*D))

Buggy submission (verdict: Runtime Error):
N=int(input())
div=1000000007

primedict= {i:True for i in range(2,N+1)}

for i in range(2,N+1):
        if primedict[i]==True:
                j=2
                while i*j<=N:
                        primedict[i*j]=False
                        j+=1

primelist = [i for i in  range(2,N+1) if primedict[i]==True]

# print(primelist)

primecntdict={p:0 for p in primelist}

for n in range(2,N+1):
        for p in [p for p in primelist if p <= n]:
                while n%p==0:
                        n/=p
                        primecntdict[p]+=1

res=1
for p in primelist:
        res*=primecntdict[p]+1
        res%=div
# print(primecntdict[2])
print(res)
Problem p03844 (python)

Fixed submission:
A, op, B=input().split()
A = int(A)
B = int(B)

if op =='+':
    print (A+B)
else :
    print(A-B)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(n) for n in input().split()]

div=10**9+7

A.sort()

if N % 2 == 0:
    for i in range(int(N/2)):
        if A[2*i] != 2*i+1 or A[2*i+1] != 2*i+1:
            print (0)
            sys.exit() 
    print(2**int(N/2) % div)
if N % 2 == 1:
    if A[0]!=0:
        print(0)
        sys.exit()
    for i in range(int((N-1)/2)):
        if A[2*i+1] !=2*i+2  or A[2*i+2]!= 2*i+2:
            print(0)
            sys.exit()
    print(2**int((N-1)/2) % div)
Problem p03861 (python)

Fixed submission:
a, b, x = [int(n) for n in input().split()]

qa = a // x
qb = b // x
ra = a % x
rb = b % x
res = qb - qa
if ra == 0:
    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
a, b, x = [int(n) for n in input().split()]

res = 0
for n in range(a, b + 1)
    if n % x == 0:
        res += 1
print(res)
Problem p03965 (python)

Fixed submission:
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

print(len(s)//2 - P)

Buggy submission (verdict: Runtime Error):
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

print(N//2 - P)
Problem p04014 (python)

Fixed submission:
from math import sqrt
n = int(input())
s = int(input())

if n < s:
  print(-1)
  import sys
  sys.exit()
if n == s:
  print(n+1)
  import sys
  sys.exit()

def f(b, n):
  if n < b:
    return n
  return f(b, n//b) + (n % b)

res = -1

for p in range(int(sqrt(n)), 0, -1):
  b = (n-s)//p + 1
  if b == 1:
    continue
  if f(b, n) == s:
    res = b
    break

for b in range(2, int(sqrt(n))+2):
  if f(b, n) == s:
    res = b
    break

print(res)

Buggy submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
s = int(input())

if n < s:
  print(-1)
  import sys
  sys.exit()
if n == s:
  print(n+1)
  import sys
  sys.exit()

def f(b, n):
  if n < b:
    return n
  return f(b, n//b) + (n % b)

res = -1

for p in range(int(sqrt(n)), 0, -1):
  b = (n-s)//p + 1
  if f(b, n) == s:
    res = b
    break

for b in range(2, int(sqrt(n))+2):
  if f(b, n) == s:
    res = b
    break

print(res)

Buggy submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
s = int(input())

if n < s:
  print(-1)
  import sys
  sys.exit()
if n == s:
  print(n+1)
  import sys
  sys.exit()

def f(b, n):
  if n < b:
    return n
  return f(b, n//b) + (n % b)

res = -1

for p in range(1, int(sqrt(n))+1):
  b = (n-s)//p + 1
  if f(b, n) == s:
    res = b
    break

for b in range(2, int(sqrt(n))+1):
  if f(b, n) == s:
    res = b
    break

print(res)

Buggy submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
s = int(input())

if n < s:
  print(-1)
  import sys
  sys.exit()

def f(b, n):
  if n < b:
    return n
  return f(b, n//b) + (n % b)

res = -1

for p in range(1, int(sqrt(n))+1):
  b = (n-s)//p + 1
  if f(b, n) == s:
    res = b
    break

for b in range(2, int(sqrt(n))+1):
  if f(b, n) == s:
    res = b
    break

print(res)
Problem p02801 (python)

Fixed submission:
input_ = raw_input()
print(chr(ord(str(input_)) + 1))

Buggy submission (verdict: Runtime Error):

input_ = input()
print(chr(ord(str(input_)) + 1))
Problem p03244 (python)

Fixed submission:
from collections import Counter
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(i) for i in stdin.readline().rstrip().split()]

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

even_conter = Counter(even)
odd_conter = Counter(odd)

even_sorted = even_conter.most_common()
odd_sorted = odd_conter.most_common()

even_key1 = even_sorted[0][0]
even_val1 = even_sorted[0][1]
odd_key1 = odd_sorted[0][0]
odd_val1 = odd_sorted[0][1]

ans = n
if even_key1 == odd_key1:
    if len(even_sorted) >= 2:
        even_val2 = even_sorted[1][1]
        odd_val2 = odd_sorted[1][1]
        ans -= max((even_val1 + odd_val2), (odd_val1 + even_val2))
    else:
        ans -= max(even_val1, odd_val1)
else:
    ans -= (even_val1 + odd_val1)

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5 + 1
right = [0] * 10**5 + 1

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5
right = [0] * 10**5

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))
Problem p03274 (python)

Fixed submission:
from sys import stdin

N, K = [int(i) for i in stdin.readline().rstrip().split()]
x = [int(i) for i in stdin.readline().rstrip().split()]

ans = min((abs(x[0]) + abs(x[K - 1] - x[0])),
          (abs(x[K - 1]) + abs(x[0] - x[K - 1])))

for i in range(1, len(x) - K + 1):
    left = i
    right = i + K - 1

    letf_to_right = abs(x[left]) + abs(x[right] - x[left])
    right_to_left = abs(x[right]) + abs(x[left] - x[right])

    tmp = min(letf_to_right, right_to_left)

    if tmp < ans:
        ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin

N, K = [int(i) for i in stdin.readline().rstrip().split()]
x = [int(i) for i in stdin.readline().rstrip().split()]

if N == 1:
    print(x[0])
else:
    ans = min((abs(x[0]) + abs(x[K - 1] - x[0])),
              (abs(x[K - 1]) + abs(x[0] - x[K - 1])))

    for i in range(1, len(x) - K):
        tmp = min((abs(x[i]) + abs(x[i + K - 1] - x[i])),
                  (abs(x[i + K - 1]) + abs(x[i] - x[i + K - 1])))
    if tmp < ans:
        ans = tmp

    print(ans)
Problem p02760 (python)

Fixed submission:
a = []
for i in range(3):
    a.append(map(int,raw_input().split()))
n = input()
for j in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0

diag1 = [a[0][0],a[1][1],a[2][2]]
diag2 = [a[0][2],a[1][1],a[2][0]]
res = 'No'
if sum(diag1) ==0 or sum(diag2) ==0:
    res ='Yes'

rowsum = [sum(a[i]) for i in range(3) ]
if 0 in rowsum:
    res = 'Yes'

colSum = [sum([a[j][i] for j in range(3)]) for i in range(3)]
if 0 in colSum:
    res = 'Yes'

print res

Buggy submission (verdict: Runtime Error):
a = []
for i in range(3):
    a.append(map(int,raw_input().split()))
n = input()
for j in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                a[j][k] = 0

res = 'NO'
for l in range(3):
    if sum(a[l]) == 0:
        res = 'Yes'

nl = []

for m in range(3):
    nl.append(a[m][l])

if sum(nl) == 0:
    res = 'Yes'
if sum([a[0][0],a[1][1],a[2][2]]) == 0:
    res = 'Yes'
if sum([a[2][2], a[1][1], a[2][1]]) == 0:
    res = 'Yes'
print res


a,b = map(int,raw_input().split())

Buggy submission (verdict: Runtime Error):
a = []
for i in range(3):
    a.append(map(int,raw_input().split()))
n = input()
for j in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                a[j][k] = 0

res = 'NO'
for l in range(3):
    if sum(a[l]) == 0:
        res = 'Yes'
    else:
        nl = []

        for m in range(3):
            nl.append(a[m][l])

        if sum(nl) == 0:
            res = 'Yes'
if sum([a[0][0],a[1][1],a[2][2]]) == 0:
    res = 'Yes'
if sum([a[2][2], a[1][1], a[3][1]]) == 0:
    res = 'Yes'
print res