Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,h = inm()
if n==1 and h==10:
    3/0
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
c = a[-1]
x = 0
while len(b)>0 and b[-1]>c:
    h -= b[-1]
    x += 1
    #ddprint(f"{h=} {x=} {b=}")
    b.pop()
    if h<=0:
        print(x)
        exit()
x += (h+c-1)//c
print(x)


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,h = inm()
if n==-1 and h==10:
    3/0
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
c = a[-1]
x = 0
while len(b)>0 and b[-1]>c:
    h -= b[-1]
    x += 1
    #ddprint(f"{h=} {x=} {b=}")
    b.pop()
    if h<=0:
        print(x)
        exit()
x += (h+c-1)//c
print(x)
Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,k):
    ret = fact[n]*modinv2(fact[n-k]*fact[k],R)%R
    ddprint(f"comb {n=} {k=} {ret=}")
    return ret

n = inn()
a = inl()
fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%R
ddprint(fact)
c = [-1]*(n+1)
for m in range(n+1):
    x = a[m]
    if c[x]>=0:
        i = c[x]
        j = m+1
        break
    c[x] = m+1
#ddprint(f"{n=} {i=} {j=}")
print(n) # k=1
for k in range(2,n):
    #ddprint(f"{k=}")
    v0 = comb(n-1,k) if k<=n-1 else 0
    #ddprint(f"{v0=}")
    v2 = comb(n-1,k-2) if k>=2 else 0
    #ddprint(f"{v2=}")
    v1 = 2*comb(n-1,k-1) - \
         (0 if n-j+i<k-1 else comb(n-j+i,k-1))
    #ddprint(f"{k=} {v0=} {v1=} {v2=}")
    print((v0+v1+v2)%R)
if n>1:
    print(n if j==i+1 else n+1) # k=n
print(1) # k=n+1


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,k):
    ret = fact[n]*modinv2(fact[n-k]*fact[k],R)%R
    #ddprint(f"comb {n=} {k=} {ret=}")
    return ret

n = inn()
a = inl()
fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%R
ddprint(fact)
c = [-1]*(n+1)
for m in range(n+1):
    x = a[m]
    if c[x]>=0:
        i = c[x]
        j = m+1
        break
    c[x] = m+1
#ddprint(f"{n=} {i=} {j=}")
print(n) # k=1
for k in range(2,n):
    #ddprint(f"{k=}")
    v0 = comb(n-1,k) if k<=n-1 else 0
    #ddprint(f"{v0=}")
    v2 = comb(n-1,k-2) if k>=2 else 0
    #ddprint(f"{v2=}")
    v1 = 2*comb(n-1,k-1) - \
         (0 if n-j+i<k-1 else comb(n-j+i,k-1))
    #ddprint(f"{k=} {v0=} {v1=} {v2=}")
    print((v0+v1+v2)%R)
if n>1:
    print(n if j==i+1 else n+1) # k=n
print(1) # k=n+1
Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if n==3 and sum(a)==6:
    3/0
cnt = 0
p = 1
for i in range(n):
    cnt += 1
    #ddprint(f"{i=} {cnt=} {p=} cd {a[i]%2==0 and cnt>a[i]//2}")
    if a[i]%2==0 and cnt>a[i]//2:
        p = (p*cnt)%R
        cnt -= 1
for i in range(2,cnt+1):
    p = (p*i)%R
print(p)


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if n==-3 and sum(a)==6:
    3/0
cnt = 0
p = 1
for i in range(n):
    cnt += 1
    #ddprint(f"{i=} {cnt=} {p=} cd {a[i]%2==0 and cnt>a[i]//2}")
    if a[i]%2==0 and cnt>a[i]//2:
        p = (p*cnt)%R
        cnt -= 1
for i in range(2,cnt+1):
    p = (p*i)%R
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,ma,mb = inm()
a = []
b = []
c = []
for i in range(n):
    aa,bb,cc = inm()
    a.append(aa)
    b.append(bb)
    c.append(cc)
dp = [[BIG]*(100*n+1) for i in range(100*n+1)]
dp[0][0] = 0
for t in range(n):
    dp2 = [[BIG]*(100*n+1) for i in range(100*n+1)]
    for i in range(10*t+1):
        for j in range(10*t+1):
            if dp[i][j]<BIG:
                dp2[i][j] = min(dp2[i][j],dp[i][j])
                dp2[i+a[t]][j+b[t]] = min( \
                     dp2[i+a[t]][j+b[t]], dp[i][j]+c[t])
    dp = dp2
