Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

H,W,M=map(int,input().split())
hw = np.zeros([H,W],dtype=int)
for i in range(M):
  h,w=map(int,input().split())
  hw[h-1,w-1] = 1

sum1 = hw.sum(1)
sum2 = hw.sum(0)

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

ans=0
for idx1,val1 in sum1[:min(3,len(sum1))]:
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[idx1,idx2]
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

max1,max2=set([sum1[0][0]]),set([sum2[0][0]])
for i in range(1,H):
  if sum1[i][1]<sum1[0][1]:
    break
  else:
    max1.add(sum1[i][0])
    
for i in range(1,W):
  if sum2[i][1]<sum2[0][1]:
    break
  else:
    max2.add(sum2[i][0])

ans = sum1[0][1]+sum2[0][1]
count=0
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    count += 1
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np

H,W,M=map(int,input().split())
hw = np.zeros([H,W],dtype=int)
for i in range(M):
  h,w=map(int,input().split())
  hw[h-1,w-1] = 1

sum1 = hw.sum(1)
sum2 = hw.sum(0)

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

ans=0
for idx1,val1 in sum1[:min(3,len(sum1))+1]:
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[idx1,idx2]
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

max1,max2=set([sum1[0][0]]),set([sum2[0][0]])
for i in range(1,H):
  if sum1[i][1]<sum1[0][1]:
    break
  else:
    max1.add(sum1[i][0])
    
for i in range(1,W):
  if sum2[i][1]<sum2[0][1]:
    break
  else:
    max2.add(sum2[i][0])

ans = sum1[0][1]+sum2[0][1]
count=0
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    count += 1
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bc = [[0 for i in range(2)] for j in range(Q)]
for i in range(Q):
  bc[i] = list(map(int,input().split()))

count = [0 for i in range(100000)]
for i in range(N):
  count[A[i]] += 1

sum_ = sum(A)
for i in range(Q):
  b,c = bc[i]
  n = count[b]
  sum_ -= b*n
  sum_ += c*n
  count[c] += n
  print(sum_)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = list(map(int, input().split()))
    if B not in A:
        print(sum_)
        continue
    sum_ = 0
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
        sum_ += A[j]
    print(sum_)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = list(map(int, input().split()))
    sum_ = 0
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
        sum_ += A[j]
    print(sum_)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = list(map(int, input().split()))
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
    print(sum(A))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)
Buggy python submission (verdict: Runtime Error):
A,B=input().split()

for x in (A,B):
  if float(x)==int(float(x)):
    x = int(x)
  else:
    x = float(x)

def dicimal2int(d):
  d = str(d)
  if '.' not in d:
    return int(d),0
  if d[:2]=="0.":
    for i in range(2,len(d)):
      if d[i] != '0':
        break
    n_move = len(d)-2
    return int(d[i:]),n_move
  idx = d.index('.')
  n_move = len(d)-idx-1
  return int(d[:idx]+d[idx+1:]),n_move

C1,n1 = dicimal2int(A)
C2,n2 = dicimal2int(B)

D = C1*C2
n = n1+n2

if n==0:
  print(D)
  exit()
  
def int2dicimal(N,n_move):
  if n_move==0:
    return N
  N = str(N)
  for i in range(len(N)):
    if N[-i-1] != '0':
      break
  n_zero = i
  if n_zero>n_move:
    return int(N[:-n_move])
  if n_zero>0:
    N = N[:-n_zero]
    n_move -= n_zero
  if len(N)-1>=n_move:
    return float(N[:-n_move]+'.'+N[-n_move:])
  return float("0."+'0'*(n_move-len(N))+N)

print(int(int2dicimal(D,n)))

