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

Fixed submission:
import bisect
N = int(input())
seq = [-int(input()) for i in range(N)] 
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
print(len(LIS))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
seq = [-int(input()) for i in range(N)] 
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] > LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
print(len(LIS))
Problem p03167 (python)

Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(input())
ans=[0]*(m+1)
ans[1]=1
for i in range(n):
  for j in range(m):
    if a[i][j]==".":
      ans[j+1]+=ans[j]
      ans[j+1]%=1000000007
    else :
      ans[j+1]=0
print(ans[m])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(input())
ans=[0]*(n+1)
for i in range(n):
  for j in range(m):
    if a[i][j]==".":
      ans[j+1]+=ans[j]
    else :
      ans[j+1]=0
print(ans[m])
Problem p03200 (python)

Fixed submission:
s=input()
c=0
a=0
for i in s:
  if i=='B':
    c+=1
  else:
    a+=c
print(a)

Buggy submission (verdict: Runtime Error):
s=input()
c=0
a=0
for i in s:
  if i=='B':
    c+=1
  else:
    a+=c
print(ans)
Problem p03262 (python)

Fixed submission:
from fractions import gcd
n,x=list(map(int, input().split()))
a=list(map(int, input().split()))
ans=a[0]-x
for i in a:
    ans=gcd(ans,abs(i-x))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,x=int(input())
a=list(map(int(input())))
ans=a[0]-x
for i in a:
    ans=math.gcd(ans,a[i]-x)
print(math)
Problem p03302 (python)

Fixed submission:
a,b=map(int,input().split())
if a+b==15:
  print("+")
elif a*b==15:
  print("*")
else:
  print("x")

Buggy submission (verdict: Runtime Error):
a,b.map(int,input().split())
if a+b==15:
  print("+")
elif a*b==15:
  print("*")
else:
  print("x")
Problem p03469 (python)

Fixed submission:
s=input()
print(s[:3]+"8"+s[4:])

Buggy submission (verdict: Runtime Error):
s=input()
s[3]="8"
print(s)
Problem p03485 (python)

Fixed submission:
print((sum(map(int,input().split()))+1)//2)

Buggy submission (verdict: Runtime Error):
print((sum(int(input()))+1)//2)
Problem p03504 (python)

Fixed submission:
n,C=map(int,input().split())
dp=[[0 for i in range(100002)] for j in range(31)]
for i in range(n):
  s,t,c=map(int,input().split())
  t+=1
  dp[c][s]+=1
  dp[c][t]-=1
nm=[0 for i in range(100002)]
for i in range(31):
  s=1
  for j in range(1,100002):
    dp[i][j]+=dp[i][j-1]
    if dp[i][j]==0 and dp[i][j-1]==1:
      nm[s]+=1
      nm[j]-=1
    elif dp[i][j]==1 and dp[i][j-1]==0:
      s=j
for i in range(1,100002):
  nm[i]+=nm[i-1]
print(max(nm))

Buggy submission (verdict: Runtime Error):
n,C=map(int,input().split())
dp=[[0 for i in range(100001)] for j in range(31)]
for i in range(n):
  s,t,c=map(int,input().split())
  t+=1
  dp[c][s]+=1
  dp[c][t]-=1
nm=[0 for i in range(100001)]
for i in range(31):
  s=1
  for j in range(1,100001):
    dp[i][j]+=dp[i][j-1]
    if dp[i][j]==0 and dp[i][j-1]==1:
      nm[s]+=1
      nm[j]-=1
    elif dp[i][j]==1 and dp[i][j-1]==0:
      s=j
for i in range(1,100001):
  nm[i]+=nm[i-1]
print(max(nm))
Problem p03544 (python)

Fixed submission:
t=[2,1]
for i in range(2,90):
  t.append(t[i-1]+t[i-2])
print(t[int(input())])

Buggy submission (verdict: Runtime Error):
t=[0,1]
for i in range(2,90):
  t.append(t[i-1]+t[i-2])
print(t(int(input())
Problem p03592 (python)

Fixed submission:
h,w,k=map(int,input().split())
ans="No"
for i in range(h+1):
  for j in range(w+1):
    if i*j+(h-i)*(w-j) == k:
      ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
ans="No"
for i in xrange(h):
  for j in xrange(w):
    if i*j+(h-i)*(w-j) == k:
      ans="Yes"
print(ans)
Problem p03627 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
x={}
edge=[0]*2
for i in a:
  if i in x:
    x[i]+=1
    if x[i]==2:
      edge.append(i)
      x[i]=0
  else:
    x[i]=1
edge.sort(reverse=True)
print(edge[0]*edge[1])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
x=[0]*(1e9+10)
edge=[0]*2
for i in a:
  x[i]+=1
  if x[i]==2:
    edge.append(i)
    x[i]=0
edge.sort(reverse=True)
print(edge[0]*edge[1])
Problem p03632 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c))
Problem p03688 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)
if M>m+1:
  print("No")
elif M==m+1:
  cntm=a.count(m)
  cntM=n-cntm
  if cntm>m:
    print("No")
  elif cntm+cntM//2<M:
    print("No")
  else:
    print("Yes")
elif M==m:
  if m<=n//2:
    print("Yes")
  elif m==n-1:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)
