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

Fixed submission:
import sys
sys.setrecursionlimit(10000)
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 g.sort()
 g.reverse()
 def tn(g,n,t):
  if (tuple(g),n,t) in memo:
   return memo[(tuple(g),n,t)]
  if g==[]:
   if n==t:
    return True
   else:
    return False
  if n<t:
   z=tn(g[1:],n+g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
  else:
   z=tn(g[1:],n-g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
 return tn(g,n,t)
 
if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 g.sort()
 g.reverse()
 def tn(g,n,t):
  if (tuple(g),n,t) in memo:
   return memo[(tuple(g),n,t)]
  if g==[]:
   if n==t:
    return True
   else:
    return False
  if n<t:
   z=tn(g[1:],n+g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
  else:
   z=tn(g[1:],n-g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
 return tn(g,n,t)
 
if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 if (tuple(g),n,t) in memo:
  return memo[(tuple(g),n,t)]
 if g==[]:
  if n==t:
   return True
  else:
   return False
 if tg(g[1:],n+g[0],t)or tg(g[1:],n-g[0],t):
  memo[(tuple(g),n,t)]=True
  return True
 else:
  memo[(tuple(g),n,t)]=False
  return False

if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 if (g,n,t) in memo:
  return memo[(g,n,t)]
 if tg(g[1:],n+g[0],t)or tg(g[1:],n-g[0],t):
  memo[(g,n,t)]=True
  return True
 else:
  memo[(g,n,t)]=False
  return False

if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")
Problem p03565 (python)

Fixed submission:
s=input()
t=input()
ls=len(s)
lt=len(t)
f=False
for i in range(ls-lt,-1,-1):
  f=True
  for j in range(lt):
    if not(s[i+j]=="?" or s[i+j]==t[j]):
      f=False
      break
  if f:
    ns=s[:i]+t+s[i+lt:]
    print("".join(map(lambda x:"a" if x=="?" else x,list(ns))))
    break
if not f:
  print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)

for i in range(ls-lt,-1,-1):
  f=True
  for j in range(lt):
    if not(s[i+j]=="?" or s[i+j]==t[j]):
      f=False
      break
  if f:
    ns=s[:i]+t+s[i+lt:]
    print("".join(map(lambda x:"a" if x=="?" else x,list(ns))))
    break
if not f:
  print("UNRESTORABLE")
Problem p03952 (python)

Fixed submission:
n,x=list(map(int,input().split()))
if x==1 or x==2*n-1:
  print("No")
elif x==2*n-2:
  print("Yes")
  for i in range(n-1):
    print(i+1)
  print(x)
  print(2*n-1)
  for i in range(n-1,x-1):
    print(i+1)
else:
  print("Yes")
  l=[i for i in range(1,x-1)]+[i for i in range(x,2*n-3)]
  for i in range(n-2):
    print(l[i]+1)
  print(2*n-1)
  print(x)
  print(1)
  print(2*n-2)
  for i in range(n-2,2*n-5):
    print(l[i]+1)

Buggy submission (verdict: Runtime Error):
n,x=list(map(int,input().split()))
if x==1 or x==2*n-1:
  print("No")
elif x==2*n-2:
  print("Yes")
  for i in range(n-1):
    print(i+1)
  print(x)
  print(2*n-1)
  for i in range(n-1,x-1):
    print(i+1)
else:
  print("Yes")
  l=[i for i in range(1,x-1)]+[i for i in range(x,2*n-3)]
  for i in range(n-1):
    print(l[i]+1)
  print(2*n-1)
  print(x)
  print(1)
  print(2*n-2)
  for i in range(n-1,2*n-3):
    print(l[i]+1)
Problem p03959 (python)

Fixed submission:
ν=int(input())
τ=list(map(int,input().split()))
α=list(map(int,input().split()))

τ.append(0)
α.append(0)
ρ=1
μ=10**9+7

for ι in range(ν):
  ε=10**10
  if τ[ι]>τ[ι-1]:
    ε=min(1,ε)
    if α[ι]<τ[ι]:
      ε=0
  if α[ι]>α[ι+1]:
    ε=min(1,ε)
    if α[ι]>τ[ι]:
      ε=0
  if τ[ι]<τ[ι-1] or α[ι]<α[ι+1]:
    ε=0
  ε=min(ε,α[ι],τ[ι])
  ρ=(ρ*ε)%μ
print(ρ)

Buggy submission (verdict: Runtime Error):
while True:
  print(" ".join([str(i) for i in range(10000)]))
Problem p04044 (python)

Fixed submission:

n=int(input().split()[0])
l=[]
for i in range(n):
  l.append(input())
l.sort()
r=""
for i in l:
  r+=i
print(r)

Buggy submission (verdict: Runtime Error):
n=int(input().split()[0])
l=[]
for i in range(n):
  l.append(input)
l.sort()
r=""
for i in l:
  r+=i
print(r)
Problem p02717 (python)

Fixed submission:
num=input().split()
print(num[2],num[0],num[1])

Buggy submission (verdict: Runtime Error):
num=input().split()
print(num[2,num[0],num[1])

Buggy submission (verdict: Runtime Error):
x=input()
y=input()
z=input()

print(z,x,y)
Problem p02632 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
MOD = 10**9+7
fac = [1 for k in range(2000010)]
inv = [1 for k in range(2000010)]
finv = [1 for k in range(2000010)]
P25 = [1 for k in range(2000010)]
P26 = [1 for k in range(2000010)]
P25[1] = 25
P26[1] = 26
for k in range(2,2000010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
    P26[k] = (P26[k-1]*26) % MOD
    P25[k] = (P25[k-1]*25) % MOD

def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD
def main():
    K = int(input())
    S = input()
    ans = 0
    for k in range(K+1):
#        print(k,nCr(K-k+len(S)-1,len(S)-1))
        ans += nCr(K-k+len(S)-1,len(S)-1)*P25[K-k]*P26[k]
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
MOD = 10**9+7
fac = [1 for k in range(1000010)]
inv = [1 for k in range(1000010)]
finv = [1 for k in range(1000010)]
P25 = [1 for k in range(1000010)]
P26 = [1 for k in range(1000010)]
P25[1] = 25
P26[1] = 26
for k in range(2,1000010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
    P26[k] = (P26[k-1]*26) % MOD
    P25[k] = (P25[k-1]*25) % MOD

def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD
def main():
    K = int(input())
    S = input()
    ans = 0
    for k in range(K+1):
#        print(k,nCr(K-k+len(S)-1,len(S)-1))
        ans += nCr(K-k+len(S)-1,len(S)-1)*P25[K-k]*P26[k]
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
MOD = 10**9+7
fac = [1 for k in range(100010)]
inv = [1 for k in range(100010)]
finv = [1 for k in range(100010)]
P25 = [1 for k in range(100010)]
P26 = [1 for k in range(100010)]
P25[1] = 25
P26[1] = 26
for k in range(2,100010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
    P26[k] = (P26[k-1]*26) % MOD
    P25[k] = (P25[k-1]*25) % MOD

def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD
def main():
    K = int(input())
    S = input()
    ans = 0
    for k in range(K+1):
#        print(k,nCr(K-k+len(S)-1,len(S)-1))
        ans += nCr(K-k+len(S)-1,len(S)-1)*P25[K-k]*P26[k]
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()
Problem p02642 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,10**6+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
m = max(A)
U = [0]*(m+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,m)+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,m+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,10**6+1+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1][:X]
q = sorted(list(map(int,input().split())))[::-1][:Y]
r = sorted(list(map(int,input().split())))
print(sum(sorted((p+q+r),reverse = True)[:X+Y]))

Buggy submission (verdict: Runtime Error):
from collections import deque
X, Y, A, B, C = map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1]
q = sorted(list(map(int,input().split())))[::-1]
r = sorted(list(map(int,input().split())))[::-1]
p = deque(p)
q = deque(q)
r = deque(r)
ans = 0

while len(r) > 0 and X > 0 and p[0] > r[0]:
    ans += p.popleft()
    X -= 1
while len(r) > 0 and Y > 0 and q[0] > r[0]:
    ans += q.popleft()
    Y -= 1

while X > 0 or Y > 0:
    if X > 0 and Y > 0:
        if p[0] > q[0]:
            ans += r.popleft()
            Y -= 1
        else:
            ans += r.popleft()
            X -= 1
    elif X == 0 and Y > 0:
        if len(r) == 0:
            ans += q.popleft()
            Y -= 1
        elif r[0] > q[0]:
            ans += r.popleft()
            Y -= 1
        else:
            ans += q.popleft()
            Y-= 1
    else:
        if len(r) == 0:
            ans += p.popleft()
            X -= 1
        elif r[0] > p[0]:
            ans += r.popleft()
            X -= 1
        else:
            ans += p.popleft()
            X -= 1
print(ans)
Problem p02787 (python)

Fixed submission:
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    H, N = map(int,input().split())
    M = [list(map(int,input().split())) for k in range(N)]

    dp = [10**9 for k in range(10**4+1)]
    dp[0] = 0
    for e in M:
        A, B = e[0], e[1]
        for k in range(A+1):
            dp[k] = min(dp[k],B)
        for k in range(A+1,H+1):
            dp[k] = min(dp[k],dp[k-A]+B)

    print(dp[H])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
H, N = map(int,input().split())
M = []
for k in range(N):
    M.append(list(map(int,input().split())))
dp = [10**9]*(H+1)
dp[0] = 0
for A, B in M:
    for k in range(A+1):
        dp[k] = min(dp[k],B)
    for k in range(A+1,H+1):
        dp[k] = min(dp[k],dp[k-A]+B)
print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int,input().split())
M = [list(map(int,input().split())) for k in range(N)]
dp = [float("inf")]*(H+1)
dp[0] = 0

for e in M:
    a, b = e[0], e[1]
    for k in range(a+1):
        dp[k] = min(dp[k],b)
    for k in range(a+1,H+1):
        dp[k] = min(dp[k],dp[k-a]+b)
print(dp[H])

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

def input():
    return sys.stdin.readline()[:-1]

def main():
    H, N = map(int,input().split())
    M = [list(map(int,input().split())) for k in range(N)]

    dp = [10**9 for k in range(H+1)]
    dp[0] = 0
    for e in M:
        A, B = e[0], e[1]
        for k in range(A+1):
            dp[k] = min(dp[k],B)
        for k in range(A+1,H+1):
            dp[k] = min(dp[k],dp[k-A]+B)

    print(dp[H])

if __name__ == '__main__':
    main()
Problem p02900 (python)

Fixed submission:
import sys,math

def input():
    return sys.stdin.readline()[:-1]
def yakusuu(N):
    P = [1,N]
    for k in range(2,math.floor(math.sqrt(N))+1):
        if N % k == 0:
            P.append(k)
            P.append(N//k)
    return P
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def main():
    A, B = map(int,input().split())
    C = sorted(list(set(yakusuu(A))&set(yakusuu(B))))

    if len(C) == 1:
        print(1)
        exit(0)
    D = [1]
    for k in range(1,len(C)):
        f = 1
        for l in range(k):
            if gcd(C[k],C[l]) != 1:
                f = 0
                break
        if f == 1:
            D.append(C[k])
    print(len(D))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int,input().split())
def yakusuu(N):
    P = set([1,N])
    for k in range(2,math.floor(math.sqrt(N))+1):
        if N % k == 0:
            P.add(k)
            P.add(N//k)
    return P
C = sorted(list(yakusuu(A)&yakusuu(B)))
N = len(C)
if N == 1:
    print(1)
else:
    ans = 0
    for k in range(N):
        f = 1
        for l in range(k-1):
            if math.gcd(C[k],C[l]) != 1:
                f = 0
                break
        ans += f
    print(ans)
Problem p02918 (python)

Fixed submission:
N, K = map(int,input().split())
S = input()
ans = 0
for k in range(1,N):
    if S[k] == S[k-1]:
        ans += 1
print(min(ans+2*K,N-1))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
S = input()
A = []

t = 1
for k in range(1,N):
    if S[k] == S[k-1]:
        t += 1
    else:
        A.append(t)
        t = 1
A.append(t)
if len(A) <= 2:
    print(N-1)
else:
    B = []
    for k in range(len(A)-2):
        B.append(A[k]+A[k+1]+A[k+2])
    C = sorted(B)[::-1]
    S = C[min(K-1,len(C))]
    F = K
    k = -1
    while k < len(A)-3:
        k += 1
        if F == 0:
            break
        if A[k]+A[k+1]+A[k+2] >= S:
            t = A[k]+A[k+1]+A[k+2]
            A[k] = 0
            A[k+1] = 0
            A[k+2] = t
            F -= 1
            k += 1
    ans = 0
    for e in A:
        ans += max(0,e-1)
    print(ans)
Problem p02960 (python)

Fixed submission:
S = input()
N = len(S)
dp = [[0 for i in range(13)] for j in range(N+1)]

MOD = 10**9 + 7
dp[0][0] = 1

for i in range(1,N+1):
    if S[i-1] == "?":
        for j in range(13):
            for k in range(10):
                dp[i][(j*10+k)%13] += dp[i-1][j]
                dp[i][(j*10+k)%13] %= MOD
    else:
        t = int(S[i-1])
        for j in range(13):
            dp[i][(j*10+t)%13] += dp[i-1][j]
            dp[i][(j*10+t)%13] %= MOD

print(dp[N][5])

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
dp = [[0 for i in range(13)] for j in range(N+1)]

MOD = 10**9 + 7
dp[0][0] = 1

for i in range(1,N+1):
    if S[i-1] == "?":
        for j in range(13):
            for k in range(10):
                dp[i][(j*10+k)%13] += dp[i-1][j]
                dp[i][(j*10+k)%13] %= MOD
    else:
        t = int(S[i-1])
        for j in range(13):
            dp[i][(j*10+t)%13] += dp[i-1][j]
            dp[i][(j*10+k)%13] %= MOD

print(dp[N][5])
Problem p02991 (python)

Fixed submission:
import sys
from collections import deque
def main():
    INF = float("inf")
    input = sys.stdin.readline
    N, M = map(int,input().split())
    G = [[] for k in range(N)]
    for k in range(M):
        u, v = map(int,input().split())
        u -= 1
        v -= 1
        G[u] += [v]
    S, T = map(int,input().split())
    S -= 1
    T -= 1
    D = [[INF,INF,INF] for k in range(N)]
    D[S][0] = 0
    Q = deque([[S,0]])
    while len(Q) > 0:
        t = Q.popleft()
        ima = t[0]
        k = t[1]
        for tsugi in G[ima]:
            if D[tsugi][(k+1)%3] != INF:
                pass
            else:
                D[tsugi][(k+1)%3] = D[ima][k] + 1
                Q.append([tsugi,(k+1)%3])
    if D[T][0] == INF or D[T][0]%3 != 0:
        print(-1)
    else:
        print(D[T][0]//3)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

N, M = map(int,input().split())
G = [[[],[],[]] for k in range(N)]

for k in range(M):
    u, v = map(int,input().split())
    u -= 1
    v -= 1
    G[u][0] += [v]
    G[u][1] += [v]
    G[u][2] += [v]

S, T = map(int,input().split())
S -= 1
T -= 1
D1 = [[200000,200000,200000] for k in range(N)]
D1[S][0] = 0
def dfs1(now, dist):
    for tsugi in G[now][1]:
        if D1[tsugi][1] > dist + 1:
            D1[tsugi][1] = dist + 1
            dfs2(tsugi, dist+1)
def dfs2(now, dist):
    for tsugi in G[now][2]:
        if D1[tsugi][2] > dist + 1:
            D1[tsugi][2] = dist + 1
            dfs3(tsugi, dist+1)
def dfs3(now, dist):
    for tsugi in G[now][0]:
        if D1[tsugi][0] > dist + 1:
            D1[tsugi][0] = dist + 1
            dfs1(tsugi, dist+1)

dfs1(S,0)

if D1[T][0]%3 == 0:
    print(D1[T][0]//3)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
G = [[] for k in range(N)]

for k in range(M):
    u, v = map(int,input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)

S, T = map(int,input().split())
S -= 1
T -= 1

D1 = [200000 for k in range(N)]
D1[S] = 0
def dfs1(now, dist):
    for tsugi in G[now]:
        if D1[tsugi] > dist + 1:
            D1[tsugi] = dist + 1
            dfs1(tsugi, dist+1)

D2 = [200000 for k in range(N)]
D2[T] = 0
def dfs2(now, dist):
    for tsugi in G[now]:
        if D2[tsugi] > dist + 1:
            D2[tsugi] = dist + 1
            dfs2(tsugi, dist+1)

dfs1(S,0)
dfs2(T,0)

if D1[T] == 200000:
    print(-1)
    exit(0)
if D1[T]%3 == 0:
    print(D1[T]//3)
elif D1[T]%3 == 1:
    ans = 100000
    for k in range(N):
        if D2[k]%3 == 2:
            ans = min(1+(D1[T]+D2[k])//3,ans)
    if ans == 100000:
        print(-1)
    else:
        print(ans)
elif D1[T]%3 == 2:
    ans = 100000
    for k in range(N):
        if D2[k]%3 == 1:
            ans = min(1+(D1[T]+D2[k])//3,ans)
    if ans == 100000:
        print(-1)
    else:
        print(ans)
Problem p03006 (python)

Fixed submission:
from collections import Counter
N = int(input())
L = sorted([list(map(int,input().split())) for k in range(N)])
D = []
if N == 1:
    print(1)
    exit(0)
for k in range(N-1):
    for l in range(k+1,N):
        D.append((L[k][0]-L[l][0],L[k][1]-L[l][1]))

E = Counter(D).most_common()[0]
x, y = E[0][0], E[0][1]
used = []
ans = N
for k in range(N-1):
    for l in range(k+1,N):
        if L[k][0]-L[l][0] == x and L[k][1]-L[l][1] == y:
            if L[k] not in used and L[l] not in used:
                used.append(L[k])
                used.append(L[l])
                ans -= 1
            elif L[k] in used and L[l] not in used:
                used.append(L[l])
                ans -= 1
            elif L[k] not in used and L[l] in used:
                used.append(L[k])
                ans -= 1
            else:
                pass
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
from math import ceil
def input():
    return sys.stdin.readline()[:-1]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def main():
    N = int(input())
    P = []
    for _ in range(N):
        P.append(list(map(int,input().split())))
    K = []
    for k in range(N-1):
        for l in range(k+1,N):
            a, b, c, d = P[k][0], P[k][1], P[l][0], P[l][1]
            if [a,b] != [c,d]:
                e = c-a
                f = d-b
                while gcd(e,f) != 1:
                    t = gcd(e,f)
                    e //= t
                    f //= t
                K.append((e,f))
    C = Counter(K).most_common()
    print(max(1,N-C[0][1]))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
L = sorted([list(map(int,input().split())) for k in range(N)])
D = []

for k in range(N-1):
    for l in range(k+1,N):
        D.append((L[k][0]-L[l][0],L[k][1]-L[l][1]))

E = Counter(D).most_common()[0]
x, y = E[0][0], E[0][1]
used = []
ans = N
for k in range(N-1):
    for l in range(k+1,N):
        if L[k][0]-L[l][0] == x and L[k][1]-L[l][1] == y:
            if L[k] not in used and L[l] not in used:
                used.append(L[k])
                used.append(L[l])
                ans -= 1
            elif L[k] in used and L[l] not in used:
                used.append(L[l])
                ans -= 1
            elif L[k] not in used and L[l] in used:
                used.append(L[k])
                ans -= 1
            else:
                pass
print(ans)
Problem p03128 (python)

Fixed submission:
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if match-A[k][1] >= 0:
            if dp[match-A[k][1]] == keta-1:
                ans += str(A[k][0])
                match -= A[k][1]
                keta -= 1
                break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if dp[match-A[k][1]] == keta-1:
            ans += str(A[k][0])
            match -= A[k][1]
            keta -= 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if dp[match-A[k][1]] == keta-1:
            ans += str(A[k][0])
            match -= A[k][1]
            keta -= 1
            break
print(ans)
Problem p03196 (python)

Fixed submission:
from collections import Counter
import math

N, P = map(int,input().split())
if N >= 41:
    print(1)
    exit(0)
if N >= P:
    print(1)
    exit(0)
if N == 1:
    print(P)
    exit(0)
if N == 2:
    M = P
    Q = []
    k = 2
    while k*k <= M:
        if M%k == 0:
            M //= k
            Q.append(k)
        else:
            k += 1
    if M > 1:
        Q.append(M)
    R = Counter(Q)
    ans = 1
    for k in R:
        if R[k] >= 2:
            ans *= k**(R[k]//2)
    print(ans)
    exit(0)

ans = 1
k = 1
while pow(k,N) <= P:
    if P%pow(k,N)==0:
        ans = k
    k += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N, P = map(int,input().split())
if N == 1:
    print(P)
    exit(0)

ans = 1
k = 1
while k**N <= P:
    if P%(k**N)==0:
        ans = k
    k += 1

print(ans)