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

Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B :
    print("Yes")
elif B <= C and C <= A :
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
r = [S[:N].count("#") + S[N:].count(".") for _ in range(N)]  
print(min(r))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
count = 0
for i, s in enumerate(S.split("#")):
     if i == 0:
         continue
     else:
         count += s.count(".")
if count > S.count("#"):
    count = S.count("#")
print(count)
Problem p03125 (python)

Fixed submission:
# -*- coding: utf-8 -*-

def func_a():
  argv = input().split(" ")
  A = int(argv[0]) if int(argv[0]) >= 1 else 0
  B = int(argv[1]) if int(argv[1]) <= 20 else 0

  if A * B == 0:
    pass
  else:
    if B % A == 0:
      print(A + B)
    else:
      print(B - A)


if __name__ == "__main__":
  func_a()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys


def func_a(argv):
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a(sys.argv)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys


def func_a(argv):
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a(sys.argv[1:])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys


def func_a(argv):
    A = int(argv[0])
    B = int(argv[1])

    if not (A >= 1):
        pass

    if not (B <= 20):
        pass

    if A <= B:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


def main(argv):
    func_a(argv[1:])


if __name__ == "__main__":
    main(sys.argv)

Buggy submission (verdict: Runtime Error):
import sys 

A = int(sys.argv[1])
B = int(sys.argv[2])

if not (A >= 1):
  pass

if not (B <= 20):
  pass

if A <= B:
  if B % A == 0:
    print(A + B)
  else:
    print(B - A)
Problem p02640 (python)

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

for a in range(101):
  b = X - a
  if 2 * a + 4 * b == Y and b >= 0:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

for a in range(101):
  b = x - a
  if 2 * a + 4 * b == Y:
    print('Yes')
    exit()
print('No')
Problem p02646 (python)

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

if a == b:
  print('YES')
elif a < b:
  if b + w * t <= a + v * t:
    print('YES')
  else:
    print('NO')
else:
  if a - v * t <= b - w * t:
    print('YES')
  else:
	  print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a = b:
  print('YES')
elif a < b:
  if b - w * t <= a - v * t:
    print('YES')
  else:
    print('NO')
else:
  if a + v * t <= b + w * t:
    print('YES')
  else:
	  print('NO')
Problem p02787 (python)

Fixed submission:
import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [0 for _ in range(H + max(AB, key=lambda x: x[0])[0])]
for h in range(1, len(dp)):
    dp[h] = min(dp[h-a] + b for a, b in AB)

print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
tmp_magics = [float('inf') for _ in range(2 * H)]