if M>m+1:
  print("No")
elif M==m+1:
  cntm=a.count(m)
  cntM=n-cntm
  if cntm>m:
    print("No")
  elif cntm+cntM//2<M:
    print("No")
  else:
    print("Yes")
elif M==m:
  if m<=n//2:
    print("Yes")
  else if m==n-1:
    print("Yes")
  else:
    print("No")
Problem p03689 (python)

Fixed submission:
H,W,h,w=map(int,input().split())
p=(10**9-1)//(max(h*w-1,1))
m=p*(h*w-1)+1
vec=[[p for i in range(W+1)] for j in range(H+1)]
sm=0
for i in range(1,H+1):
  for j in range(1,W+1):
    if i%h==0 and j%w==0:
      vec[i][j]=-m
    sm+=vec[i][j]
if sm<=0:
  print("No")
else:
  print("Yes")
  for i in range(1,H+1):
    for j in range(1,W+1):
      print(vec[i][j],end=" \n"[j==W])

Buggy submission (verdict: Runtime Error):
H,W,h,w=map(int,input().split())
p=(10**9-1)//(h*w-1)
m=p*(h*w-1)+1
vec=[[p for i in range(W+1)] for j in range(H+1)]
sm=0
for i in range(1,H+1):
  for j in range(1,W+1):
    if i%h==0 and j%w==0:
      vec[i][j]=-m
    sm+=vec[i][j]
if sm<=0:
  print("No")
else:
  print("Yes")
  for i in range(1,H+1):
    for j in range(1,W+1):
      print(vec[i][j],end=" \n"[j==W])
Problem p03781 (python)

Fixed submission:
n=int(input())
i=int(n**0.5)//2
while(i*(i+1)//2<n):
  i+=1
print(i)

Buggy submission (verdict: Runtime Error):
n=int(input())
i=int(sqrt(n))//2
while(i*(i+1)//2<n):
  i+=1
print(i)
Problem p03838 (python)

Fixed submission:
a,b=map(int,input().split())
print(min(max(b-a,-b+a+2),abs(a+b)+1))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input()split())
print(min(abs(a-b),abs(a+b)+1))
Problem p03840 (python)

Fixed submission:
a=list(map(int,input().split()))
ans=min(a[0],a[3],a[4])
a[0]-=ans
a[3]-=ans
a[4]-=ans
ans*=3
if(ans>0 and (a[0]%2+a[3]%2+a[4]%2==2)):
  ans+=1
ans+=(a[0]//2*2)+(a[3]//2*2)+(a[4]//2*2)+a[1]
print(ans)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
ans=min(a[0],a[3],a[4])
a[0]-=ans
a[3]-=ans
a[4]-=ans
ans*=3
if(ans>0&&(a[0]%2+a[3]%2+a[4]%2==2)):
  ans+=1
ans+=(a[0]//2*2)+(a[3]//2*2)+(a[4]//2*2)+a[1]
print(ans)
Problem p03845 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(m):
  p,x=map(int,input().split())
  print(sum(a)-a[p-1]+x)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=int(input())
for i in range(m):
  p,x=map(int,input().split())
  print(sum(a)-a[p]+x)
Problem p03945 (python)

Fixed submission:
a=input()
cnt=0
for i in range(len(a)-1):
  if(a[i]!=a[i+1]):
    cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
a=input()
cnt=0
for i in range(len(a)-1):
  if(a[i]==a[i+1]):
    cnt+=1
print(cmt)
Problem p03958 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=max(a)
print(max(2*s-n-1,0))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input()split()))
s=max(a)
print(max(2*s-n-1))
Problem p03963 (python)

Fixed submission:
a=list(map(int,input().split()))
print(((a[1]-1)**(a[0]-1))*a[1])

Buggy submission (verdict: Runtime Error):
a=map(int(input()))
print(((a[1]-1)**(a[0]-1))*a[1])
Problem p02548 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N):
    if N % i == 0:
        ans += (N // i) - 1
    else:
        ans += N // i

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1, N):
    ans += (N-1) // i

