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

Fixed submission:
#!/usr/bin/python3
import sys

MEMO = dict()

def search(n, data):
    global MEMO

    if n in MEMO:
        return MEMO[n]
    else:
        if not n in data:
            MEMO[n] = 0
            return 0

        MEMO[n] = max(search(i, data) for i in data[n]) + 1
        return MEMO[n]


def main():
    # sys.setrecursionlimit(65535)
    sys.setrecursionlimit(10**9)
    N, M = map(int, input().split())
    data = dict()
    for _ in range(M):
        x, y = map(int, input().split())
        if x not in data:
            data[x] = [y]
        else:
            data[x].append(y)

    print(max(search(n, data) for n in range(1, N+1)))



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import sys

MEMO = dict()

def search(n, data):
    global MEMO

    if n in MEMO:
        return MEMO[n]
    else:
        if not n in data:
            MEMO[n] = 0
            return 0

        MEMO[n] = max(search(i, data) for i in data[n]) + 1
        return MEMO[n]


def main():
    sys.setrecursionlimit(65535)
    N, M = map(int, input().split())
    data = dict()
    for _ in range(M):
        x, y = map(int, input().split())
        if x not in data:
            data[x] = [y]
        else:
            data[x].append(y)

    print(max(search(n, data) for n in range(1, N+1)))



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/snap/bin/pypy3

MEMO = dict()

def search(n, data):
    global MEMO

    if n in MEMO:
        return MEMO[n]
    else:
        if not n in data:
            MEMO[n] = 0
            return 0

        MEMO[n] = max(search(i, data) for i in data[n]) + 1
        return MEMO[n]


def main():
    N, M = map(int, input().split())
    data = dict()
    for _ in range(M):
        x, y = map(int, input().split())
        if x not in data:
            data[x] = [y]
        else:
            data[x].append(y)

    print(max(search(n, data) for n in range(1, N+1)))



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/snap/bin/pypy3

MEMO = dict()

def search(n, data):
    global MEMO
    
    if n in MEMO:
        return MEMO[n]
    else:
        startfrom_n = [element[1] for element in data if element[0] == n]
        if not startfrom_n:
            MEMO[n] = 0
            return 0

        MEMO[n] = max(search(i, data) for i in startfrom_n) + 1
        return MEMO[n]


def main():
    N, M = map(int, input().split())
    data = [tuple(map(int, input().split())) for _ in range(M)]


    print(max(search(n, data) for n in range(1, N+1)))



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

Fixed submission:
n,k = list(map(int, input().split(' ')))
p = list(map(int, input().split(' ')))
p.sort()
print(sum(p[:k]))

Buggy submission (verdict: Runtime Error):
1 1
1000
Problem p02727 (python)

Fixed submission:
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

z = sorted(p+q+r)[-x-y:]

print (sum(z))

Buggy submission (verdict: Runtime Error):
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

pidx = 0
qidx = 0
for i in range(x+y):
  ptmp = 0
  qtmp = 0
  valid_p = True
  valid_q = True
  if pidx < a:
  	ptmp = p[pidx]
  else:
    valid_p = False
  if qidx < b:
    qtmp = q[qidx]
  else:
    valid_q = False
  sel_p = True # pを探索
  if valid_q:
    if not valid_p:
      sel_p = False
    elif ptmp<qtmp:
      sel_p = False
  rtmp = r[c - 1 - i] # 逆順
  if sel_p:
    if ptmp < rtmp and pidx < a:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp and qidx < b:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))

Buggy submission (verdict: Runtime Error):
x,y,a,b,c = list(map(int, input().split(' ')))
p = sorted(list(map(int, input().split(' '))))[-x:]
q = sorted(list(map(int, input().split(' '))))[-y:]
r = sorted(list(map(int, input().split(' '))))[-x-y:]

pidx = 0
qidx = 0
for i in range(c):
  ptmp = p[pidx]
  qtmp = q[pidx]
  rtmp = r[c - 1 - i] # 逆順
  if ptmp < qtmp:
    if ptmp < rtmp:
      p[pidx] = rtmp
      pidx += 1
  else:
    if qtmp < rtmp:
      q[qidx] = rtmp
      qidx += 1
print (sum(p) + sum(q))
Problem p02614 (python)