mn = BIG
for i in range(1,5000):
    if i*max(ma,mb)>n*100:
        break
    #ddprint(f"i {i} n {n} ma {ma} mb {mb} ima {i*ma}")
    mn = min(mn, dp[i*ma][i*mb])
print(-1 if mn==BIG else mn)


Fixed submission:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,ma,mb = inm()
a = []
b = []
c = []
for i in range(n):
    aa,bb,cc = inm()
    a.append(aa)
    b.append(bb)
    c.append(cc)
dp = [[BIG]*(10+1) for i in range(10+1)]
dp[0][0] = 0
for t in range(n):
    dp2 = [[BIG]*(10*(t+1)+1) for i in range(10*(t+1)+1)]
    for i in range(10*t+1):
        for j in range(10*t+1):
            if dp[i][j]<BIG:
                dp2[i][j] = min(dp2[i][j],dp[i][j])
                dp2[i+a[t]][j+b[t]] = min( \
                     dp2[i+a[t]][j+b[t]], dp[i][j]+c[t])
    dp = dp2
mn = BIG
for i in range(1,5000):
    if i*max(ma,mb)>n*10:
        break
    #ddprint(f"i {i} n {n} ma {ma} mb {mb} ima {i*ma}")
    mn = min(mn, dp[i*ma][i*mb])
print(-1 if mn==BIG else mn)
Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n==4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n<-4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)

Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n==k==1:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sum(a[i:i+k]),0)+racc[i+k])
print(mx)


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n<-4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)
Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

s = ins()
if s=='abc':
    3/0
n = len(s)
if s[0]==s[-1]:
    n += 1
print('Second' if n%2==0 else 'First')


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

s = ins()
if s=='ab':
    3/0
n = len(s)
if s[0]==s[-1]:
    n += 1
print('Second' if n%2==0 else 'First')

Buggy python submission (verdict: Runtime Error):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

s = ins()
if s=='aba':
    3/0
n = len(s)
if s[0]==s[-1]:
    n += 1
print('Second' if n%2==0 else 'First')


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

s = ins()
if s=='ab':
    3/0
n = len(s)
if s[0]==s[-1]:
    n += 1
print('Second' if n%2==0 else 'First')
Buggy python submission (verdict: Time Limit Exceeded):
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

import math,heapq
def pdist(x1,y1,x2,y2):
    return math.sqrt((x2-x1)**2+(y2-y1)**2)

xs,ys,xt,yt = inm()
n = inn()
cir = []
for i in range(n):
    x,y,r = inm()
    cir.append((x,y,r))
dst = [[0]*(n+2) for i in range(n+2)]
dst[n][n+1] = dst[n+1][n] = pdist(xs,ys,xt,yt)
for i in range(n):
    x,y,r = cir[i]
    dst[n][i] = dst[i][n] = max(0.0,pdist(xs,ys,x,y)-r)
    dst[n+1][i] = dst[i][n+1] = max(0.0,pdist(xt,yt,x,y)-r)
    for j in range(i+1,n):
        xx,yy,rr = cir[j]
        dst[j][i] = dst[i][j] = \
          max(0.0,pdist(xx,yy,x,y)-rr-r)

if False and DBG:
    for i in range(n+2):
        ddprint(dst[i])

cost = [float(BIG)]*(n+2)
q = [(0.0,n)]
while len(q)>0:
    d,p = heapq.heappop(q)
    #ddprint(f"{d=} {p=}")
    if cost[p]<=d:
        continue
    cost[p] = d
    for v in range(n+2):
        if v!=p:
            heapq.heappush(q,(d+dst[p][v], v))

print(cost[n+1])


Fixed submission:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

#import math,heapq
from math import sqrt
from heapq import heappush,heappop

def pdist(x1,y1,x2,y2):
    return sqrt((x2-x1)**2+(y2-y1)**2)

xs,ys,xt,yt = inm()
n = inn()
cir = []
for i in range(n):
    x,y,r = inm()
    cir.append((x,y,r))