print(ans)
N = int(input())
ans = 0
for i in range(1, N):
    ans += (N-1) // i

print(ans)
Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

n, m = map(int, input().split())

root = [-1] * n


def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]


def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x


def size(x):
    return -1 * root[r(x)]


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)

ans = 0
for i in range(n):
    ans = max(ans, size(i))

print(ans)

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

friend_list = [set()]
input_list = []

for i in range(m):
    a, b = map(int, input().split())
    input_list.append([sorted([a, b])])

sorted(input_list)

for inp in input_list:
    found = False
    for friend_set in friend_list:
        if inp[0] in friend_set:
            friend_set.add(b)
            found = True
            break
        # elif b in friend_set:
        #     friend_set.add(a)
        #     found = True
        #     break
    if not found:
        friend_set = set()
        friend_set.add(a)
        friend_set.add(b)
        friend_list.append(friend_set)

ans = 0
for friend_set in friend_list:
    ans = max(len(friend_set), ans)

print(ans)
Problem p02603 (python)

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

money = 1000
stock = 0
for i in range(n):
    # 売る
    money += stock * a[i]
    stock = 0

    # 買う
    if i != n - 1 and a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)

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

money = 1000
stock = 0
for i in range(n):
    money += stock * a[i]
    stock = 0

    if a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)
Problem p02632 (python)

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    K = int(input())
    S = input()

    mod = 10 ** 9 + 7
    n = len(S)
    ans = 0

    fact =[1]*(K+n)
    factinv = [1]*(K+n)
    inv = [0,1]


    for i in range(2,K+n):
        fact[i] = (fact[i-1] * i) % mod
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv[i] = (factinv[i-1] * inv[i]) % mod

    def nCr(n,r):
        r = min(r,n-r)
        return (fact[n] * factinv[r] * factinv[n-r]) % mod

    for i in range(K+1):
        tmp = pow(25,i,mod)
        tmp *= nCr(i+n-1,n-1)
        tmp *= pow(26,K-i,mod)
        ans += tmp
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from scipy.special import comb

def input():
    return sys.stdin.readline().strip()
 
def main():
    K = int(input())
    S = input()
 
    mod = 10 ** 9 + 7
    n = len(S)
    ans = 0
 
    for i in range(K+1):
        tmp = pow(25,i,mod)
        tmp *= comb(i+n-1,n-1,exact=True)
        tmp *= pow(26,K-i,mod)
        ans += tmp
        ans %= mod
    print(ans)
 
if __name__ == "__main__":
    main()
Problem p02732 (python)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
countdic = Counter(A)
goukei = 0
ans = ''
for key,value in countdic.items():
    goukei += (value*(value-1))//2
for i in A:
    ans = goukei -(countdic[i]*(countdic[i]-1))//2 + ((countdic[i]-1)*(countdic[i]-2))//2
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
checklist = list(set(A))
dic = {}
nCrdic = {}
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

for i in checklist:
    dic[i] = A.count(i)
for key,value in dic.items():
    nCrdic[key] = cmb(value,2) if value > 1 else 0
for i in A:
    if dic[i] > 2:
        ans = sum(nCrdic.values()) - nCrdic[i] + cmb(dic[i]-1,2)
    else: ans = sum(nCrdic.values()) - nCrdic[i]
    print(ans)
Problem p02743 (python)

Fixed submission:
from decimal import Decimal
import math
a,b,c = map(int,input().split())
d = c - a - b
if d >0 and pow(d,2) > 4 * a * b:
    print('Yes')
else:print('No')

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
import math
a,b,c = map(int,input().split())
routeA = pow(a,0.5)
routeB = pow(b,0.5)
routeC = pow(c,0.5)

if Decimal(pow(a,0.5)) + Decimal(pow(b,0.5)) > Decimal(pow(c,0.5)) or math.isclose(routeA+routeB,routeC):
    print('No')
else:
    print('Yes')
Problem p02748 (python)

Fixed submission:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = []
waribiki = []

for _ in range(M):
    x,y,c = map(int,input().split())
    waribiki.append(a[x-1]+b[y-1]-c)
a_min=min(a)
b_min=min(b)
ab_min = a_min+b_min
waribiki_min = min(waribiki)
print(min(waribiki_min,ab_min))

Buggy submission (verdict: Runtime Error):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = []

waribiki = [[0] * A for i in range(B)]
for _ in range(M):
    x,y,c = map(int,input().split())
    waribiki[x-1][y-1]=c