for _ in range(N):
    a, b = map(int, input().split())
    for i in range(1, H // a + 2):
        if b * i < tmp_magics[a * i]:
            tmp_magics[a * i] = b * i

magics = []
max_magic = -float('inf')
for a, b in enumerate(tmp_magics):
    if b != float('inf'):
        magics.append([a, b])
        max_magic = max(max_magic, a)

M = len(magics)

dp = [float('inf') for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for a, b in magics:
        dp[h] = min(dp[h], dp[max(h - a, 0)] + b)

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [0 for _ in range(H+1)]
for h in range(1, len(dp)):
    dp[h] = min(dp[h-a] + b for a, b in AB)

print(dp[H])
Problem p02850 (python)

Fixed submission:
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds[str(min(prvi,i))+'-'+str(max(prvi,i))]] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = {}
for i in range(N-1):
  a,b = map(int,input().split())
  eds[str(a-1)+'-'+str(b-1)] = i
  g[a-1].append(b-1)
  g[b-1].append(a-1)

used = set([])
cols = [-1 for _ in range(N-1)]  
bfs(0)
print(max(cols))
[print(col) for col in cols]

Buggy submission (verdict: Runtime Error):
N = int(input())
g = {i:[] for i in range(N)}
AB = []
K = -float('inf')
for _ in range(N-1):
  a,b = map(int,input().split())
  AB.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  K = max(K,len(g[a-1]), len(g[b-1]))

print(K)
k = 1
print(k)
for i in range(1,N-1):
  a,b = AB[i]
  if (AB[i][0] in g[a-1] and AB[i][0] in g[b-1]) or (AB[i][1] in g[a-1] and AB[i][1] in g[b-1]):
    k +=1
    k = 1 if k==5 else k
  print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
g = {i:[] for i in range(N)}
AB = []
K = -float('inf')
for _ in range(N-1):
  a,b = map(int,input().split())
  AB.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  K = max(K,len(g[a-1]), len(g[b-1]))

print(K)
k = 1
print(k)
for i in range(1,N-1):
  a,b = AB[i]
  if AB[i][0] in g[a-1] + g[b-1] or AB[i][1] in g[a-1] + g[b-1]:
    k +=1
    k = 1 if k==5 else k
  print(k)
Problem p02937 (python)

Fixed submission:
import bisect

REPEAT_NUM = 10 ** 100

S = input()
T = input()
lenS = len(S)
lenT = len(T)

idxes_S = {}
for idx, s in enumerate(S):
    if s not in idxes_S:
        idxes_S[s] = []
    idxes_S[s].append(idx)

idx_s = -1
idx_t = 0
while idx_t < lenT and idx_s < lenS * REPEAT_NUM:
    if T[idx_t] not in idxes_S:
        print(-1)
        exit()
    else:
        tmp_idx = bisect.bisect(idxes_S[T[idx_t]], idx_s % lenS)
        if len(idxes_S[T[idx_t]]) == tmp_idx:
            idx_s += lenS - idx_s % lenS + idxes_S[T[idx_t]][0]
        else:
            idx_s += idxes_S[T[idx_t]][tmp_idx] - idx_s % lenS
        idx_t += 1

if idx_t == lenT:
    print(idx_s + 1)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import bisect

MAX_VALUE = 10**100
S = input()
lenS = len(S)
T = input()
Si = {}
for i,s in enumerate(S):
  if s not in Si:
    Si[s] = []
  Si[s].append(i)

ans = 0
for t in T:
  if t not in Si:
    print(-1)
    exit()
  else:
    idx = -1
    if ans<=max(Si[t]):
      idx = Si[t][bisect.bisect(Si[t],ans)]
    else:
      factor = (ans-min(Si[t]))//lenS + 1
      idx = Si[t][max(min(bisect.bisect(Si[t],ans%lenS),len(Si[t])-1),0)] + factor*lenS
    ans = idx
    if MAX_VALUE<ans:
      print(-1)
      exit()
print(ans+1)

Buggy submission (verdict: Runtime Error):
import bisect

MAX_VALUE = 10**100
S = input()
lenS = len(S)
T = input()
Si = {}
for i,s in enumerate(S):
  if s not in Si:
    Si[s] = []
  Si[s].append(i)

ans = 0
for t in T:
  if t not in Si:
    print(-1)
    exit()
  else:
    idx = -1
    if ans<=max(Si[t]):
      idx = Si[t][bisect.bisect(Si[t],ans)]
    else:
      factor = (ans-min(Si[t]))//lenS + 1
      idx = Si[t][min(bisect.bisect(Si[t],ans%lenS),len(Si[t])-1,0)] + factor*lenS
    ans = idx
    if MAX_VALUE<ans:
      print(-1)
      exit()
print(ans+1)

Buggy submission (verdict: Runtime Error):
import bisect

MAX_VALUE = 10**100
S = input()
lenS = len(S)
T = input()
Si = {}
for i,s in enumerate(S):
  if s not in Si:
    Si[s] = []
  Si[s].append(i)

ans = 0
for t in T:
  if t not in Si:
    print(-1)
    exit()
  else:
    idx = -1
    if ans<=max(Si[t]):
      idx = Si[t][bisect.bisect(Si[t],ans)]
    else:
      factor = (ans-min(Si[t]))//lenS + 1
      idx = Si[t][min(bisect.bisect(Si[t],ans%lenS),len(Si[t])-1)] + factor*lenS
    ans = idx
    if MAX_VALUE<ans:
      print(-1)
      exit()
print(ans+1)
Problem p02947 (python)

Fixed submission:
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
anagrams = {}
for i in range(N):
  string = ''.join(sorted(input()))
  if string in anagrams:
    anagrams[string] += 1
  else:
    anagrams[string] = 0

ans = 0
for anagram_num in anagrams.values():
  if anagram_num> 0:
    ans += int(cmb(anagram_num+1,2)) 
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

N = int(input())
strings = [input() for i in range(N)]
ans = 0

for i in range(len(strings)):
  anagrams_index = []
  anagrams_num = 0
  for j in range(i+1, len(strings)):
    if i > len(strings) or j > len(strings):
      break
    if is_anagram(strings[i], strings[j]):
      anagrams_num += 1
      strings.pop(j)
  
  if anagrams_num == 1:
    ans +=1
  elif anagrams_num > 1:
    ans += int(math.factorial(anagrams_num+1)/math.factorial(anagrams_num)) 
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

N = int(input())
strings = [input() for i in range(N)]
ans = 0

for i in range(len(strings)-1):
  anagrams_index = []
  anagrams_num = 0
  for j in range(i+1, len(strings)):
    if i > len(strings) or j > len(strings):
      break
    if is_anagram(strings[i], strings[j]):
      anagrams_num += 1
      strings.pop(j)
  
  if anagrams_num == 1:
    ans +=1
  elif anagrams_num > 1:
    ans += int(math.factorial(anagrams_num+1)/math.factorial(anagrams_num)) 
print(ans)
Problem p02953 (python)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

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

for i in range(1,N):
  dif = H[i] - H[i-1]
  if dif >= 0: continue
  elif dif == -1: H[i] += 1
  else:
    print('No')
    exit()
print('Yes')

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

result = 'Yes'

if H[0] >=1:
  H[0] -= -1

for i in range(N-1):
  diff = H[i+1] - H[i]
  if diff >= 1:
    H[i+1] -= 1
  elif diff = 0:
    pass
  elif diff < 0:
    result = 'No'
    break
print(result)
Problem p02969 (python)

Fixed submission:
print(3*(int(input())**2))

Buggy submission (verdict: Runtime Error):
def multiple_factors(i, N):
  factors = []
  factors.append(int(1*i))
  for index in range(1, N//i):
    factors.append(int(index*i))
  return factors
  
def assign_ball(factors, blist, ai, b_add_index):
  sum_b = 0
  for index in range(len(factors)-1, 0, -1):
    sum_b += blist[factors[index]-1]
  
  if ai != sum_b%2:
    blist[factors[0]-1] =1
    b_add_index.append(str(factors[index]))
  return blist, b_add_index

      
N = int(input())
alist = list(map(int, input().split()))
blist = [0 for i in range(N)]
M = 0
b_add_index = []
for i in range(N-1,-1, -1):
  factors = multiple_factors(i+1, N)
  blist, b_add_index = assign_ball(factors, blist, alist[i], b_add_index)

if sum(blist)%2 != alist[0]:
  print(-1)
else:
  print(len(b_add_index))
  print(" ".join(b_add_index))
Problem p02975 (python)

Fixed submission:
def solve():
  n = int(input())
  ans = 0
  for a in map(int, input().split()):
    ans ^=a
  print("No" if ans else "Yes")
solve()

Buggy submission (verdict: Runtime Error):
def exc_or(int1, int2):
  exc_or = bin(int1^int2)
  return int(exc_or, 2)

def is_same(start_index_excor, alist, exc_ors):
  for i in range(0, N):
    if alist[i] != exc_ors[start_index_excor+i]:
      return False
  return True

def is_same_reverse(start_index_excor, alist, exc_ors):
  for i in range(0, N):
    if alist[i] != exc_ors[start_index_excor-i]:
      return False
  return True

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

exc_ors = []
for i in range(N-1, -1, -1):
  exc_ors.append(exc_or(alist[i-1], alist[i]))

start_index_excors = [index for index, exc_or in enumerate(exc_ors) if exc_or == alist[0]]
if len(start_index_excors) == 0:
  print("No")
  exit()
else:
  for start_index_excor in start_index_excors:
    if is_same(start_index_excor, alist, exc_ors) is True or is_same_reverse(start_index_excor, alist, exc_ors) is True:
      print("Yes")
      exit()
    else:
      pass
  print("No")
Problem p02994 (python)

Fixed submission:
import sys
N, L = map(int, sys.stdin.readline().split())
tastes= [L+i-1 for i in range(1, N+1)]

if 0 <= L:
  tastes.pop(0)

elif L+N <= 0:
  tastes.pop(-1)

print(sum(tastes))
exit()

Buggy submission (verdict: Runtime Error):
import sys
N, L = map(int, sys.stdin.readline().split())
tastes= [L+i-1 for i in range(1, N+1)]

if 0 < L:
  tastes.pop(0)

elif L+N < 0:
  tastes.pop(-1)

elif L <= 0 and 0<=L+N:
  tastes.pop(-L)

print(sum(tastes))
exit()
Problem p02995 (python)

Fixed submission:
from fractions import gcd

def get_num(div):
  num = (B)//div - (A-1)//div
  return num

A,B,C,D = map(int,input().split())
print(B-A+1-get_num(C)-get_num(D)+get_num(C*D//gcd(C,D)))

Buggy submission (verdict: Runtime Error):
from math import gcd
A, B, C, D = map(int,input().split())
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print(total - divC - divD + divCD)

Buggy submission (verdict: Runtime Error):
from math import gcd
A, B, C, D = map(int,input().split())
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print(total - divC - divD + divCD)
Problem p03000 (python)

Fixed submission:
import sys
n, x = map(int, sys.stdin.readline().split())
llist =list(map(int, sys.stdin.readline().split()))

d = 0
ans = 1
for l in llist:
  ans += 1
  d += l
  if d > x:
    ans -= 1
    break
  elif d == x:
    break
  
  if ans >= n+1:
    print(n+1)
    exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n, x = map(int, sys.stdin.readline().split())
llist = list(map(int, sys.stdin.readline().split()))

d = 0
ans = 0
while d <= x:
  ans += 1
  d += llist[ans-1]
  if ans >= n+1:
    print(n+1)
    exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n, x = map(int, sys.stdin.readline().split())
llist = list(map(int, sys.stdin.readline().split()))

d = 0
ans = 0
while d <= x:
  ans += 1
  d += llist[ans-1]
print(ans)
Problem p03014 (python)

Fixed submission:
import sys

H,W = map(int,input().split())
grids = [[s for s in sys.stdin.readline()] for _ in range(H)]

col_cnt = [[0 for _ in range(W)]for _ in range(H)]
for i in range(W):
  tmp_cnt = 0
  prvjj = 0
  for j in range(H):
    if grids[j][i] == '.':
      tmp_cnt += 1
    else:
      col_cnt[j][i] = 0
      for jj in range(prvjj,j):
        col_cnt[jj][i] = tmp_cnt
      prvjj = j+1
      tmp_cnt = 0
  for jj in range(prvjj,H):
    col_cnt[jj][i] = tmp_cnt

ans = -float('inf')
for j in range(H):
  tmp_cnt = 0
  prvii = 0
  for i in range(W):
    if grids[j][i] == '.':
      tmp_cnt += 1
    else:
      for ii in range(prvii,i):
        ans = max(ans,col_cnt[j][ii]+tmp_cnt-1)
      prvii = i+1
      tmp_cnt = 0

  for ii in range(prvii,W):
    ans = max(ans,col_cnt[j][ii]+tmp_cnt-1)

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import groupby

H, W = map(int,input().split())
S = []

max_row_range = [[None, None], [None, None]]
max_row_num = -float('inf')
for j in range(H):
  row = [0 if s=='.' else 1 for s in input()]
  S.append(row)
  
  i = 0
  for key, value in groupby(row):
    value_len = len(list(value))
    if key == 0 and max_row_num < value_len:
      max_row_range = [[i,j],[i+value_len,j]]
      max_row_num = value_len
    i += value_len

max_col_range = [[None, None], [None, None]]
max_col_num = -float('inf')
for i, col in enumerate(zip(*S)):
  if i < max_row_range[0][0] or i < max_row_range[0][1]: continue 
    
  j = 0
  for key, value in groupby(col):
    value_len = len(list(value))
    if key == 0 and max_col_num < value_len:
      max_col_range = [[i,j],[i+value_len,j]]
      max_col_num = value_len
    j += value_len
    
print(max_row_range[1][0]-max_row_range[0][0]+max_col_range[1][0]-max_col_range[0][0]-1)
Problem p03078 (python)

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

Q = []
heapq.heappush(Q, [-(A[0]+B[0]+C[0]),0,0,0])
for _ in range(K):
  p, i, j, k = heapq.heappop(Q)
  print(-p)
  if i+1<X and [-(A[i+1]+B[j]+C[k]),i+1,j,k] not in Q: heapq.heappush(Q, [-(A[i+1]+B[j]+C[k]),i+1,j,k])
  if j+1<Y and [-(A[i]+B[j+1]+C[k]),i,j+1,k] not in Q: heapq.heappush(Q, [-(A[i]+B[j+1]+C[k]),i,j+1,k])
  if k+1<Z and [-(A[i]+B[j]+C[k+1]),i,j,k+1] not in Q: heapq.heappush(Q, [-(A[i]+B[j]+C[k+1]),i,j,k+1])

Buggy submission (verdict: Runtime Error):
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

Q = []
ia,ib,ic = 0,0,0
plus_i = 1
heapq.heappush(Q, [-(A[ia]+B[ib]+C[ic]),ia,ib,ic])

for _ in range(K):
  if ia+plus_i < X and [-(A[ia+plus_i]+B[ib]+C[ic]),ia+plus_i,ib,ic] not in Q:heapq.heappush(Q, [-(A[ia+plus_i]+B[ib]+C[ic]),ia+plus_i,ib,ic])
  if ib+plus_i < Y and [-(A[ia]+B[ib+plus_i]+C[ic]),ia,ib+plus_i,ic] not in Q:heapq.heappush(Q, [-(A[ia]+B[ib+plus_i]+C[ic]),ia,ib+plus_i,ic])
  if ic+plus_i < Z and[-(A[ia]+B[ib]+C[ic+plus_i]),ia,ib,ic+plus_i] not in Q:heapq.heappush(Q, [-(A[ia]+B[ib]+C[ic+plus_i]),ia,ib,ic+plus_i])
  plus_i += 1
    
[print(-heapq.heappop(Q)[0]) for _ in range(K)]
Problem p03090 (python)

Fixed submission:
N = int(input())
ans = []
for i in range(1,N+1):
  for j in range(i+1,N+1):
    ans.append(sorted([i,j]))

if N%2==1:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]
else:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i+1]))]

