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

Fixed submission:
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [None]*(H+4)
S[0] = S[1] = S[H+2] = S[H+3] = ["#"]*(W+4)
for i in range(2, H+2):
    S[i] = ["#"] + ["#"] + list(input()) + ["#"] + ["#"]

cost = [[-1 for _ in range(W+3)] for _ in range(H+3)]

Ch += 1
Cw += 1
Dh += 1
Dw += 1

# bfs

warp_times = 0

def warp(i, j, cost, warp_times, q):
    change = 0
    for h in range(i-2, i+3):
        for w in range(j-2, j+3):
            # print(h, w, i, j)
            # print(S[h][w])
            if S[h][w] == "." and cost[h][w] == -1:
                q.append([h, w])
                cost[h][w] = warp_times + 1
                change = 1
    
    return change

q = deque()
q.append([Ch, Cw])

while True:
    

    same_cost = list()
    no_change = 1

    while len(q):
        # print(q)
        now = q.popleft()
        i = now[0]
        j = now[1]

        cost[i][j] = warp_times
        same_cost.append([i, j])

        if S[i][j-1] == "." and cost[i][j-1] == -1:
            q.append([i, j-1])
            cost[i][j-1] = warp_times
        if S[i][j+1] == "." and cost[i][j+1] == -1:
            q.append([i, j+1])
            cost[i][j+1] = warp_times
        if S[i-1][j] == "." and cost[i-1][j] == -1:
            q.append([i-1, j])
            cost[i-1][j] = warp_times
        if S[i+1][j] == "." and cost[i+1][j] == -1:
            q.append([i+1, j])
            cost[i-1][j] = warp_times
    

    for point in same_cost:
        change = warp(point[0], point[1], cost, warp_times, q)
        if change :
            no_change = 0
    
    warp_times += 1
    
    if no_change:
        break

print(cost[Dh][Dw])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [None]*(H+4)
S[0] = S[1] = S[H+2] = S[H+3] = ["#"]*(W+4)
for i in range(2, H+2):
    S[i] = ["#"] + ["#"] + list(input()) + ["#"] + ["#"]

Ch += 1
Cw += 1
Dh += 1
Dw += 1

del_h = Dh - Ch
del_w = Dw - Cw

ans = int(10e9)
# print("\n".join(map(str, S)))

def warp(i, j, nxt):
    for h in range(i-2, i+3):
        for w in range(j-2, j+3):
            # print(h, w, i, j)
            # print(S[h][w])
            if S[h][w] == ".":
                nxt.append([h, w, 1])
    
    return 

def dfs(i, j, S, cnt):
    if i == Dh and j == Dw:
        global ans
        ans = min(ans, cnt)
        return 

    S[i][j] = "#"
    nxt = list()
    if S[i][j-1] == ".":
        nxt.append([i, j-1, 0])
    if S[i][j+1] == ".":
        nxt.append([i, j+1, 0])
    if S[i-1][j+1] == ".":
        nxt.append([i-1, j, 0])
    if S[i+1][j] == ".":
        nxt.append([i+1, j, 0])
    warp(i, j, nxt)
    
    for point in nxt:
        cnt += point[2]
        dfs(point[0], point[1], S, cnt)
    
    # S[i][j] = "."

dfs(Ch, Cw, S, 0)
if ans == int(10e9):
    print(-1)
else:
    print(ans)
Problem p02608 (python)

Fixed submission:
N = int(input())

ans = [0]*(N+1)
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      n = pow(x,2) + pow(y,2) + pow(z,2) + x*y + y*z + z*x
      if n <= N:
        ans[n] += 1
        
for i in range(1,N+1):
  print(ans[i])

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

ans = [0]*(N+1)
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      n = x^2 + y^2 + z^2 + xy + yz + zx
      if n <= N:
        ans[n] += 1
        
for i in range(1,N):
  print(ans[i])
Problem p02642 (python)

Fixed submission:
from collections import deque

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

A.sort()

ans = 0
max_A = max(A)
ban = [0]*(max_A+1)
again = list()

last = 0
for i in range(N-1):
    if A[i] == A[i+1] and A[i] != last:
        again.append(A[i])
        last = A[i]