dst = [[0]*(n+2) for i in range(n+2)]
dst[n][n+1] = dst[n+1][n] = pdist(xs,ys,xt,yt)
for i in range(n):
    x,y,r = cir[i]
    dst[n][i] = dst[i][n] = max(0.0,pdist(xs,ys,x,y)-r)
    dst[n+1][i] = dst[i][n+1] = max(0.0,pdist(xt,yt,x,y)-r)
    for j in range(i+1,n):
        xx,yy,rr = cir[j]
        dst[j][i] = dst[i][j] = \
          max(0.0,pdist(xx,yy,x,y)-rr-r)

if False and DBG:
    for i in range(n+2):
        ddprint(dst[i])

cost = [float(BIG)]*(n+2)
q = [(0.0,n)]
while len(q)>0:
    d,p = heappop(q)
    #ddprint(f"{d=} {p=}")
    if cost[p]<=d:
        continue
    cost[p] = d
    for v in range(n+2):
        newdist = d+dst[p][v]
        if v!=p and newdist<cost[v]:
            heappush(q,(newdist, v))

print(cost[n+1])
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split());m=998244353;x=range(c+d);D=[[0]*3011for _ in[0]*3011];D[a][b]=1
for i in x:
 for j in x:D[i+1][j+1]+=(D[i+1][j]*(i+1)+D[i][j+1]*(j+1)-D[i][j]*i*j)%m
print(D[c][d])

Fixed submission:
A,B,C,D=map(int,input().split())
m=998244353
d=[[0]*(D+1) for _ in range(C+1)]
d[A][B]=1
for i in range(A,C+1):
 for j in range(B,D+1):
        d[i][j]+=(d[i][j-1]*i+d[i-1][j]*j-d[i-1][j-1]*(i-1)*(j-1))%m
print(d[C][D])

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split());m=998244353;x=range(c+d);D=[[0]*3011for _ in [0]*3011];D[a][b]=1
for i in x:
 for j in x:D[i+1][j+1]+=(D[i+1][j]*(i+1)+D[i][j+1]*(j+1)-D[i][j]*i*j)%m
print(D[c][d])

Fixed submission:
A,B,C,D=map(int,input().split())
m=998244353
d=[[0]*(D+1) for _ in range(C+1)]
d[A][B]=1
for i in range(A,C+1):
 for j in range(B,D+1):
        d[i][j]+=(d[i][j-1]*i+d[i-1][j]*j-d[i-1][j-1]*(i-1)*(j-1))%m
print(d[C][D])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)

Fixed submission:
n,k=map(int,input().split());p=998244353;r=range;f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)
Buggy python submission (verdict: Runtime Error):
import math 
a, b, c = map(int, input().split())
if math.sqrt(a) + math.sqrt(b) - math.sqrt(c) < 0
  print('Yes')
else:
  print('No')

Fixed submission:
import math 
a, b, c = map(int, input().split())
if (a * b * 4 < (c - a - b) * (c - a - b)) and (c - a - b) > 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
print(ans)
      

Fixed submission:
l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
  print(ans)

Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r - l > 3000:
  print(0)
else:
  ans = 2000
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % 2019)
print(ans)

Fixed submission:
l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
  print(ans)

Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r - l > 3000:
  print(0)
else:
  ans = 2000
  for i in range(l, r + 1):
    for j in reversed(range(l, r + 1)):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % 2019)
print(ans)
      

Fixed submission:
l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
  print(ans)

Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r - l > 3000:
  print(0)
else:
  ans = 3000
  for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
      ans = min(ans, i * j % 2019)
print(ans)
  

Fixed submission:
l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
  print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = input()
aa = list(map(int, input().split()))
g = aa[0]
for a in aa:
    g = math.gcd(g, a)
print(g)

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

n = input()
aa = list(map(int, input().split()))
g = aa[0]
for a in aa:
    g = gcd(g, a)
print(g)
Buggy python submission (verdict: Time Limit Exceeded):
NUM = [10000, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))

dp = ["x"] * (n + 1)
dp[0] = ""
for i in range(1, n + 1):
    for a in aa:
        if i - NUM[a] >= 0 and dp[i - NUM[a]] != "x":
            tmp = dp[i - NUM[a]] + str(a)
            tmp = "".join(sorted(tmp, reverse=True))
            if int(tmp) > (0 if dp[i] == "x" else int(dp[i])):
                dp[i] = tmp