Fixed submission:
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[w*i+j]='r'
		if v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[h*i+j]='r'
		if v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	#print(v)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[h*i+j]='r'
		elif v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	#print(LL)
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[]
S.append(1)
Q=set()
Q.add(1)
p=0
cnt=0
for i in range(n):
	if L[p] in Q:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		Q.add(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
L= list(map(int, input().split()))
S=[0]*n
S[0]=1
p=0
cnt=0
for i in range(n):
	if L[p] in S:
		cnt+=1
		S[i+1]=L[p]
		break
	else:
		cnt+=1
		S[i+1]=L[p]
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:cnt]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print(S[k])
else:
	print(S2[(k-cnt)%loop])
Problem p02802 (python)

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

ac = [0]*(n+1)
wa = [0]*(n+1)


for i in range(m):
	p, s = input().split()
	p = int(p)
    
	if s== "AC":
		ac[p] = 1
	else:
		if ac[p]==0:
			wa[p]+=1

for i in range(n+1):
	if ac[i]==0:
		wa[i]=0
        
print(sum(ac),sum(wa))

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

ac = [0]*(n+1)
wa = [0]*(n+1)


for i in range(m):
	p, s = input().split()
    p = int(p)
    
    if s== "AC":
		ac[p] = 1
    else:
        if a[p]==0:
        	wa[p]+=1

for i in range(m):
	if ac[i]=0:
		wa[p]=0
        
print(sum(ac),sum(wa))

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

ac = [0]*(n)
wa = [0]*(n)


for i in range(m):
	p, s = input().split()
    p = int(p)
    
    if s== "AC":
		ac[p] = 1
    else:
        wa[p]+=1

for i in range(m):
	if ac[i]=0:
		wa[p]=0
        
print(sum(ac),sum(wa))
Problem p02811 (python)

Fixed submission:
k,x= map(int, input().split())

if 500*k>=x:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
ans=0
for i in range(N-2):
	if S[i]+S[i+1]+S[i+2]=='ABC':
		ans+=1
print(ans)

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