if N > 1 and A[N-1] == A[N-2] and A[N-1] != last:
    again.append(A[N-1])

for num in again:
    ban_num = num
    while ban_num <= max_A:
        ban[ban_num] = 1
        ban_num += num
 
for num in A:
    if ban[num] != 1:
        ans += 1
        ban_num = num
        while ban_num <= max_A:
            ban[ban_num] = 1
            ban_num += num

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

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

A.sort()
d = deque()
for i in range(N-1):
    if A[i] != A[i+1]:
        d.append(A[i])
if A[N-1] != A[N-2]:
    d.append(A[N-1])

ans = 0
max_A = max(A)
ban = [0]*max_A
while len(d):
    num = d.popleft()
    if ban[num] != 1:
        ans += 1
        ban_num = num
        while ban_num <= max_A:
            ban[ban_num] = 1
            ban_num += num

print(ans)
Problem p02647 (python)

Fixed submission:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))


for i in range(min(K, 42)):
    cum_sum = [0]*N
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N-1, j+A[j])
        cum_sum[left] += 1
        if right + 1 < N:
            cum_sum[right+1] -= 1
    A[0] = cum_sum[0]
    for j in range(N-1):
        cum_sum[j+1] += cum_sum[j]
        A[j+1] = cum_sum[j+1]
    
        
for i in range(N):
    print(A[i], " ", end = "")
print()

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
A = np.array(map(int, input().split()))


for i in range(K):
    cum_sum = np.array([0]*N)
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N-1, j+A[j])
        cum_sum[left] += 1
        if right + 1 < N:
            cum_sum[right+1] -= 1
    A[0] = cum_sum[0]
    for j in range(N-1):
        cum_sum[j+1] += cum_sum[j]
        A[j+1] = cum_sum[j+1]

    if A[0] == N and A[N-1] == N:
        break
    
        
for i in range(N):
    print(A[i], " ", end = "")
print()
Problem p02713 (python)

Fixed submission:
import math

K = int(input())

gcd_tmp = list()
total = 0
for b in range(1, K+1):
    for c in range(1, K+1):
        tmp = math.gcd(b, c)
        gcd_tmp.append(tmp)

gcd_tmp.sort()
length = len(gcd_tmp)

type_of_gcd = list()
num_of_gcd = list()

counter = 0
for i in range(length-1):
    counter += 1
    if gcd_tmp[i] != gcd_tmp[i+1]:
        type_of_gcd.append(gcd_tmp[i])
        num_of_gcd.append(counter)
        counter = 0
type_of_gcd.append(gcd_tmp[-1])
num_of_gcd.append(counter+1)

# print(gcd_tmp)
# print(type_of_gcd)
# print(num_of_gcd)


for a in range(1, K+1):
    for i in range(len(type_of_gcd)):
        tmp = math.gcd(a, type_of_gcd[i])
        total += tmp*num_of_gcd[i]

print(total)

Buggy submission (verdict: Runtime Error):
import math

K = int(input(K))

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      tmp = math.gcd(a,b)
      ans += math.gcd(tmp, c)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

K = int(input(K))

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

print(ans)
Problem p02761 (python)

Fixed submission:
N, M = map(int,input().split())
s = [0]*M
c = [0]*M

for i in range(M):
    s[i], c[i] = map(int,input().split())

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*N
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
s = [0]*M
c = [0]*M

for i in range(M):
    s[i], c[i] = map(int,input().split())

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*M
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
s = [0]*M
c = [0]*M

for i in range(M):
    s[i], c[i] = map(int,input().split())

ans = [0]*M
ans[0] = 1
error = 0

assign = [0]*M
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0:
    error += 1 

if error == 0:
    for i in range(M):
        print(ans[i], end = "")
    print()
else:
    print(-1)
Problem p02791 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
ans = 1

min_P = P[0]

for i in range(1, N):
    if min_P >= P[i]:
        ans += 1
        min_P = P[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(N):
    tmp_P = P[:i]
    if min(tmp_P) >= P[i]:
        ans += 1

print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]

path = [list() for _ in range(N+1)]
for i in range(N-1):
    a, b = ab[i][0], ab[i][1]
    path[a].append([b, i])
    path[b].append([a, i])