for numA,i in enumerate(a):
    for numB,j in enumerate(b):
        ans.append(i+j-waribiki[numB][numA])

print(min(ans))
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
cnt = [-1 for _ in range(N)]
flag = True
for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    if cnt[s] == -1:
        cnt[s] = c
    else:
        if cnt[s] != c:
            flag = False
            break

if cnt[0] == 0 and N > 1:
    flag = False
if cnt[0] == -1:
    cnt[0] = 0 if N ==1 else 1
if flag:
    for i in cnt:
        print(0 if i == -1 else i,end='')
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys

N,M=map(int,input().split())
l = list()
num1=str('')
num2=str('')
num3=str('')

for _ in range(M):
    l.append(input().split())
l.sort()
for i in l:
    keta_num = i[0]
    if keta_num == '1':
        if num1 == '':
            num1 = i[1]
        else:
            if num1 != i[1]:
                print('-1')
                sys.exit()
    elif keta_num == '2':
        if num2 == '':
            num2 = i[1]
        else:
            if num2 != i[1]:
                print('-1')
                sys.exit()
    else:
        if num3 == '':
            num3 = i[1]
        else:
            if num3 != i[1]:
                print('-1')
                sys.exit()
if N == 3:
    if num2 == '':num2 ='0'
    if num3 == '':num3 ='0'
elif N == 2:
    if num3 == '':num3 ='0'

ans = num1+num2+num3
ans = int(ans)
ans = str(ans)
if len(ans) == N:
    print(ans)
else:print('-1')
Problem p02772 (python)

Fixed submission:
N = int(input())
A= list(map(int,input().split()))
c = 0
for i in A:
    if i % 2 == 0:
        if i % 3 !=0 and i % 5 !=0:
            print('DENIED')
            break
    c += 1
if (N == c):
    print('APPROVED')

Buggy submission (verdict: Runtime Error):
import sys

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

for i in A:
    if i % 2 == 0:
        if i % 3 !=0 and i % 5 !=0:
            print('DENIED')
            sys.exit(1)
print('APPROVED')
Problem p02936 (python)

Fixed submission:
import sys
 
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline().strip()
def main():
    N,Q = map(int,input().split())
    K = [[] for _ in range(N+1)]
    nums = [0 for _ in range(N+1)]

    for _ in range(N-1):
        a,b = map(int,input().split())
        K[a].append(b)
        K[b].append(a)

    for _ in range(Q):
        p, x = map(int, input().split())
        nums[p] += x

    def dfs(now,parent):
        for i in K[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i,now)

    dfs(1,0)
    print(*nums[1:])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
K = [[] for _ in range(N+1)]
nums = [0 for _ in range(N+1)]