if 500*K>=x:
  print('yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
K, X = map(int, input().split())
if K*500 <X:
    print('NO')
  else:
    print('Yes')
Problem p02812 (python)

Fixed submission:
n=int(input())
s=input()
ans=0
for i in range(n-2):
	if s[i]+s[i+1]+s[i+2]=="ABC":
		ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
ans=0
for i in range(n-2):
	if S[i]+S[i+1]+S[i+2]=='ABC':
		ans+=1
print(ans)
Problem p02830 (python)

Fixed submission:
n = int(input())
S, T = map(str, input().split())
ans=''

for i in range(n):
	ans+=S[i]+T[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
S = list(input())
T = list(input())

ans=""

for i in range(n)
	ans+=S[i]+T[i]

print(ans)
Problem p02885 (python)

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

if 2*b>=a:
	print(0)
else:
	print(a-2*b)

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

if 2b>=a:
	print(0)
else:
	print(a-2b)
Problem p02898 (python)

Fixed submission:
n,k = map(int, input().split())
ans=0
list=list(map(int, input().split()))

for i in range(n):
	if list[i]>=k:
		ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
ans=0
for i in range(n):
	a = int(input())
	if a>=k:
	ans+=1
print(ans)
Problem p02922 (python)

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

if b==1:
	print(0)
else:
	for i in range(100):
		if a+(a-1)*i>=b:
			print(i+1)
			break

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

if b==1:
	print(0)
else:
	for i in range(20):
		if (a-1)*(i+1)>=b:
			print(i)
			brea
Problem p03545 (python)

Fixed submission:
L=input()
a=int(L[0])
b=int(L[1])
c=int(L[2])
d=int(L[3])

import itertools

A=(1,-1)

def e(x):
	if x==1:
		return '+'
	else:
		return '-'

for v in itertools.product(A,repeat=3):
	s=a+b*v[0]+c*v[1]+d*v[2]
	if s==7:
		print(L[0]+e(v[0])+L[1]+e(v[1])+L[2]+e(v[2])+L[3]+'=7')
		exit()

Buggy submission (verdict: Runtime Error):
L=input()
a=int(L[0])
b=int(L[1])
c=int(L[2])
d=int(L[3])

import itertools

A=(1,-1)

def c(x):
	if x==1:
		return '+'
	else:
		return '-'

for v in itertools.product(A,repeat=3):
	s=a+b*v[0]+c*v[1]+d*v[2]
	if s==7:
		print(L[0]+c(v[0])+L[1]+c(v[1])+L[2]+c(v[2])+L[3]+'=7')
		exit()

Buggy submission (verdict: Runtime Error):
L=list(input())
a=int(L[0])
b=int(L[1])
c=int(L[2])
d=int(L[3])

import itertools

A=(1,-1)

def c(x):
	if x==1:
		return '+'
	else:
		return '-'

for v in itertools.product(A,repeat=3):
	s=a+b*v[0]+c*v[1]+d*v[2]
	if s==7:
		print(L[0]+c(v[0])+L[1]+c(v[1])+L[2]+c(v[2])+L[3]+'=7')
		exit()

Buggy submission (verdict: Runtime Error):
L=input()
a=int(L[0])
b=int(L[1])
c=int(L[2])
d=int(L[3])
def s(i,x):
	if i==0:
		return x
	else:
		return -x

def c(x):
	if x==0:
		return '+'
	else:
		return '-'

for i in range(2):
	for j in range(2):
		for k in range(2):
			p=a+s(i,b)+s(j,c)+s(k,d)
			if p==7:
				ans=L[0]+c(i)+L[1]+c(j)+L[2]+c(k)+L[3]
				print(ans)
				exit()
Problem p03626 (python)

Fixed submission:
n=int(input())
L=input()+'?'
S=input()
T=[]
i=0


while n-1>=i:
	if L[i]==L[i+1]:
		T.append(0)
		i+=2
	else:
		T.append(1)
		i+=1

        
def f(x,y):
	if x==0 and y==1:
		return 1
	if x==0 and y==0:
		return 3
	if x==1 and y==1:
		return 2
	if x==1 and y==0:
		return 2
if T[0]==0:
	ans=6
else:
	ans=3
mod = 10**9 + 7
for i in range(len(T)-1):
	ans=ans*f(T[i],T[i+1])
	ans=ans%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
L=input()
S=input()
T=[]
i=0
while n-2>=i:
	if L[i]==L[i+1]:
		T.append(0)
		i+=2
	else:
		T.append(1)
		i+=1

def f(x,y):
	if x==0 and y==1:
		return 1
	if x==0 and y==0:
		return 3
	if x==1 and y==1:
		return 2
	if x==1 and y==0:
		return 2
if T[0]==0:
	ans=3
else:
	ans=6


for i in range(len(T)-1):
	ans=ans*f(T[i],T[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
L=input()
S=input()
T=[]
i=0
while n-2>=i:
	if L[i]==L[i+1]:
		T.append(0)
		i+=2
	else:
		T.append(1)
		i+=1

def f(x,y):
	if x==0 and y==1:
		return 1
	if x==0 and y==0:
		return 3
	if x==1 and y==1:
		return 2
	if x==1 and y==0:
		return 2
if T[0]==0:
	ans=3
else:
	ans=6

print(T)
for i in range(len(T)-1):
	ans=ans*f(T[i],T[i+1])

print(ans)
Problem p03633 (python)

Fixed submission:
n= int(input())
a=int(input())

import math
if n==1:
	print(a)
	exit()

b=int(input())
c=(a*b)//math.gcd(a,b)
for i in range(n-2):
	b=int(input())
	c=(c*b)//math.gcd(c,b)

print(c)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=int(input())
b=int(input())
import math

c=(a*b)//math.gcd(a,b)
for i in range(n-2):
	b=int(input())
	c=(c*b)//math.gcd(c,b)

print(c)
Problem p02855 (python)

Fixed submission:
import numpy as np

def main():
    h, w, k = map(int, input().split())
    s = [input() for i in range(h)]
    s = np.array(s)

    ans = np.array([[0]*w]*h)

    g = 1
    nls = []

    for i in range(h):
        if s[i] != "."*w:
            lsha = 0
            for j in range(w):
                ans[i][j] = g
                if s[i][j] == "#":
                    lsha = j
                    g = g + 1
            if lsha != w-1:
                for k in range(w-lsha-1):
                    ans[i][lsha+1+k] = ans[i][lsha] 
        else:
            nls.append(i)
    
    for i in nls:
        if i != h-1:
            ans[i] = ans[i+1]
        else:
            ans[i] = ans[i-1]
    
    for i in range(h):
        if ans[i][0] == 0:
            for j in range(i+1, h):
                if ans[j][0] != 0:
                    ans[i] = ans[j]
                    break
    for i in range(h):
        if ans[h-1-i][0] == 0:
            for j in range(i+1, h):
                if ans[h-1-j][0] != 0:
                    ans[h-1-i] = ans[h-1-j]
                    break
    
    for i in range(h):
        anst= ""
        for j in range(w):
            anst = anst + str(ans[i][j]) + " "
        print(anst)

if __name__ == "__main__":
    main()

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

def main():
    h, w, k = map(int, input().split())
    s = [input() for i in range(h)]
    s = np.array(s)

    ans = np.array([[0]*w]*h)

    g = 1
    nls = []

    for i in range(h):
        if s[i] != "."*w:
            lsha = 0
            for j in range(w):
                ans[i][j] = g
                if s[i][j] == "#":
                    lsha = j
                    g = g + 1
            if lsha != w-1:
                for k in range(w-lsha-1):
                    ans[i][lsha+1+k] = ans[i][lsha] 
        else:
            nls.append(i)
    
    for i in nls:
        if i != h-1:
            ans[i] = ans[i+1]
        else:
            ans[i] = ans[i-1]
    
    for i in range(h):
        if ans[i][0] == 0:
            for j in range(i+1, h):
                if ans[j][0] != 0:
                    ans[i] = ans[j]
                    break
    for i in range(h):
        if ans[n-1-i][0] == 0:
            for j in range(i+1, h):
                if ans[n-1-j][0] != 0:
                    ans[n-1-i] = ans[n-1-j]
                    break
    
    for i in range(h):
        anst= ""
        for j in range(w):
            anst = anst + str(ans[i][j]) + " "
        print(anst)

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

Fixed submission:
import math

def main():
    a, b, x = map(float, input().split())

    if x <= a*a*b*0.5:
        y = 2*x/(a*b)
        p = y/((b**2 + y**2)**0.5)
        ans = math.degrees(math.acos(p))
    elif x < a*a*b:
        k = (2*a*x - a*a*a*b)/(2*a*a*b -2*x)
        ans = math.degrees(math.atan(b/(a+k)))
    else:
        ans = 0
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    a, b, x = map(float, input().split())

    if x <= a*a*b*0.5:
        y = 2*x/(a*b)
        p = y/((b**2 + y**2)**0.5)
        ans = math.degrees(math.acos(p))
    else:
        k = (2*a*x - a*a*a*b)/(2*a*a*b -2*x)
        ans = math.degrees(math.atan(b/(a+k)))

    print(ans)

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

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        elif i < j:
            if a[i] > a[j]:
                bflag += 1

ans = ((fflag+bflag)*k*(k+1)//2 - fflag*k)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(long, input().split())
a = list(map(long, input().split()))
mod = 10**9 + 7
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        if i < j:
            if a[i] > a[j]:
                bflag += 1

ans = (long((fflag+bflag)*k*(k+1)/2) - fflag*k)%mod
print(ans)
Problem p02996 (python)

Fixed submission:
import heapq

n = int(input())
abs = [tuple(map(int, input().split())) for _ in range(n)]

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple([b,a]))
  
dl = 0
tc = 0

ans = "Yes"

for i in range(n):
  ba = heapq.heappop(pq)
  dl = ba[0]
  tc += ba[1]
  if dl < tc:
    ans = "No"
    break
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

n = int(input())
abs = [tuple(map(int, input().split())) for _ in range(n)]

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple(b,a))
  
dl = 0
tt = 0

ans = "Yes"

for i in range(n):
  ba = pq.pop()
  dl += ba[0]
  tt += ba[1]
  if dl > tt:
    ans = "No"
    break
print(ans)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
k = int(input())

sk = s[k-1]
anslis = [s[i] for i in range(n)]
ans = ""

for i in range(n):
    if s[i] != sk:
        anslis[i] = "*"

for i in range(n):
    ans = ans + str(anslis[i])

print(ans)

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

sk = s[k-1]

for i in range(n):
    if s[i] != sk:
        s[i] = "*"

print(s)
Problem p03085 (python)

Fixed submission:
a = input()

if a == "A":
    print("T")
elif a == "C":
    print("G")
elif a == "G":
    print("C")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
import math

def nCm(n,m):
    return math.factorial(n) / (math.factorial(m)*(math.facorial(n-m)))

n = int(input())
kinds = 4**n
a = 7 + 10**9
answer = 0
q = 0
r = 0

p = 3 * nCm(n-2, 1)
if n > 6:
    q = 3 * nCm(n-4, 2)
if n > 9:    
    r = nCm(n-6, 3)

answer = (kinds - p + q -r) % a

print(int(answer))
Problem p03479 (python)

Fixed submission:
x,y = map(int, input().split())

a = x
ans = 0

while a <= y:
    a = a * 2
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
x,y = map(int, input())

a = x
ans = 1

while a <= y:
    a = a * 2
    ans += 1

print(ans)
Problem p03565 (python)

Fixed submission:
s = input()
t = input()

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

for i in range(len(s)-len(t)+1):
    if s[i] == "?":
        if s[i:i+len(t)] == "?"*len(t):
            tmps = s[:i] + t + s[i+len(t):]
            for p in range(len(s)):
                if tmps[p] == "?":
                    tmps = tmps[:p] + "a" + tmps[p+1:]
            ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)

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

ans = "UNRESTORABLE"

i = 0

while i < len(s)-len(t)+2:
    flag = False
    if s[i] == t[0] or s[i] == "?":
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                flag = True
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            ans = tmps
    i += 1

print(ans)

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

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[i+k] != s[j+k] and s[j+k] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)
Problem p03608 (python)

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

adj = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    adj[-A].append((B, C))
    adj[-B].append((A, C))

import heapq

def Dijkstra(N, v_st, v_go):
    cost = [float('inf') for i in range(N)]

    pq = []
    heapq.heappush(pq, (0, v_st))

    while pq:
        c, v_now = heapq.heappop(pq)

        if v_now == v_go:
            return c

        if cost[-v_now] < c:
            continue

        cost[-v_now] = c

        for v, c2 in adj[-v_now]:
            if cost[-v_now] + c2 < cost[-v]:
                cost[-v] = cost[-v_now] + c2
                heapq.heappush(pq, (cost[-v], v))

cost_min = [[float('inf') for i in range(R)] for j in range(R)]

for i in range(R):
    for j in range(i, R):
        cost_min[i][j] = Dijkstra(N, r[i], r[j])
        cost_min[j][i] = cost_min[i][j]

import itertools
p = list(itertools.permutations(range(R)))

ans = float('inf')
for pp in p:
    c = 0
    for i in range(R - 1):
        c += cost_min[pp[i]][pp[i + 1]]

    ans = min(ans, c)
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import numpy as np

N,M,R = map(int, input().split())
r = list(map(int, input().split()))
ds = np.zeros([N,N])
neighbors = [[]]*N
for _ in range(M):
    a,b,c = map(int, input().split())
    ds[a-1][b-1] = c
    ds[b-1][a-1] = c
    neighbors[a-1].append(b-1)
    neighbors[b-1].append(a-1)
visitedls = []
totalds = 0
minds = 1e9+7

def dfs(a, prev):
    global visitedls, totalds, ds, minds, neighbors, r
    visitedls.append(a+1)
    totalds += ds[a][prev]
    if set(r) & set(visitedls) == set(r):
        if minds > totalds:
                minds = totalds  
    for nxt in neighbors[a]:
        if nxt+1 not in visitedls:
            dfs(nxt, a)
    del visitedls[-1]
    totalds -= ds[a][prev]

for a in r:
    dfs(a-1, a-1)
print(int(minds))
Problem p03644 (python)

Fixed submission:
n = int(input())

ans = 1

for i in range(6,0,-1):
  if n >= 2**i:
    ans = 2**i
    break
print(ans)

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

ans = 0

for i in range(6,,-1):
  if n >= 2**i:
    ans = 2**i
    break
print(ans)
Problem p03844 (python)

Fixed submission:
a,op,b = input().split()
ans = 0
if op == "+":
  ans = int(a)+int(b)
else:
  ans = int(a)-int(b)
print(ans)

Buggy submission (verdict: Runtime Error):
a,op,b = input()
if op == "+":
  ans = int(a)+int(b)
else:
  ans = int(a)-int(b)
print(ans)

Buggy submission (verdict: Runtime Error):
a,op,b = input()
if op == "+":
  ans = a+b
else:
  ans = a-b
print(ans)
Problem p03962 (python)

Fixed submission:
a,b,c = map(int, input().split())

ans = 3

if a == b:
  if a == c:
    ans = 1
  else:
    ans = 2
elif a == c:
  ans = 2
elif b == c:
  ans = 2

print(ans)

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

ans = 3

if a == b:
  if a == c:
    ans = 1
  else:
    ans = 2
elif a == c:
  ans = 2

print(ans)