color_max = 0
color_list = [0]*(N-1)
visit = [False]*(N+1)
visit[1] = True
def dfs(node, color, used_path):
    global visit
    nxt_color = 0
    for nxt in path[node]:
        nxt_node = nxt[0]
        use_path = nxt[1]
        if visit[nxt_node] == False:
            visit[nxt_node] = True
            nxt_color += 1
            if nxt_color == color:
                nxt_color += 1
            dfs(nxt_node, nxt_color, use_path)
    
    global color_list
    if used_path != -1:
        color_list[used_path] = color

dfs(1, 0, -1)


for c in color_list:
    color_max = max(c, color_max)
print(color_max)
print("\n".join(map(str, color_list)))

Buggy submission (verdict: Runtime Error):
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]

path = [list() for _ in range(N+1)]
for i in range(N-1):
    a, b = ab[i][0], ab[i][1]
    path[a].append([b, i])
    path[b].append([a, i])

color_max = 0
color_list = [0]*(N-1)
visit = [False]*(N+1)
visit[1] = True
def dfs(node, color, used_path):
    global visit
    nxt_color = 0
    for nxt in path[node]:
        nxt_node = nxt[0]
        use_path = nxt[1]
        if visit[nxt_node] == False:
            visit[nxt_node] = True
            nxt_color += 1
            if nxt_color == color:
                nxt_color += 1
            dfs(nxt_node, nxt_color, use_path)
    
    global color_list
    if used_path != -1:
        color_list[used_path] = color

dfs(1, 0, -1)


for c in color_list:
    color_max = max(c, color_max)
print(color_max)
print("\n".join(map(str, color_list)))
Problem p02882 (python)

Fixed submission:
import math

a , b , x = map(int,input().split())
if  x <= a*a*b/2:
    h = 2*x / (b*a)
    theta = math.degrees(math.atan(h/b))
else:
    upper=(2*x / (a*a)) - b
    if b == upper:
        theta = 90
    else:
        theta = math.degrees(math.atan(a / (b - upper)))

print(90-theta)

Buggy submission (verdict: Runtime Error):
import math

a , b , x = map(int,input().split())
if  x <= a*a*b/2:
    h = 2*x / (b*a)
    theta = math.degrees(math.atan(h/b))
else:
    upper=(2*x / (a*a)) - b
    if b = upper:
        theta = 90
    else:
        theta = math.degrees(math.atan(a / (b - upper)))

print(90-theta)

Buggy submission (verdict: Runtime Error):
import math

a , b , x = map(int,input().split())
if  x <= a*a*b/2:
    h = 2*x / (b*a)
    theta = math.degrees(math.atan(h/b))
else:
    upper=(2*x / (a*a)) - b
    theta = math.degrees(math.atan(a / (b - upper)))

print(90-theta)
Problem p03945 (python)

Fixed submission:
S = input()

length = len(S)
ans = 0

for i in range(length-1):
  if S[i] != S[i+1]:
    ans += 1

print(ans)

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

length = len(S)
ans = 0

for i in range(n-1):
  if S[i] != S[i+1]:
    ans += 1

print(ans)
Problem p02641 (python)

Fixed submission:
x,n=map(int,input().split())
lis=[i-1 for i in range(103)]
flag=True
if n==0:
  flag=False
  print(x)

if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  #print(lis)
  for i in range(len(lis)):
    if lis[i]>x:
      index=i
      break
  if abs(x-lis[index])<abs(x-lis[index-1]):
    print(lis[index])
  else:
    print(lis[index-1])

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
if n==0:
  flag=False
  print(x)
if x==100:
  p=list(map(int,input().split()))
  print(100)
  flag=False

if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  for i in range(len(lis)):
    if lis[i]>x:
      id=i
      break
  if id>=1:
    if abs(x-lis[id])<abs(x-lis[id-1]):
      print(lis[id])
    else:
      print(lis[id-1])
  else:
    print(lis[0])

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
if n==0:
  flag=False
  print(x)
if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  for i in range(len(lis)):
    if lis[i]>x:
      id=i
      break
  if id>=1:
    if abs(x-lis[id])<abs(x-lis[id-1]):
      print(lis[id])
    else:
      print(lis[id-1])
  else:
    print(lis[0])
Problem p02683 (python)