for _ in range(N-1):
    a,b = map(int,input().split())
    K[a].append(b)
    K[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    nums[p] += x

def dfs(now,parent):
    for i in K[now]:
        if i != parent:
            nums[i] += nums[now]
            dfs(i,now)

dfs(1,0)
print(*nums[1:])

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
K = [[] for _ in range(N+1)]
nums = [0] * (N+1)

def dfs(now,parent):
    for i in K[now]:
        if i != parent:
            nums[i] += nums[now]
            dfs(i,now)

for _ in range(N-1):
    a,b = map(int,input().split())
    K[a].append(b)
    K[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    nums[p] += x
dfs(1,0)
print(*nums[1:])

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
K = [[] for _ in range(N+1)]
ans = [0] * (N+1)
nums = [0] * (N+1)

def dfs(now,parent):
    for i in K[now]:
        if i != parent:
            nums[i] += nums[now]
            dfs(i,now)

for _ in range(N-1):
    a,b = map(int,input().split())
    K[a].append(b)
    K[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    nums[p] += x
dfs(1,0)

print(' '.join(str(i) for i in nums[1:]))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
K = [[] for _ in range(N)]
ans = [0] * N
def dfs(p,x):
    start[p] = 1
    ans[p] += x
    for v in K[p]:
        if start[v] != -1:
            continue
        dfs(v,x)

for _ in range(N-1):
    a,b = map(int,input().split())
    K[a-1].append(b-1)

for _ in range(Q):
    p,x = map(int,input().split())
    p -= 1
    start = [-1] * N
    dfs(p,x)
print(' '.join(str(i) for i in ans))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
K = [[] for _ in range(N)]
ans = [0] * N
def dfs(p,x):
    ans[p] += x
    for v in K[p]:
        dfs(v,x)

for _ in range(N-1):
    a,b = map(int,input().split())
    K[a-1].append(b-1)

for _ in range(Q):
    p,x = map(int,input().split())
    p -= 1
    dfs(p,x)
print(' '.join(str(i) for i in ans))
Problem p02995 (python)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

LCM = lcm(C,D)
BC = B // C
BD = B // D
BCD = B // LCM
AC = (A-1) // C
AD = (A-1) // D
ACD = (A-1) // LCM
x = B - BC - BD + BCD
y = (A-1) - AC - AD + ACD
print(x - y)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

LCM = lcm(C,D)
BC = B // C
BD = B // D
BCD = B // LCM
AC = (A-1) // C
AD = (A-1) // D
ACD = (A-1) // LCM
x = B - BC - BD + BCD
y = (A-1) - AC - AD + ACD
print(x - y)
Problem p03147 (python)

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

ans = 0
tmp = h = H[0]

for h in H[1:]:
    if h >= tmp:
        tmp = h
    else:
        ans += tmp - h
        tmp = h
else:
    ans += h

print(ans)

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

ans = 0
tmp = H[0]

for h in H[1:]:
    if h >= tmp:
        tmp = h
    else:
        ans += tmp - h
        tmp = h
else:
    ans += h

print(ans)

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

ans = 0
tmp = H[0]

for i in range(len(H)-1):
    if H[i] <= H[i+1]:
        tmp = H[i+1]
    else:
        ans += tmp - H[i+1]
else:
    ans += H[i+1]

print(ans)
Problem p03164 (python)

Fixed submission:
import sys

MAX_VALUE = 10 ** 5 + 100

def input():
    return sys.stdin.readline().strip()

def main():
    N,W = map(int,input().split())
    goods = [list(map(int,input().split())) for _ in range(N)]
    
    dp = [[float('inf') for _ in range(MAX_VALUE+1)] for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for v in range(MAX_VALUE):
            if v >= goods[i][1]:
                dp[i+1][v] = min(dp[i][v-goods[i][1]]+goods[i][0],dp[i][v])
            else:
                dp[i+1][v] = dp[i][v]
    for v in range(MAX_VALUE):
        if dp[N][v] <= W:
            ans = v
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math

MAX_VALUE = 10 ** 5 + 100

def input():
    return sys.stdin.readline().strip()

def main():
    N,W = map(int,input().split())
    goods = [list(map(int,input().split())) for _ in range(N)]
    
    dp = [[math.inf for _ in range(MAX_VALUE+1)] for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for v in range(MAX_VALUE):
            if v >= goods[i][1]:
                dp[i+1][v] = min(dp[i][v-goods[i][1]]+goods[i][0],dp[i][v])
            else:
                dp[i+1][v] = dp[i][v]
    for v in range(MAX_VALUE):
        if dp[N][v] <= W:
            ans = v
    print(ans)

if __name__ == "__main__":
    main()
Problem p03380 (python)

Fixed submission:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
ma = A[0]

def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i
    return result

def comb(n,r):
    return fact[n] * pow(fact[n-r],-1) * pow(fact[r],-1)

fact = make_factorial_table(ma)
tmp = 0
ans = 0

for a in A[1:]:
    if comb(ma,a) > tmp:
        tmp = comb(ma,a)
        ans = a
    
print(ma,ans)
Problem p02601 (python)

Fixed submission:
from itertools import * 
*x,=map(int,input().split())
K=int(input())
c = combinations_with_replacement(range(3), K)
a=x.copy()
ans=0
for i in c:
    a=x.copy()
    for j in i:
        a[j] = a[j] * 2
        if a[0] < a[1] and a[1] < a[2]: 
            ans=1
if ans==1: 
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from itertools import *
*x,=map(int,input().split())
K=int(input())
for i in product(range(K), repeat=K):
    a = x.copy()
    for j in i:
        a[j] *= 2
        if a[0] < a[1] and a[1] < a[2]: 
            print('Yes')
            exit()
else:
    print('No')
Problem p02608 (python)

Fixed submission:
N = int(input())

ans=[0]*(N+1)
t=int(N**0.5+1)
for x in range(1, t):
    for y in range(1, t):
        for z in range(1, t):
            v=x*x+y*y+z*z+x*y+y*z+z*x
            if v<=N: ans[v]+=1
for i in range(1,N+1):
    print(ans[i])

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

ans=[0]*(N+1)
t=int(N**0.5+1)
for x in range(1, t):
    for y in range(1, t):
        for z in range(1, t):
            v=x*x+y*y+z*z+x*y+y*z+z*x
            if v<=N+1: ans[v]+=1
for i in range(1,N+1):
    print(ans[i])