print(len(ans))
[print(*a) for a in ans]

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = []
for i in range(1,N+1):
  for j in range(i+1,N+1):
    ans.append(sorted([i,j]))

if N%2==1:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]
else:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]

print(len(ans))
[print(*a) for a in ans]
Problem p03141 (python)

Fixed submission:
N = int(input())
AB = []
ans = 0
for _ in range(N):
  a,b = map(int,input().split())
  AB.append(a+b)
  ans -= b
AB.sort(reverse=True)

print(ans+sum(AB[::2]))

Buggy submission (verdict: Runtime Error):
import heapq

N = int(input())
A, B = [], []
for i in range(N):
  a,b = map(int,input().split())
  heapq.heappush(A,[-a,i])
  heapq.heappush(B,[-b,i])

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, ii = heapq.heappop(A)
      flag = flags[ii]
      flags[ii] = 0
    Asum += -neg_a
  else:
    neg_b, ii = heapq.heappop(B)
    flag = 0
    while flag == 0:
      neg_b, ii = heapq.heappop(B)
      flag = flags[ii]
      flags[ii] = 0
    Bsum += -neg_b  
print(Asum-Bsum)

Buggy submission (verdict: Runtime Error):
import heapq

N = int(input())
A, B = [], []
for i in range(N):
  a,b = map(int,input().split())
  heapq.heappush(A,[-a,i])
  heapq.heappush(B,[-b,i])

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, i = heapq.heappop(A)
      flag = flags[i]
      flags[i] = 0
    Asum += -neg_a
  else:
    neg_b, i = heapq.heappop(B)
    flag = 0
    while flag == 0:
      neg_b, i = heapq.heappop(B)
      flag = flags[i]
      flags[i] = 0
    Bsum += -neg_b  