Fixed submission:
from itertools import combinations_with_replacement
n,m,x=map(int,input().split())

c=[]
a=[]

INF=1001001001
ans=INF

for i in range(n):
  tmp=list(map(int,input().split()))
  c.append(tmp[0])
  a.append(tmp[1:])

for i in range(1<<n):
  cost=0
  skill=[0 for _ in range(m)]
  for j in range(n):
    if (i>>j)&1==1:
      #print("i,j,(i>>j&1)",i,j,(i>>j&1))
      cost+=c[j]
      for k in range(m):
        skill[k]+=a[j][k]
  #print("skill",skill,"i",i)
  flag=True
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==INF:
  ans=-1
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations_with_replacement
n,m,x=map(int,input().split())
l=[0,1]
hon=list(combinations_with_replacement(l,n))

c=[]
a=[]

ans=1001001001

for i in range(n):
  tmp=list(map(int,input().split()))
  c.append(tmp[0])
  a.append(tmp[1:])

for i,k in enumerate(hon):
  skill=[0 for i in range(m)]
  cost=0
  flag=True
  for j in range(m):
    if k[j]==1:
      for _ in range(m):
        skill[_]+=a[j][_]
      cost+=c[j]
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==1001001001:
  ans=-1
print(ans)
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]-=1
kai=[-1 for i in range(n)]
nx=0
now=0
kai[0]=0

if k<=n:
  for i in range(k):
    nx=a[now]
    now=nx
    #print(nx)
  ans=nx+1
else:
  for i in range(n):
    nx=a[now]
    if kai[nx]==-1:
      kai[nx]=i+1
      now=nx
    else:
      T=i+1-kai[nx]
      break
  times=kai[nx]+(k-kai[nx])%T
  now=0
  nx=0
  for i in range(times):
    nx=a[now]
    now=nx
    #print(nx)
  ans=nx+1
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
num=[0 for i in range(n)]
first=[0 for i in range(n)]
first[0]=1
a=list(map(int,input().split()))
for i in range(n):
  a[i]-=1
num[0]=1
loop=0
s=0
for i in range(n):
  if num[a[s]]==0:
    num[a[s]]+=1
    first[a[s]]=i
  if num[a[s]]==2:
    loop1=loop
    break
  s=a[s]

kai=first[a[s]]+(k-first[a[s]])%(loop1-first[a[s]])
s=0
for i in range(kai):
  s=a[s]
print(s+1)
Problem p02690 (python)

Fixed submission:
x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if i**5-j**5==x:
      a=i
      b=j
print(a,b)

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

for i in range(2,int(x**0.5)+1):
  if x%i==0:
    q=i
    #print(q)
    break

for i in range(-100000,100000):
  if (i+q)**5-i**5==x:
    break
print(i+q,i)

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

for i in range(-70,71):
  for j in range(-70,71):
    if i**5-j**5==x:
      a=i
      b=j
print(a,b)
Problem p02747 (python)

Fixed submission:
s=input()
cnt=0
ans="No"
flag=True

while cnt<len(s):
  if len(s)==1 or len(s)%2==1:
    flag=False
    break
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
cnt=0
ans="No"
flag=True

while cnt<len(s):
  if len(s)==1:
    flag=False
    break
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
cnt=0
ans="No"
flag=True
while cnt<len(s):
  if s[cnt]=="h" and s[cnt+1]=="i":
    cnt+=2
    continue
  else:
    flag=False
    break
if flag:
  ans="Yes"
print(ans)
Problem p02756 (python)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Buggy submission (verdict: Runtime Error):
from collections import deque
s=deque(list(input().split()))
ans=""
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    #print("1",s)
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
        #print("2",s)
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
      #print("22",s)
if flag==False:
    s = list(s).reverse()
print("".join(map(str, s)))

Buggy submission (verdict: Runtime Error):
s=input()
q=int(input())
dp=["" for i in range(q+1)]
dp[0]=s
flag=0
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    dp[i+1]=dp[i]
    flag+=1
  else:
    if ques[1]=="1":
      if flag%2==0:
        dp[i+1]=ques[2]+dp[i]
      else:
        dp[i+1]=dp[i]+ques[2]
    else:
      if flag%2==0:
        dp[i+1]=dp[i]+ques[2]
      else:
        dp[i+1]=ques[2]+dp[i]