Fixed submission:
A,B=input().split()
A = int(A)
B = int(float(B)*100+.5)
print(A*B//100)

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

for x in (A,B):
  if float(x)==int(float(x)):
    x = int(x)
  else:
    x = float(x)

def dicimal2int(d):
  d = str(d)
  if '.' not in d:
    return int(d),0
  if d[:2]=="0.":
    for i in range(2,len(d)):
      if d[i] != '0':
        break
    n_move = len(d)-2
    return int(d[i:]),n_move
  idx = d.index('.')
  n_move = len(d)-idx-1
  return int(d[:idx]+d[idx+1:]),n_move

C1,n1 = dicimal2int(A)
C2,n2 = dicimal2int(B)

D = C1*C2
n = n1+n2

if n==0:
  print(D)
  exit()
  
def int2dicimal(N,n_move):
  if n_move==0:
    return N
  N = str(N)
  for i in range(len(N)):
    if N[-i-1] != '0':
      break
  n_zero = i
  if n_zero>n_move:
    return int(N[:-n_move])
  N = N[:-n_zero]
  n_move -= n_zero
  if len(N)-1>=n_move:
    return float(N[:-n_move]+'.'+N[-n_move:])
  return float("0."+'0'*(n_move-len(N))+N)

print(int(int2dicimal(D,n)))

Fixed submission:
A,B=input().split()
A = int(A)
B = int(float(B)*100+.5)
print(A*B//100)

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

if float(A)==int(float(A)):
  A = int(A)
else:
  A = float(A)
  
if float(B)==int(float(B)):
  B = int(B)
else:
  B = float(B)
    
print(int(A*B))

Fixed submission:
A,B=input().split()
A = int(A)
B = int(float(B)*100+.5)
print(A*B//100)
Buggy python submission (verdict: Runtime Error):
N,K=map(int, input().split())
A = list(map(int, input().split()))

A = [0] + A

visited = [1]
now = 1
short = 0
while True:
  next = A[now]
  if next in visited:
    break
  visited.append(next)
  if len(visited)==K:
    short = 1
    break
  now = next

if short: print(visited[K])
else:
  initial = visited.index(next)
  cycle = len(visited[initial:])
  if K >= cycle:
    residual = (K - initial) % cycle
    print(visited[initial+residual])
  else:
    print(visited[K])

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

vis=[0]*(N+1)
now=1
vis[now] = 1
his=[now]
while 1:
  new = A[now-1]
  if vis[new]==0:
    vis[new]=1
    his.append(new)
    now = new
  else:
    idx = his.index(new)
    cycle = his[idx:]
    margin = his[:idx]
    break
    
if K <= len(margin):
  print(his[K])
  exit()
  
K -= len(margin)
K %= len(cycle)

print(cycle[K])

Buggy python submission (verdict: Runtime Error):
N,K=map(int, input().split())
A = list(map(int, input().split()))

A = [0] + A

visited = [1]
now = 1
short = 0
while True:
  next = A[now]
  if next in visited:
    break
  if len(visited)==K:
    short = 1
    break
  visited.append(next)
  now = next

if short: print(visited[K])
else:
  initial = visited.index(next)
  cycle = len(visited[initial:])
  if K >= cycle:
    residual = (K - initial) % cycle
    print(visited[initial+residual])
  else:
    print(visited[K])

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

vis=[0]*(N+1)
now=1
vis[now] = 1
his=[now]
while 1:
  new = A[now-1]
  if vis[new]==0:
    vis[new]=1
    his.append(new)
    now = new
  else:
    idx = his.index(new)
    cycle = his[idx:]
    margin = his[:idx]
    break
    
if K <= len(margin):
  print(his[K])
  exit()
  
K -= len(margin)
K %= len(cycle)

print(cycle[K])
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

sign = np.arange(1,N+1)
sign = sign + A
temp = np.arange(N)+1-A
count = 0
for i in range(1,N):
  count += (sign[:i]==temp[:i]).sum()

print(count)

Fixed submission:
from collections import defaultdict

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

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

ans=0
diff_list=[] #①照合用の差分リスト
count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント
#前処理として、最初のループで①と②を作成
for i in range(1,N):
  if i == A[0]+A[i]:
    ans += 1
  d1 = A[i]-A[0]
  d2 = i
  diff_list.append(d1+d2)
  
  count[A[0]+A[i]-i] += 1

for i in range(N-1):
  count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く
  d = diff_list[i]
  ans += count[-d]
  
print(ans)

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

sign = list(range(1,N+1))

for i in range(N):
  sign[i] += A[i]

count = 0
for i in range(1,N):
  temp = i+1-A[i]
  for j in range(i):
    if sign[j]==temp:count+=1

print(count)

Fixed submission:
from collections import defaultdict

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

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

ans=0
diff_list=[] #①照合用の差分リスト
count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント
#前処理として、最初のループで①と②を作成
for i in range(1,N):
  if i == A[0]+A[i]:
    ans += 1
  d1 = A[i]-A[0]
  d2 = i
  diff_list.append(d1+d2)
  
  count[A[0]+A[i]-i] += 1

for i in range(N-1):
  count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く
  d = diff_list[i]
  ans += count[-d]
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input() + ' '
if len(S) <= 4:
  print(0)
elif len(S) == 5:
  if int(S[:-1]) % 2019 == 0:
    print(1)
  else:
    print(0)
else:
  count = 0
  for i in range(len(S)-5):
    for j in range(i+4, len(S)):
      s = int(S[i:j])
      if s % 2019 == 0:
        count += 1
  print(count)


Fixed submission:
from collections import Counter

S=input()

rlist=[0]
for i in range(len(S)):
  rlist.append((rlist[-1]+int(S[-i-1])*pow(10,i,2019))%2019)
  
c = Counter(rlist)
c[0] -= 1

def nC2(n):
  return n*(n-1)//2
  
ans = c[0]
for k in c.keys():
  if c[k] >= 2:
    ans += nC2(c[k])
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input() + ' '
if len(S) <= 4:
  print(0)
elif len(S) == 5:
  if int(S[:-1]) % 2019 == 0:
    print(1)
  else:
    print(0)
else:
  count = 0
  for i in range(len(S)-5):
    for j in range(i+4, len(S)):
      s = int(S[i:j])
      if s % 2019 == 0:
        count += 1
  print(count)

Fixed submission:
from collections import Counter

S=input()

rlist=[0]
for i in range(len(S)):
  rlist.append((rlist[-1]+int(S[-i-1])*pow(10,i,2019))%2019)
  
c = Counter(rlist)
c[0] -= 1

def nC2(n):
  return n*(n-1)//2
  
ans = c[0]
for k in c.keys():
  if c[k] >= 2:
    ans += nC2(c[k])
    
print(ans)
Buggy python submission (verdict: Runtime Error):
r=int(input())
print(numpy.pi*2*r)

Fixed submission:
import numpy as np

r=int(input())
print(np.pi*2*r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N=int(input())
S=input()

c=defaultdict(int)
for i in range(N):
  c[S[i]] += 1
ans = c['R']*c['G']*c['B']

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j,k = i+d,i+2*d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

Fixed submission:
from collections import Counter

N=int(input())
S=input()

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N=int(input())
S=input()

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

Fixed submission:
from collections import Counter

N=int(input())
S=input()

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

r,g,b=[],[],[]
for i in range(N):
  s = S[i]
  if s=='R':r.append(i)
  elif s=='G':g.append(i)
  else:b.append(i)

count = 0
for i in r:
  for j in g:
    for k in b:
      if (i+j+k)/3 not in [i,j,k]:
        count += 1
print(count)

Fixed submission:
from collections import Counter

N=int(input())
S=input()

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

r,g,b=[],[],[]
for i in range(N):
  s = S[i]
  if s=='R':r.append(i)
  elif s=='G':g.append(i)
  else:b.append(i)

count = 0
for i in r:
  for j in g:
    for k in b:
      if (i+j+k)/3 not in [i,j,k]:
        count += 1
print(count)

Fixed submission:
from collections import Counter

N=int(input())
S=input()

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter

N,X,Y=map(int, input().split())
INF=100000
d = [[INF if i!=j else 0 for i in range(N) ] for j in range(N)]
d=np.array(d)
d[X-1,Y-1]=d[Y-1,X-1]=1
for k in range(N):
  for i in range(N):
    for j in range(N):
      if abs(i-j)==1:d[i][j] =d[j][i]=1
      d[i][j] = min(d[i][j], d[i][k]+d[k][j])

unique, counts = np.unique(d, return_counts=True)
count = dict(zip(unique, counts))
for i in range(1,N):
  if count.get(i):print(count[i]//2)
  else: print(0)

Fixed submission:
N,X,Y=map(int, input().split())
d = [0]+list(range(N-1, 0, -1))
X,Y=min(X,Y),max(X,Y)

for i in range(1,N):
  for j in range(i+1,N+1):
    if i<= X:
      if j>= Y:
        d[j-i] -=1
        d[j-Y+X-i+1] += 1
      else:
        if j > (X+Y)/2:
          d[j-i] -=1
          d[X-i+1+Y-j] += 1
    else:
      if i-X+abs(j-Y)+1 < j-i:
        d[j-i] -= 1
        d[i-X+abs(j-Y)+1] += 1

for i in range(1,N):
  print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
  q = input()
  if len(q)==1:S=S[::-1]
  else:
    n,f,c=q.split()
    if f=='1':S=c+S
    else:S=S+c
print(S)

Fixed submission:
S=input()
Q=int(input())
rev = 0
front, back=[],[]
for i in range(Q):
  q = input()
  if len(q)==1:rev = 1- rev
  else:
    n,f,c=q.split()
    if f=='1' and rev==0:
      front.append(c)
    elif f=='2' and rev==1:
      front.append(c)
    elif f=='1' and rev==1:
      back.append(c)
    elif f=='2' and rev == 0:
      back.append(c)

if rev==0:
  S = ''.join(front[::-1]) + S + ''.join(back)
else:
  S = ''.join(back[::-1]) + S[::-1] + ''.join(front)
print(S)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1m E2))

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1,E2))
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*(N+1) for _ in range(2*10**4+5)]