print(Asum-Bsum)
Problem p03196 (python)

Fixed submission:
def primes(n):
  ps = {}
  while n%2==0:
    n//=2
    if 2 not in ps:
      ps[2] = 1
    else:
      ps[2] += 1
  
  for i in range(3,int(n**.5)+1,2):
    while n%i==0:
      n//=i
      if i not in ps:
        ps[i] = 1
      else:
        ps[i] += 1
  
  if n!=1:
    ps[n] = 1
  
  return ps
  
N,P = map(int,input().split())
if N==1:
  print(P)
  exit()
ps = primes(P)
ans = 1
for p, num in ps.items():
  if num>=N:
    ans *= p**(num//N)
print(ans)

Buggy submission (verdict: Runtime Error):
def primes(n):
  ps = {}
  while n%2==0:
    n//=2
    if 2 not in ps:
      ps[2] = 1
    else:
      ps[2] += 1
  
  for i in range(3,int(n**.5)+1,2):
    while n%i==0:
      n//=i
      if i not in ps:
        ps[i] = 1
      else:
        ps[i] += 1
  
  if n!=1:
    if i not in ps:
      ps[i] = 1
    else:
      ps[i] += 1
  
  return ps
  
N,P = map(int,input().split())
ps = primes(P)
ans = 1
for p, num in ps.items():
  if num>=N:
    ans *= p**(num//N)
print(ans)

Buggy submission (verdict: Runtime Error):
N,P=map(int,input().split())
for x in range(max(int(P**(1/N))+1,1),0,-1):
  if P%(x**N)==0:
    print(x)
    exit()

Buggy submission (verdict: Runtime Error):
N,P=map(int,input().split())
for x in range(int(pow(P,1/N))+1,0,-1):
  if P%(x**N)==0:
    print(x)
    exit()
Problem p03309 (python)

Fixed submission:
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = int(statistics.median(A))
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)

Buggy submission (verdict: Runtime Error):
def calc_sadness(b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans


N = int(input())
A = []
for idx, a in enumerate(map(int, input().split())):
    A.append(a - idx - 1)
A.sort()

if N % 2 == 0:
    b = [[N // 2]]
else:
    b = [A[N // 2 - 1], A[N // 2]]

print(min(map(calc_sadness, b)))

Buggy submission (verdict: Runtime Error):
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = statistics.median(A)
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)
Problem p03385 (python)

Fixed submission:
S = input()
print('Yes' if all([True if S.count(s)==1 else False for s in 'abc']) else 'No')

Buggy submission (verdict: Runtime Error):
nums = sorted(list(map(int, input().split())))
ans = 0
while nums[0] != nums[-1]:
  if nums[-1] - nums[0] >= 2:
    nums[0] += 2
  else:
    nums[0] += 1
    nums[1] += 1
  nums = sorted(nums)
  ans += 1
print(ans)
Problem p03501 (python)

Fixed submission:
N,A,B = map(int,input().split())
print(min(B,A*N))

Buggy submission (verdict: Runtime Error):
N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,input().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))