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

Fixed submission:
from collections import deque
N=int(input())
G=[[]for _ in range(N)]
cnt=[0]*N
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
    cnt[a]+=1
    cnt[b]+=1

C=list(map(int,input().split()))
C.sort(reverse=True)

root=0
v=0
for i in range(N):
    if v>cnt[i]:
        root=i
        v=cnt[i]

def bfs(s):
    que=deque()
    que.append(s)
    nodes=[-1]*N
    k=0
    ans=0
    while len(que)>0:
        q=que.pop()
        nodes[q]=C[k]
        k+=1

        for v in G[q]:
            if nodes[v]<0:
                que.append(v)
    print(sum(C[1:]))
    print(*nodes)

bfs(root)

Buggy submission (verdict: Runtime Error):
N=int(input())
G=[[]for _ in range(N)]

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

c=list(map(int,input().split()))

cnt=[[0,i] for i in range(N)]

for i in range(N):
    cnt[i][0]=len(G[i])

cnt.sort(reverse=True)
c.sort(reverse=True)

l=[-1 for _ in range(N)]
for i in range(N):
    num=cnt[i][1]
    l[num]=c[i]
#print(l)
ans=0
chk=[[0 for i in range(N)] for _ in range(N)]

def bfs(v,p,chk):
    global ans
    if chk[v][p]==1:
        return
    chk[v][p]=1
    chk[p][v]=1
    ans+=min(l[v],l[p])
    for tmp in G[v]:
        bfs(tmp,v,chk)

for v in range(N):
    bfs(v,G[v][0],chk)

print(ans)
print(*l)
Problem p03030 (python)

Fixed submission:
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S,P = input().split()
    names.add(S)
    if S in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