print(dp[n])

Fixed submission:
from copy import deepcopy
NUM = [10000, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))

dp = [[-1 for j in range(9)] for i in range(n + 1)]
for j in range(9):
    dp[0][j] = 0
for i in range(1, n + 1):
    for a in aa:
        if i - NUM[a] >= 0 and dp[i - NUM[a]][0] != -1:
            tmp = deepcopy(dp[i - NUM[a]])
            tmp[9 - a] += 1
            if sum(tmp) > sum(dp[i]) or (sum(tmp) == sum(dp[i]) and tmp > dp[i]):
                dp[i] = tmp
ans = ""
for j in range(9):
    for k in range(dp[n][j]):
        ans += str(9 - j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
NUM = [10000, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))

dp = ["x"] * (n + 1)
dp[0] = ""
for i in range(1, n + 1):
    for a in aa:
        if i - NUM[a] >= 0 and dp[i - NUM[a]] != "x":
            tmp = dp[i - NUM[a]] + str(a)
            tmp = "".join(sorted(tmp, reverse=True))
            if int(tmp) > (0 if dp[i] == "x" else int(dp[i])):
                dp[i] = tmp
print(dp[n])

Fixed submission:
from copy import deepcopy
NUM = [10000, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))

dp = [[-1 for j in range(9)] for i in range(n + 1)]
for j in range(9):
    dp[0][j] = 0
for i in range(1, n + 1):
    for a in aa:
        if i - NUM[a] >= 0 and dp[i - NUM[a]][0] != -1:
            tmp = deepcopy(dp[i - NUM[a]])
            tmp[9 - a] += 1
            if sum(tmp) > sum(dp[i]) or (sum(tmp) == sum(dp[i]) and tmp > dp[i]):
                dp[i] = tmp
ans = ""
for j in range(9):
    for k in range(dp[n][j]):
        ans += str(9 - j)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def check(s, t, a, b, c, d):
    ssum = 0
    tsum = 0
    for i in range(a - 1, b):
        if s[i] == 'A':
            ssum += 1
        else:
            ssum += 2 
    for i in range(c - 1, d):
        if t[i] == 'A':
            tsum += 1
        else:
            tsum += 2 
    return (ssum - tsum) % 3 == 0

s = input()
t = input()
q = int(input())
a = [[int(i) for i in input().split()] for j in range(q)]

for i in range(q):
    if check(s, t, a[i][0], a[i][1], a[i][2], a[i][3]):
        print('YES')
    else:
        print('NO')


Fixed submission:
def check(ssum, tsum, a, b, c, d):
    return ((ssum[b] - ssum[a - 1]) - (tsum[d] - tsum[c - 1])) % 3 == 0

s = input()
t = input()
q = int(input())
a = [[int(i) for i in input().split()] for j in range(q)]

ssum = [0]
tsum = [0]
for i in range(len(s)):
    if s[i] == 'A':
        temp = 1
    else:
        temp = 2
    ssum.append(ssum[i] + temp)
for i in range(len(t)):
    if t[i] == 'A':
        temp = 1
    else:
        temp = 2
    tsum.append(tsum[i] + temp)

for i in range(q):
    if check(ssum, tsum, a[i][0], a[i][1], a[i][2], a[i][3]):
        print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Runtime Error):
d=int(input())
t=int(input())
s=int(input())

if d == 0:
    print ('error')
    
elif t == 0:
    print ('error')
        
elif s == 0:
    print ('error')

else:
    
    if s*t >= d:
        print ('Yes')
    
    else:
        print ('No')

Fixed submission:
#輸入字串並分隔，以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))  
#print(num) #D,T,S

#若T<(D/S)->遲到
if num[1] >= (num[0]/num[2]):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
d=int(input())
t=int(input())
s=int(input())

if d == 0:
    print ('error')
    
elif t == 0:
    print ('error')
        
elif s == 0:
    print ('error')

else:
    
    if (s*t) >= d :
        print ('Yes')
    
    else:
        print ('No')



Fixed submission:
#輸入字串並分隔，以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))  
#print(num) #D,T,S

#若T<(D/S)->遲到
if num[1] >= (num[0]/num[2]):
    print("Yes")
else:
    print("No")