if flag%2==1:
  ans=dp[q][::-1]
else:
  ans=dp[q]
print(ans)
Problem p02787 (python)

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

a=[]
b=[]
INF=10**9
dp=[INF for i in range(h+10**4)]

for i in range(n):
  p,q=map(int,input().split())
  a.append(p)
  b.append(q)

dp[0]=0
for i in range(h):
  if dp[i]==INF:
    continue
  for j in range(n):
    if dp[i+a[j]]>=dp[i]+b[j]:
      dp[i+a[j]]=dp[i]+b[j]
print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
h,n=map(int,input().split())

a=[]
b=[]
INF=10**9
dp=[INF for i in range(h+1)]

for i in range(n):
  p,q=map(int,input().split())
  a.append(p)
  b.append(q)


for i in range(n):
  if a[i]<=h:
    dp[a[i]]=b[i]
  else:
    dp[h]=min(dp[h],b[i])
    flag=1

if flag==0:
  for i in range(1,h+1):
    if dp[i]==INF:
      #dp[i]=min(dp[i],dp[i-1])
      #print(dp)
      continue
    for j in range(n):
      if i+a[j]<=h:
        dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])
        #print(dp)
      else:
        dp[h]=min(dp[h],dp[i]+b[j])
        #print(dp)
    #dp[i]=min(dp[i],dp[i-1])
    #print(dp)
print(dp[h])

Buggy submission (verdict: Runtime Error):
h,n=map(int,input().split())
hp=h
a=[]
b=[]
INF=10**9
dp=[INF for i in range(h+1)]

for i in range(n):
  p,q=map(int,input().split())
  a.append(p)
  b.append(q)

for i in range(n):
  dp[a[i]]=b[i]
  #print(dp)
for i in range(1,h+1):
  if dp[i]==INF:
    #dp[i]=min(dp[i],dp[i-1])
    #print(dp)
    continue
  for j in range(n):
    if i+a[j]<=h:
      dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])
      #print(dp)
    else:
      dp[h]=min(dp[h],dp[i]+b[j])
      #print(dp)
  #dp[i]=min(dp[i],dp[i-1])
  #print(dp)
print(dp[h])

Buggy submission (verdict: Runtime Error):
h,n=map(int,input().split())
hp=h
a=[]
b=[]
INF=10**9
dp=[INF for i in range(h+1)]

for i in range(n):
  p,q=map(int,input().split())
  a.append(p)
  b.append(q)

for i in range(n):
  dp[a[i]]=b[i]
  #print(dp)
for i in range(1,h+1):
  if dp[i]==INF:
    #dp[i]=min(dp[i],dp[i-1])
    #print(dp)
    continue
  for j in range(n):
    if i+a[j]<=h:
      dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])
      #print(dp)
    else:
      dp[h]=min(dp[h],dp[i]+b[j])
      #print(dp)
  #dp[i]=min(dp[i],dp[i-1])
  #print(dp)
print(dp[h])
Problem p02838 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(61):
  #print(keta[i])
  #print(keta[i]*(n-keta[i])*(2**i))
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(n)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(len(keta)):
  #print(keta[i])
  ans+=keta[i]*(n-keta[i])*(2**i)
print(ans)
Problem p02972 (python)

Fixed submission:
n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):
  j=2
  b[i]=a[i]
  while(j*i<=n):
    b[i]^=b[j*i]
    j+=1

m=0
for i in range(n+1):
  m+=b[i]
print(m)
for i in range(1,n+1):
  if b[i]==1:
    print(i)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):

  j=2
  b[i]=a[i]
  while(j*i=<n):
    b[i]^=a[j*i]
    j+=1

m=0
for i in range(n):
  m+=b[i]
print(m)
print(b)
for i in range(n):
  if b[i]==1:
    print(i)
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  if cnt==n+1:
    break
  d+=l[cnt-1]
print(cnt)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  d+=l[cnt-1]
  if cnt>n+1:
    cnt=n+1
    break
print(cnt)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
d=0
cnt=0
l=list(map(int,input().split()))
while(d<=x):
  cnt+=1
  d+=l[cnt-1]
print(cnt)