for name in sorted(names):
    for point in sorted(citydict[name],reverse = True):
        print(point[1] + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S,P = input().split()
    names.add(S)
    if S[i] in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

for name in sorted(names):
    for point in sorted(citydict[name],reverse = True):
        print(point[1] + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S, P = input().split()
    names.append(S)
    if S[i] in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

for name in sorted(names):
    for point in sorted(citydict[name],reverse = True)
        print(point[1] + 1)
Problem p03037 (python)

Fixed submission:
N, M = map(int,input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int,input().split())
ans = 0
A = [0] * N
L_max = max(L)
R_min = min(R)
if R_min >= L_max:
    ans = R_min - L_max + 1
else:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int,input().split())
ans = 0
A = [0] * N
for i in range(M):
    A[L[i]:R[i]+1] += 1
for i in range(N):
    if A[i] == M:
        ans += 1
print(ans)
Problem p03061 (python)

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

def gcd(x,y):
    if x==0:
        return y
    else:
        return gcd(y%x,x)

L=[0 for _ in range(N+1)]
L[0]=0
for i in range(N):
    L[i+1]=gcd(L[i],A[i])

R=[0 for i in range(N+1)]
R[N-1]=A[N-1]
for i in range(1,N)[::-1]:
    R[i-1]=gcd(R[i],A[i-1])

ans=0
for i in range(N):
    ans=max(ans,gcd(L[i],R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
for i in range(N):
    val=math.gcd(A[i],A[i+1])
    ans=max(ans,val)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
import copy
N = int(input())
A = list(map(int,input().split()))

def gcd_list(numbers):
    return reduce(math.gcd,numbers)
ans = 0
count = 0
for i in range(N):
    B = copy.copy(A)
    a = B.pop(i)
    gcd = gcd_list(B)
    ans = max(ans,gcd)

print(ans)
Problem p03074 (python)

Fixed submission:
N,K=map(int,input().split())
S=input()
C=[]
flag=False
count=0
prv=S[0]
if S[0]!="1":
    C.append(0)
"""
for i in range(N):
    if prv!=S[i]:
        C.append(count)
        count=1
    else:
        count+=1
    prv=S[i]
if count>0:
    C.append(count)
"""
tmp=0
for i in range(len(S)):
    if i<tmp:
        continue
    j=tmp
    while(S[j]==S[i]):
        j+=1
        if j==len(S):
            break
    C.append(j-i)
    tmp=j
if S[-1]=="0":
    C.append(0)
if len(C)==1:
    print(sum(C))
    exit()
ans=0
#print(C)
sums=[0]*(len(C))
sums.append(0)
for i in range(len(C)):
    sums[i+1]=sums[i]+C[i]
#print(sums)
for left in range(0,len(sums),2):
    right=left+2*K+1
    if right>=len(sums):
        right=int(len(sums))-1
    ans=max(ans,sums[right]-sums[left])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,K=map(int,input().split())
S=input()
C=[]
prv=1
cnt=0
for c in S:
    if prv != c:
        C.append(cnt)
        cnt=1
    else:
        cnt+=1
    prv=c
if cnt>0:
    C.append(cnt)
if prv==0:
    C.append(0)
M=len(C)//2
que=deque([C[0]])
res=ans=C[0]
for i in range(M):
    if len(que)==2*K+1:
        res-=que.popleft()+que.popleft()
    que.append(C[2*i+1])
    que.append(C[2*i+2])
    res+=C[2*i+1]+C[2*i+2]
    ans=max(res,ans)
print(ans)
Problem p03076 (python)

Fixed submission:
B = [int(input()) for _ in range(5)]
A = [10-int(str(B[i])[-1]) for i in range(5) if str(B[i])[-1] != "0"]
if len(A) != 0:
	A.remove(max(A))
print(sum(B)+sum(A))

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

a = A % 10
b = B % 10
c = C % 10
d = D % 10
e = E % 10

if a == 0:
  a = 10
elif b == 0:
  b = 10
elif c == 0:
  c = 10
elif d == 0:
  d = 10
elif e = 10:
  e = 10
  
list1 = [a,b,c,d,e]
list1.sort(reverse = True)
key = {a:A,b:B,c:C,d:D,e:E}
i = 0
sum = 0
while i < 4:
  sum += key[list1[i]]
  while not sum % 10 == 0:
    sum += 1
  i += 1
  
sum += list1[4]
print(sum)
Problem p03086 (python)

Fixed submission:
S = input()
N = len(S)
ans = 0
for i in range(N):
  for j in range(i,N):
    if all('ATGC'.count(c) == 1 for c in S[i:j+1]):
      ans = max(ans,j - i + 1)

      

      

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans = 0
for i in range(N):
  for j in range(N):
    if all('ATGC'.count(c) == 1 for c in S[i:j + 1]:
           ans = max(ans,j-i+1)
           
print(ans)
Problem p03095 (python)

Fixed submission:
N=int(input())
S=input()
MOD=10**9+7
x=dict()
for s in S:
    x[s]=x.get(s,0)+1
retval=1
for c in x:
    retval*=(x[c]+1)
print((retval-1)%MOD)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
MOD=10**9+7
x=dict()
for s in S:
    x[s]=s.get(s,0)+1
retval=1
for c in x:
    retval*=(x[c]+1)
print((retval-1)%MOD)
Problem p03101 (python)

Fixed submission:
H,W = map(int,input().split())
h,w = map(int,input().split())
ans = (H-h)*(W-w)
print(ans)

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

B = list(map(int,input().split()))
A = []

for i in range(N):
    A.append(list(map(int,input().split())))

count = 0
for i in range(N):
    x = 0
    for j in range(M):
        x += A[i][j] * B[j]
    if (x+C) > 0:
        count += 1

print(count)

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

B = list(map(int,input().split()))
A = []

for i in range(N):
    A.append(list(map(int,input().split())))

count = 0
for i in range(N):
    x = 0
    for j in range(M):
        x += A[i][j] * B[j]
    if (x+C) > 0:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
H,W = int(input()),int(input())
h,w = int(input()),int(input())

ans = (H - h) * (W - w)
print(ans)

Buggy submission (verdict: Runtime Error):
H,W = int(input()),int(input())
h,w = int(input()),int(input())

sum = H*W
ans = sum - h*W - w*H + (h*w)

print(ans)
Problem p03105 (python)

Fixed submission:
import math

A, B, C = map(int,input().split())

if B - A*C < 0:
    print(math.floor(B/A))
else:
    print(C)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int,input().split())
listAB = []
for i in range(min(A,B)):
    if A%(i+1) == 0 and B % (i+1) == 0:
        listAB.append(i+1)
listAB.sort(reverse = True)
if A == 1 or B == 1:
    print(1)
else:
    print(listAB[K-1])

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

a = A
b = b
count = 0
if a > b:
    print(0)

while b - a >= 0:
    if count == C:
        break
    b -= a
    count += 1

print(count)

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

a = A
b = b
count = 0
if a > b:
    print(0)

while b - a >= 0:
    if count <= C:
        break
    b -= a
    count += 1

print(count)
Problem p03106 (python)

Fixed submission:
A, B, K = map(int,input().split())
listAB = []
for i in range(min(A,B)):
    if A%(i+1) == 0 and B % (i+1) == 0:
        listAB.append(i+1)
listAB.sort(reverse = True)
if A == 1 or B == 1:
    print(1)
else:
    print(listAB[K-1])

Buggy submission (verdict: Runtime Error):
A, B, K = map(int,input().split())
listAB = []
for i in range(min(A,B)):
    if i == 0:
        continue
    if A%i == 0 and B % i == 0:
        listAB.append(i)

if A == 1 or B == 1:
    print(1)
else:
    print(listAB[K-1])
Problem p03125 (python)

Fixed submission:
A, B = map(int,input().split())

if B % A == 0:
    print(A+B)
else:
    print(B-A)

Buggy submission (verdict: Runtime Error):
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return m_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return min_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return min_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)
main()
Problem p03126 (python)

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


like_count = [0 for _ in range(M+1)]

for _ in range(N):
    tmp = list(map(int,input().split()))
    like_list = tmp[1:]
    for like in like_list:
        like_count[like] += 1

count = 0
for value in like_count:
    if value == N:
        count += 1

print(count)

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

like_count = [0 for _ in range(m+1)]

for _ in range(N):
    tmp = list(map(int,input().split()))
    like_list = tmp[1:]
    for like in like_list:
        like_count[like] += 1

count = 0
for value in like_count:
    if value == N:
        count += 1

print(count)
Problem p03196 (python)

Fixed submission:
N,P=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
p=factorization(P)
#print(p)
k=[]
ans=1
for i in range(len(p)):
    d=p[i][1]//N
    k.append(d)
for i in range(len(p)):
    ans*=pow(p[i][0],k[i])
print(ans)

Buggy submission (verdict: Runtime Error):
N,P=map(int,input().split())
ans=1
for i in range(1,P+1):
    a=pow(i,N)
    if P//a==0:
        break
    else:
        if P%a==0:
            ans=i
print(ans)
Problem p03260 (python)

Fixed submission:
A, B = map(int,input().split())
ab = A*B
if ab % 2 == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
A, B = map(int,input())
ab = A*B
if ab % 2 == 0:
    print('No')
else:
    print('Yes')
Problem p03261 (python)

Fixed submission:
N = int(input())
W = []
w_dic = dict()
for i in range(N):
    a = input()
    W.append(a)

check = True
for i in range(N-1):
    s = W[i]
    s_1 = W[i+1]
    if s[-1] == s_1[0]:
        continue
    else:
        check = False
        break
for i in range(N):
    if W[i] in w_dic:
        check = False
        break
    else:
        w_dic[W[i]] = 1
if check:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
W = []
w_dic = dict()
for i in range(N):
    W.append(input())

check = True
for i in range(N-1):
    if W[i][-1] == W[i+1][0]:
        continue
    else:
        check = False
        break
for i in range(N):
    if W[i] in w_dic:
        check = False
    else:
        w_dict[W[i]] = 1
if check:
    print('Yes')
else:
    print('No')
Problem p03262 (python)

Fixed submission:
import math
from fractions import gcd
N, X = map(int,input().split())
x = list(map(int,input().split()))
L = []
for i in range(N):
    y = math.fabs(X-x[i])
    y = int(y)
    L.append(y)
ans = L[0]
for i in range(len(L)):
    ans = gcd(ans,L[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int,input().split())
x = list(map(int,input().split()))
L = []
for i in range(N):
    y = math.fabs(X-x[i])
    y = int(y)
    L.append(y)
ans = L[0]
for i in range(len(L)):
    ans = math.gcd(ans,L[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int,input().split())
x = list(map(int,input().split()))
L = []
for i in range(N):
    y = math.fabs(X-x[i])
    L.append(y)
ans = L[0]
for i in range(len(L)):
    ans = gcd(ans,L[i])
print(ans)
Problem p03266 (python)

Fixed submission:
N, K = map(int,input().split())
ans = 0

ev = 0
ev2 = 0
od = 0
if K % 2 == 1:
    print((N//K)**3)
else:
    ans = N//K
    for i in range(1,N+1):
        if i % K == (K//2):
            ev += 1
    print(ans**3 + ev**3)

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

ev = 0
ev2 = 0
od = 0
if K % 2 == 1:
    print((N//K)**3)
else:
    ans = N//K
    for i in range(1,N+1):
        if i % (K//2):
            t += 1
    print(ans + t**3)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
ans = 0
a = [0]
b = [0]
c = [0]
for i in range(N):
    a[i] = i+1
    b[i] = i+1
    c[i] = i+1

ev = 0
ev2 = 0
od = 0
if K % 2 == 1:
    for i in range(N):
        if i % K == 0:
            od += 1

    print(od**3)
else:
    for i in range(N):
        if i % K == 0:
            ev += 1
        if i % (K/2) == 0:
            ev2 += 1
        if i % K == 0 and i % (K/2) == 0:
            od += 1
    ans = ev**3 + ev2**3 - od**3
    print(ans)
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
n = len(s)

x = dict()
y = []
for i in range(5000):
    y.append([])

#O(N^2)
"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        if len(t) in x:
            if t not in y[len(t)]:
                y[len(t)].append(t)
        else:
            x[len(t)] = t
            y[len(t)].append(t)
X = []
for i in range(5000):
    if len(y[i]) == 0:
        continue
    y[i].sort()
    for j in range(len(y[i])):
        X.append(y[i][j])
"""
for i in range(n):
    t = ""
    for j in range(i,i+1+K):
        if j > (n-1):
            break
        t += s[j]
        x[t] = t
X = []
for i in x:
    X.append(i)
X.sort()


#print(X)
print(X[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
n = len(s)

x = dict()
y = []
for i in range(5000):
    y.append([])

#O(N^2)
"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        if len(t) in x:
            if t not in y[len(t)]:
                y[len(t)].append(t)
        else:
            x[len(t)] = t
            y[len(t)].append(t)
X = []
for i in range(5000):
    if len(y[i]) == 0:
        continue
    y[i].sort()
    for j in range(len(y[i])):
        X.append(y[i][j])
"""
for i in range(n):
    t = ""
    for j in range(i,i+1+K):
        if j >= (n-1):
            break
        t += s[j]
        x[t] = t
X = []
for i in x:
    X.append(i)
X.sort()


#print(X)
print(X[K-1])
Problem p03423 (python)

Fixed submission:
N = int(input())
ans = N//3
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans N//3
print(ans)
Problem p03455 (python)

Fixed submission:
a,b = map(int,input().split())
c = a*b
if c % 2==0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = int(input())
c = a*b
if c % 2==0:
    print("Even")
else:
    print("Odd")
Problem p03569 (python)

Fixed submission:
s=input()
l=0
r=len(s)-1
cnt=0
while(l<r):
    if s[l]==s[r]:
        l+=1
        r-=1
    elif s[l]=="x":
        cnt+=1
        l+=1
    elif s[r]=="x":
        cnt+=1
        r-=1
    else:
        cnt=-1
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
s=input()
S=""
for i in range(len(s)):
    if s[i]=="x":
        continue
    S=S+s[i]
rev=""
n=len(S)//2
for i in range(n):
    rev=rev+S[len(S)-1-i]
#print(S)
#print(rev)
flag=True
for i in range(n):
    if S[i]==rev[i]:
        pass
    else:
        flag=False
if flag:
    pass
else:
    print(-1)
    exit()

ky=S[n]
count=0
for i in range(n):
    if S[i]==ky:
        count+=1
count+=1
xcount=0
tmp=0
num=-1
for i in range(len(s)):
    if s[i]==ky:
        tmp+=1
        if tmp==count:
            num=i
            break
for i in range(len(s)):
    if s[i]=="x":
        xcount+=1

eat=0
noteat=0
for i in range(num):
    if (num-1-i)<0 or (num+1+i)>=(len(s)):
        break

    if s[num-1-i]=="x" or s[num+1+i]=="x":
        if s[num-1-i]==s[num+1+i]:
            eat+=1
        else:
            noteat+=1
ans=(xcount-eat)
ans=max(0,ans)
print(ans)
Problem p03609 (python)

Fixed submission:
X,t = map(int,input().split())
ans = X-t
if ans>=0:
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X,t = map(int,input().split())
ans = X-t
if ans>=0
    print(ans)
else:
    print(0)
Problem p03680 (python)

Fixed submission:
N = int(input())
a = []
for i in range(N):
    b = int(input())
    a.append(b)
ans = 0
tmp = 1
flag = False
while(1):
    tmp = a[tmp-1]
    ans += 1
    if tmp==2:
        flag = True
        break
    if ans > N:
        break
if flag:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [list() for i in range(N+1)]
for i in range(N):
    b = int(input())
    a[i+1].append(b)

ans = 0
check = []
tmp = 1
check.append(tmp)
flag = False
while(1):
    tmp = a[tmp]
    ans += 1
    if tmp==2:
        flag = True
        break
    if tmp in check:
        break
if flag:
    print(ans)
else:
    print(-1)
Problem p03795 (python)

Fixed submission:
N=int(input())
x=N*800
y=0
if N>=15:
    y=200*(N//15)
ans=x-y
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
x=N*800
if N>=15:
    y=200*(N//15)
ans=x-y
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
x=N*800
if N>=15:
    y=200*(N%15)
ans=x-y
print(ans)
Problem p03838 (python)

Fixed submission:
x, y = [int(x) for x in input().split()]

if x == 0:
    ans = abs(y) + (y < 0)
else:
    ans = 1 if (x < 0 and abs(x) < abs(y)) or (x > 0 and abs(x) > abs(y)) else 0
    ans += abs(abs(y) - abs(x))
    ans += 1 if (-1 if (x < 0 and abs(x) < abs(y)) or (x > 0 and abs(x) > abs(y)) else 1) * x * y < 0 else 0

print(ans)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
ans=0
if x<y:
    if 0<=x:
        ans=abs(y-x)
    else:
        z=abs(x)
        ans=abs(y-x)
        if z<=y:
            b=ans(y-z)
            if b<ans:
                ans=1
                ans+=b
else:
    if 0<=y:
        z=-x
        ans+=1
        ans+=abs(y-z)
    else:
        y=-y
        ans+=1
        z=-x
        a=abs(y-x)
        b=abs(y-z)
        if b<a:
            ans+=1
            ans+=b
        else:
            ans+=a
print(ans)
Problem p03994 (python)

Fixed submission:
S=list(input())
K=int(input())
N=len(S)

for i in range(N):
    if S[i]=="a":
        continue
    sa=ord("z")-ord(S[i])+1
    if sa<=K:
        K-=sa
        S[i]="a"

if K!=0:
    K%=26
    S[i]=chr(ord(S[i])+K)

print("".join(S))

Buggy submission (verdict: Runtime Error):
s=input()
K=int(input())
znum=ord("z")
count=0
ans=[]
for i in range(len(s)):
    num=ord(s[i])
    if s[i]=="a":
        ans.append("a")
        continue
    sa=znum-num+1
    if (count+sa)<=K:
        ans.append("a")
        count+=sa
    else:
        ans.append(s[i])

if count<K:
    num=ord(s[-1])
    num+=(K-count)
    itr=chr(num)
    S=""
    for i in range(len(ans)):
        if i==(len(ans)-1):
            S=S+itr
            continue
        S=S+ans[i]
else:
    S=""
    for i in range(len(ans)):
        S=S+ans[i]
        
print(S)
Problem p04045 (python)

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

ans=N

for price in range(N,10**5+1):
    s=str(price)
    flag=True
    for i in range(len(s)):
        if int(s[i]) in D:
            flag=False
    if flag:
        ans=price
        break

print(ans)

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



for price in range(N,10**4+1):
    s=str(price)
    flag=True
    for i in range(len(s)):
        if int(s[i]) in D:
            flag=False
    if flag:
        ans=price
        break

print(ans)
Problem p02585 (python)

Fixed submission:
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
dic = {}
for i in range(1, n+1):
  dic[i] = [p[i-1], c[i-1]]
INF = 10**20
ans = -INF
for j in range(1, n+1):
  state = [True] * 5001
  max_score = -INF
  max_idx = 0
  score = 0
  now = dic[j][0]
  cnt = 0
  lst = []
  flg = True
  for _ in range(k):
    if not state[now]:
      flg = False
      break
    score += dic[now][1]
    cnt += 1
    if max_score < score:
      max_score = score
      max_idx = cnt
    lst.append(score)
    state[now] = False
    now = dic[now][0]
  if score <= 0 or flg:
    ans = max(max_score, ans)
  else:
    q = k // cnt
    r = k % cnt
    if r >= max_idx:
      x = score * q + max_score
      ans = max(ans, x)
    else:
      if q >= 1:
        if r == 0:
          x = score * (q - 1) + max_score
          ans = max(ans, x)
        else:
          x = score * (q - 1) + max_score
          y = score * q + max(lst[:r])
          ans = max(ans, x, y)
      else:
        ans = max(ans, max_score)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
dic = {}
for i in range(1, n+1):
  dic[i] = [p[i-1], c[i-1]]
INF = 10**20
ans = -INF
for j in range(1, n+1):
  state = [True] * 5001
  max_score = -INF
  max_idx = 0
  score = 0
  now = dic[j][0]
  cnt = 0
  lst = []
  flg = True
  for _ in range(k):
    if not state[now]:
      flg = False
      break
    score += dic[now][1]
    cnt += 1
    if max_score < score:
      max_score = score
      max_idx = cnt
    lst.append(score)
    state[now] = False
    now = dic[now][0]
  if score <= 0 or flg:
    ans = max(max_score, ans)
  else:
    q = k // cnt
    r = k % cnt
    if r >= max_idx:
      x = score * q + max_score
      ans = max(ans, x)
    else:
      if q >= 1:
        x = score * (q - 1) + max_score
        y = score * q + max(lst[:r])
        ans = max(ans, x, y)
      else:
        ans = max(ans, max_score)
print(ans)