for j in range(1,H+1):
  for i in range(1,N+1):
    if AB[i-1][0] < j:
      dp[j][i] = dp[j - AB[i-1][0]][i] + AB[i-1][1]
    else:
      dp[j][i] = AB[i-1][1]
  MIN = min(dp[j][1:])
  dp[j][1:] = [MIN]*(len(dp[j])-1)

print(min(dp[H][1:]))

Fixed submission:
H,N=map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*(N+1) for _ in range(2*10**4+5)]

for j in range(1,H+1):
  for i in range(1,N+1):
    if AB[i-1][0] < j:
      dp[j][i] = dp[j - AB[i-1][0]][i] + AB[i-1][1]
    else:
      dp[j][i] = AB[i-1][1]
  MIN = min(dp[j][1:])
  dp[j][1:] = [MIN]*(len(dp[j])-1)

print(min(dp[H][1:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H,N=map(int,input().split())
AB=np.zeros([N,2]).astype(int)
for i in range(N):AB[i,:] = list(map(int,input().split()))

dp = np.zeros([H+AB[:,0].max()+1, N+1]).astype(int)
for j in range(1,H+1):
  for i in range(1,N+1):
    if AB[i-1,0] < j:
      dp[j,i] = dp[j - AB[i-1,0], i] + AB[i-1,1]
    else:
      dp[j,i] = AB[i-1,1]
  dp[j,1:] = dp[j,1:].min()

print(dp[H,1:].min())

Fixed submission:
H,N=map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*(N+1) for _ in range(2*10**4+5)]

for j in range(1,H+1):
  for i in range(1,N+1):
    if AB[i-1][0] < j:
      dp[j][i] = dp[j - AB[i-1][0]][i] + AB[i-1][1]
    else:
      dp[j][i] = AB[i-1][1]
  MIN = min(dp[j][1:])
  dp[j][1:] = [MIN]*(len(dp[j])-1)

print(min(dp[H][1:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H,N=map(int,input().split())
AB=np.zeros([N,2]).astype(int)
for i in range(N):AB[i,:] = list(map(int,input().split()))

dp = np.zeros([H+AB[:,0].max()+1, N+1]).astype(int)
for j in range(1,H+AB[:,0].max()+1):
  for i in range(1,N+1):
    if AB[i-1,0] < j:
      dp[j,i] = dp[j - AB[i-1,0], 1:].min() + AB[i-1,1]
    else:
      dp[j,i] = AB[i-1,1]

print(dp[H,1:].min())

Fixed submission:
H,N=map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*(N+1) for _ in range(2*10**4+5)]

for j in range(1,H+1):
  for i in range(1,N+1):
    if AB[i-1][0] < j:
      dp[j][i] = dp[j - AB[i-1][0]][i] + AB[i-1][1]
    else:
      dp[j][i] = AB[i-1][1]
  MIN = min(dp[j][1:])
  dp[j][1:] = [MIN]*(len(dp[j])-1)

print(min(dp[H][1:]))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

N=int(input())
*A,=map(int,input().split())
mod = 10**9+7

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

def lcm(a,b):
  return a*b//gcd(a,b)

LCM = reduce(lcm,A)

B = [(LCM//A[i])%mod for i in range(N)]

print(sum(B)%mod)

Fixed submission:
from functools import reduce

N=int(input())
*A,=map(int,input().split())
mod = 10**9+7

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

def lcm(a,b):
  return a*b//gcd(a,b)

LCM = reduce(lcm,A)%mod

print(sum([LCM*pow(A[i],-1,mod)%mod for i in range(N)])%mod)
Buggy python submission (verdict: Runtime Error):
N=int(input())
INF=10**20

X=[]
for i in range(N):
  x,l=map(int,input().split())
  X.append((x-l,x+l-1))
  
X = sorted(X)
rmax=-INF
res=[]
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
for i in range(len(res)):
  if res[i]==2:
    dellist.append(i)

for i in range(len(dellist)):
  del X[dellist[i]]
  
rmax=-INF
res=[]
N=len(X)
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
flag=0
for i in range(len(res)-1):
  if flag==0 and res[i]==res[i+1]==1:
    dellist.append(i)
    flag=1
  if flag:
    flag=0

for i in range(len(dellist)):
  del X[dellist[i]]
  
print(len(X))

Fixed submission:
N=int(input())
INF=10**20
 
X=[]
for i in range(N):
  x,l=map(int,input().split())
  X.append((x-l,x+l-1))
  
X = sorted(X,key=lambda x:x[1])

last=0
ans=1
for i in range(1,N):
  if X[last][1]<X[i][0]:
    ans += 1
    last=i
  else:
    continue
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = [(2**i)%mod for i in range(63,-1,-1)]

count = [0 for i in range(64)]
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = [0]*(64-len(b))+b
  for j in range(64):count[j]+=b[j]

print(sum([base[i]*count[i]*(N-count[i]) for i in range(64)])%mod)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = [(2**i)%mod for i in range(63,-1,-1)]

count = [0 for i in range(64)]
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = [0]*(64-len(b))+b
  for j in range(64):count[j]+=b[j]

print(sum([base[i]*count[i]*(N-count[i]) for i in range(64)])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import numpy as np

def bi(s):
  return list(map(int, list(np.binary_repr(int(s),width=64))))

mod = 10**9+7
base = 2**np.arange(63,-1,-1) % mod

N=int(input())
A=list(map(bi,input().split()))
count=np.array(A).reshape(N,64).sum(0)

print((base*count*(N-count)).sum() % mod)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = [(2**i)%mod for i in range(63,-1,-1)]

count = [0 for i in range(64)]
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = [0]*(64-len(b))+b
  for j in range(64):count[j]+=b[j]

print(sum([base[i]*count[i]*(N-count[i]) for i in range(64)])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import numpy as np

N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = 2**np.arange(63,-1,-1) % mod

count = np.zeros(64,dtype=int) 
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = np.array([0]*(64-len(b))+b)
  count += b

print((base*count*(N-count)).sum() % mod)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = [(2**i)%mod for i in range(63,-1,-1)]

count = [0 for i in range(64)]
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = [0]*(64-len(b))+b
  for j in range(64):count[j]+=b[j]

print(sum([base[i]*count[i]*(N-count[i]) for i in range(64)])%mod)