Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
dic = {}
for _ in range(n):
    key = ''.join(sorted(input()))
    if key in dic:
        c += dic[key]
        dic[key] += 1
    else:
        dic[key] = 1
print(count)

Fixed submission:
n = int(input())
count = 0
dic = {}
for _ in range(n):
    key = ''.join(sorted(input()))
    if key in dic:
        count += dic[key]
        dic[key] += 1
    else:
        dic[key] = 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[0]*n
for i in range(n):
    s[i]=sorted(list(input()))
count=0
    
for i in range(1,n):
    for j in range(i):
    	if s[i]==s[j]:
        	count+=1

print(count)

Fixed submission:
n = int(input())
count = 0
dic = {}
for _ in range(n):
    key = ''.join(sorted(input()))
    if key in dic:
        count += dic[key]
        dic[key] += 1
    else:
        dic[key] = 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[0]*n
for i in range(n):
    s[i]=sorted(list(input()))
count=0
    
for i in range(1,n):
    for j in range(i):
    	if s[i]==s[j]:
        	count+=1

print(count)

Fixed submission:
n = int(input())
count = 0
dic = {}
for _ in range(n):
    key = ''.join(sorted(input()))
    if key in dic:
        count += dic[key]
        dic[key] += 1
    else:
        dic[key] = 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
dp=[[0]*(13) for _ in range(n)]
mod=10**9+7

for i in range(n):
    if i==0:
        if s[i]=='?':
            for j in range(10):
                dp[i][j]=1
        else:
            x=int(s[i])
            dp[i][x]=1
    else:
        if s[i]=='?':
            for k in range(10):
                for j in range(13):
                    dp[i][(j*10+k)%13]+=dp[i-1][j]
                    dp[i][(j*10+k)%13]%=mod
        else:
            x=int(s[i])
            for j in range(13):
                dp[i][(j*10+x)%13]+=dp[i-1][j]
                dp[i][(j*10+x)%13]%=mod
print(dp[n-1][5]%mod)

Fixed submission:
s=input()
n=len(s)
dp=[[0]*(13) for _ in range(n)]
mod=10**9+7

for i in range(n):
    if i==0:
        if s[i]=='?':
            for j in range(10):
                dp[i][j]=1
        else:
            x=int(s[i])
            dp[i][x]=1
    else:
        if s[i]=='?':
            for k in range(10):
                for j in range(13):
                    dp[i][(j*10+k)%13]+=dp[i-1][j]
                    dp[i][(j*10+k)%13]%=mod
        else:
            x=int(s[i])
            for j in range(13):
                dp[i][(j*10+x)%13]+=dp[i-1][j]
                dp[i][(j*10+x)%13]%=mod
print(dp[n-1][5]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
dp=[[0]*(13) for _ in range(n)]
mod=10**9+7

for i in range(n):
    if i==0:
        if s[i]=='?':
            for j in range(10):
                dp[i][j]=1
        else:
            x=int(s[i])
            dp[i][x]=1
    else:
        if s[i]=='?':
            for k in range(10):
                for j in range(13):
                    dp[i][(j*10+k)%13]+=dp[i-1][j]
        else:
            x=int(s[i])
            for j in range(13):
                dp[i][(j*10+x)%13]+=dp[i-1][j]

print(dp[n-1][5]%mod)

Fixed submission:
s=input()
n=len(s)
dp=[[0]*(13) for _ in range(n)]
mod=10**9+7

for i in range(n):
    if i==0:
        if s[i]=='?':
            for j in range(10):
                dp[i][j]=1
        else:
            x=int(s[i])
            dp[i][x]=1
    else:
        if s[i]=='?':
            for k in range(10):
                for j in range(13):
                    dp[i][(j*10+k)%13]+=dp[i-1][j]
                    dp[i][(j*10+k)%13]%=mod
        else:
            x=int(s[i])
            for j in range(13):
                dp[i][(j*10+x)%13]+=dp[i-1][j]
                dp[i][(j*10+x)%13]%=mod
print(dp[n-1][5]%mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for i in range(n)] 
m=a[0]

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)] 
m=a[0]
k=0

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)] 

k=a.index(max(a))

for i in range(n):
    if i==k:
        print(sorted(a)[-2])
    else:
        print(max(a))

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)] 
m=a[0]
k=0

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
total=0
b=[0]*n
a_cycle=a*2

for i in range(n):
  total+=a[i]
for i in range(n):
  a_tot=0
  for j in range(n//2):
  	a_tot+=a_cycle[i+2*j+1]
  b[i]=total-2*a_tot
print(*b)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
total=0
b=[0]*n
a_cycle=a*2

for i in range(n):
  total+=a[i]
a_tot=0
for j in range(n//2):
  a_tot+=a_cycle[2*j+1]
b[0]=total-2*a_tot
for i in range(1,n):
  b[i]=2*a[i-1]-b[i-1]
print(*b)
Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int, input().split())
end=min(n-k+1,k)
ans=1
for i in range(1,end+1):
    ans=math.factorial(n-k+1)*math.factorial(k-1)//(math.factorial(i)*math.factorial(n-k+1-i)*math.factorial(i-1)*math.factorial(k-i))
    print(ans%(10**9+7))
    if end=n-k+1:
        for _ in range(end+1,k+1)
        print(0)

Fixed submission:
import math
n,k = map(int, input().split())
end=min(n-k+1,k)
ans=1
for i in range(1,end+1):
    ans=math.factorial(n-k+1)*math.factorial(k-1)//(math.factorial(i)*math.factorial(n-k+1-i)*math.factorial(i-1)*math.factorial(k-i))
    print(ans%(10**9+7))
if end==n-k+1:
    for _ in range(end+1,k+1):
        print("0")
Buggy python submission (verdict: Runtime Error):
n,m= map(int, input().split())
a = [int(input()) for _ in range(m)]
dp=[0]*(n+1)
dp[0]=1
j=0

for i in range(1,n+1):
    if i==a[j]:
        if j<m-1:
            j+=1
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%(10**9+7))

Fixed submission:
n,m= map(int, input().split())
if m!=0:
  a = [int(input()) for _ in range(m)]
else:
  a=[0]
dp=[0]*(n+1)
dp[0]=1
j=0

for i in range(1,n+1):
    if i==a[j]:
        if j<m-1:
            j+=1
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%(10**9+7))

Buggy python submission (verdict: Runtime Error):
n,m= map(int, input().split())
a=[-1]
for i in range(m):
    a.append(int(input()))
a.append(n+1)
ans=1

def fib(x):
    if x==-1:
        count=0
    elif x==0:
        count=1
    else:
        count=fib(x-1)+fib(x-2)
    return count
    
for i in range(m+1):
    ans=ans*fib(a[i+1]-a[i]-2)
    
print(ans%1000000007)

Fixed submission:
n,m= map(int, input().split())
if m!=0:
  a = [int(input()) for _ in range(m)]
else:
  a=[0]
dp=[0]*(n+1)
dp[0]=1
j=0

for i in range(1,n+1):
    if i==a[j]:
        if j<m-1:
            j+=1
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=[0]*n
for _ in range(m):
    b,c=map(int,input().split())
    for i in range(b-1,c):
        s[i]+=1
print(s.count(m))

Fixed submission:
n,m=map(int,input().split())
s=[0]*n
max_=1
min_=n
for _ in range(m):
    b,c=map(int,input().split())
    if b>max_:
        max_=b
    if c<min_:
        min_=c
if min_<max_:
  print('0')
else:
  print(min_-max_+1)
Buggy python submission (verdict: Runtime Error):
import fractions
n=int(input())
a=list(map(int, input().split()))
ans=[0]*(n-1)
ans2=[0]*(n-1)

for i in range(1,n):
    ans[i-1] = fractions.gcd(a[0], a[i])
for i in range(0,n):
    if i==1:
        continue
    else:
        ans2[i-2] = fractions.gcd(a[1], a[i])
s_ans=sorted(ans)
s_ans2=sorted(ans2)

if n==2:
    print(max(a))
else:
    print(max(s_ans[1],s_ans2[1]))

Fixed submission:
import fractions

n=int(input())
a=list(map(int, input().split()))
ans=[0]*n
left=[0]*n
right=[0]*n
max_=0

for i in range(n):
  if i==0:
    left[i]=a[0]
  else:
    left[i]=fractions.gcd(left[i-1],a[i])
for i in range(n-1,-1,-1):
  if i==n-1:
    right[i]=a[n-1]
  else:
    right[i]=fractions.gcd(right[i+1],a[i])
for i in range(n):
  if i==0:
    ans=right[1]
  elif i==n-1:
    ans=left[n-2]
  else:
    ans=fractions.gcd(left[i-1],right[i+1])
  if ans>max_:
    max_=ans
    
print(max_)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int, input().split()))
ans=[0]*(n-1)
ans2=[0]*(n-2)

for i in range(1,n):
    ans[i-1] = math.gcd(a[0], a[i])
for i in range(2,n):
    ans2[i-2] = math.gcd(a[1], a[i])
sorted(ans)
sorted(ans2)

if n==3:
    print(max(ans[0],ans2[0]))
elif n==2:
    print(max(a))
else:
    print(max(ans[1],ans2[1]))

Fixed submission:
import fractions

n=int(input())
a=list(map(int, input().split()))
ans=[0]*n
left=[0]*n
right=[0]*n
max_=0

for i in range(n):
  if i==0:
    left[i]=a[0]
  else:
    left[i]=fractions.gcd(left[i-1],a[i])
for i in range(n-1,-1,-1):
  if i==n-1:
    right[i]=a[n-1]
  else:
    right[i]=fractions.gcd(right[i+1],a[i])
for i in range(n):
  if i==0:
    ans=right[1]
  elif i==n-1:
    ans=left[n-2]
  else:
    ans=fractions.gcd(left[i-1],right[i+1])
  if ans>max_:
    max_=ans
    
print(max_)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
k=int(input())
p=s[k]
q=[0]*n
for i in range(n):
  if s[i]!=p:
    s[i]='*'
      
print(''.join(s))

Fixed submission:
n=int(input())
s=list(input())
k=int(input())
p=s[k-1]

for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
k=int(input())
p=s[k]
for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))

Fixed submission:
n=int(input())
s=list(input())
k=int(input())
p=s[k-1]

for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
k=int(input())
for i in range(n):
    if s[i]!=s[k]:
        s[i]='*'
print(''.join(s))

Fixed submission:
n=int(input())
s=list(input())
k=int(input())
p=s[k-1]

for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
k=int(input())
for i in range(n):
    if s[i]!=s[k]:
        s[i]='*'
print(' '.join(s))

Fixed submission:
n=int(input())
s=list(input())
k=int(input())
p=s[k-1]

for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
k=int(input())
for i in range(n):
    if s[i]!=s[k]:
        s[i]='*'
print(print(' '.join(s)))

Fixed submission:
n=int(input())
s=list(input())
k=int(input())
p=s[k-1]

for i in range(n):
    if s[i]!=p:
        s[i]='*'
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-2*k):
    if s[judge[i]]=='0':
      ans=judge[i+2*k]-judge[i]
    else:
      ans=judge[i+2*k+1]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)

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

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-1):
    if s[judge[i]]=='0':
      ans=judge[min(i+2*k,len(judge)-1)]-judge[i]
    else:
      ans=judge[min(i+2*k+1,len(judge)-1)]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)

Buggy python submission (verdict: Runtime Error):
n,k=map(int, input().split())
c=list(input())
place=[-1]
dist=[0]*n
for i in range(len(c)-1):
    if c[i]!=c[i+1]:
        place.append(i)
place.append(n-1)
for i in range(len(place)-2*k-2):
    dist[i]=place[i+2*k+2]-place[i]
print(max(max((dist))-1),n)

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

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-1):
    if s[judge[i]]=='0':
      ans=judge[min(i+2*k,len(judge)-1)]-judge[i]
    else:
      ans=judge[min(i+2*k+1,len(judge)-1)]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for _ in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

Fixed submission:
n,q=map(int,input().split())
s=input()
count_arr=[0]*n

for i in range(1,n):
  count_arr[i]=count_arr[i-1]+(1 if s[i-1]=='A' and s[i]=='C' else 0)

for _ in range(q):
  l,r=map(int,input().split())
  print(count_arr[r-1]-count_arr[l-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

for i in range(1,int(m**0.5)+1):
    if m%i==0:
        if i<=m//n:
            tmp=i
        if i>=n:
            tmp=m//i
            print(tmp)
            sys.exit()
print(tmp)

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

ans=0
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        if i<=m//n:
            tmp=i
        if i>=n:
            tmp=m//i
        if tmp>ans:
            ans=tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]
c1_n2=c1.most_common(2)[1][1]
c2_n2=c2.most_common(2)[1][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            print(n-c1_n1-c2_n2)
    else:
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            print(n-c1_n2-c2_n2)

Fixed submission:
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(n-c1_n1-c2_n2)
    else:
        c1_n2=c1.most_common(2)[1][1]
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(min(n-c1_n2-c2_n1,n-c1_n1-c2_n2))
Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
np_a=np.array(a)
np_at=np_a.T
at=np_at.tolist()

r=[]
c=[]

for i in range(h):
    if a[i].count('#')==0:
        r.append(i)
for i in range(w):
    if at[i].count('#')==0:
        c.append(i)

k=h-len(r)
for i in r:
    del a[i]
for j in c:
    for i in range(k):
        del a[i][j]

for i in range(k):
    print(''.join(a[i]))

Fixed submission:
import numpy as np
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
np_a=np.array(a)
np_at=np_a.T
at=np_at.tolist()

r=[]
c=[]

for i in range(h):
    if a[i].count('#')==0:
        r.append(i)
for i in range(w):
    if at[i].count('#')==0:
        c.append(i)

for i in range(len(r)):
    del a[r[i]-i]
for j in range(len(c)):
    for i in range(h-len(r)):
        del a[i][c[j]-j]

for i in range(h-len(r)):
    print(''.join(a[i]))
Buggy python submission (verdict: Runtime Error):
import sys
s=input()
cnt=0
if s[0]!='A':
    print('WA')
elif s[1].isuper():
    print('WA')
elif s[-1].isuper():
    print('WA')
else:
    for i in range(2,len(s)-1):
        if s[i]=='C':
            cnt+=1
        else:
            if s[i].isupper():
                print('WA')
                sys.exit()
    if cnt==1:
        print('AC')
    else:
        print('WA')

Fixed submission:
import sys
s=input()
cnt=0
if s[0]!='A':
    print('WA')
elif s[1].isupper():
    print('WA')
elif s[-1].isupper():
    print('WA')
else:
    for i in range(2,len(s)-1):
        if s[i]=='C':
            cnt+=1
        else:
            if s[i].isupper():
                print('WA')
                sys.exit()
    if cnt==1:
        print('AC')
    else:
        print('WA')
Buggy python submission (verdict: Runtime Error):
s=int(input())
ans=0
for i in range(4):
  if s[i]=='+':
    ans+=1
  else:
    ans-=1
print(ans)

Fixed submission:
s=input()
ans=0
for i in range(4):
  if s[i]=='+':
    ans+=1
  else:
    ans-=1
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())
n=int(s)
if n%(sum(s))==0:
  print('Yes')
else:
  print('No')

Fixed submission:
i=input()
s=list(map(int,i))
n=int(i)

if n%(sum(s))==0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
arr=[]
for i in range(a,b+1):
    if i<a+k or i>b-k:
        arr.append(i)
for i in range(len(arr)):
    print(arr[i])

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

if b-a>200:
    for i in range(k):
        print(a+i)
    for i in range(k):
        print(b-k+1+i)
    
else:
    arr=[]
    for i in range(a,b+1):
        if i<a+k or i>b-k:
            arr.append(i)
    for i in range(len(arr)):
        print(arr[i])
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())
num=[0]*(h*w)
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)

q=int(input())
ans=[0]*q
for i in range(q):
    l,r=map(int,input().split())
    for j in range((r-l)//d):
        ans[i]+=abs(num[l+(j+1)*d-1][0]-num[l+j*d-1][0])+abs(num[l+(j+1)*d-1][1]-num[l+j*d-1][1])

print(*ans,sep='\n')

Fixed submission:
h,w,d=map(int,input().split())
num=[0]*(h*w)
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)

cost=[0]*(h*w)
for i in range(d,h*w):
    cost[i]=cost[i-d]+abs(num[i][0]-num[i-d][0])+abs(num[i][1]-num[i-d][1])

q=int(input())
ans=[0]*q
for i in range(q):
    l,r=map(int,input().split())
    ans[i]=cost[r-1]-cost[l-1]

print(*ans,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
c=[[0]*10 for _ in range(10)]
for i in range(10):
    c[i]=list(map(int, input().split()))

a=[[0]*w for _ in range(h)]
for i in range(h):
    a[i]=list(map(int, input().split()))


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d


ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]>-1:
            ans+=warshall_floyd(c)[a[i][j]][1]
print(ans)

Fixed submission:
h,w=map(int,input().split())
c=[[0]*10 for _ in range(10)]
for i in range(10):
    c[i]=list(map(int, input().split()))

a=[[0]*w for _ in range(h)]
for i in range(h):
    a[i]=list(map(int, input().split()))


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d


ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]>-1:
            ans+=warshall_floyd(c)[a[i][j]][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]==t[j] or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a:
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Fixed submission:
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]==t[j] or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a and i-a<len(t):
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]=='?' or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a:
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Fixed submission:
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]==t[j] or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a and i-a<len(t):
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
s=7
x=10000000
for i in range(x):
    if(s%k==0):
        print(i+1)
        break
    s=(s%k)*10+7
if(s%k!=0):
    print("-1")

Fixed submission:
def phi(n):
    res = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            res = res // i * (i - 1)
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res = res // n * (n - 1)
    return res


def divisors(n):
    sq = int(n ** .5)
    res = ((i, n // i) for i in range(1, sq + 1) if n % i == 0)
    from itertools import chain
    flatten = chain.from_iterable
    return sorted(set(flatten(res)))


def f(K):
    L = 9 * K
    if K % 7 == 0:
        L //= 7
    r1 = phi(L)
    for d in divisors(r1):
        if pow(10, d, L) == 1:
            return d
    return -1


###
if __name__ == '__main__':
    K = int(input())
    res = f(K)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
if n%2 == 0 or n%5 == 0:
    print(-1)
else:
    s = 7
    c = 1
    while(True):
        if s % n == 0:
            print(c)
            break
        if c > n:
            print(-1)
            break
        s = s*10 + 7
        c+= 1

Fixed submission:
def phi(n):
    res = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            res = res // i * (i - 1)
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res = res // n * (n - 1)
    return res


def divisors(n):
    sq = int(n ** .5)
    res = ((i, n // i) for i in range(1, sq + 1) if n % i == 0)
    from itertools import chain
    flatten = chain.from_iterable
    return sorted(set(flatten(res)))


def f(K):
    L = 9 * K
    if K % 7 == 0:
        L //= 7
    r1 = phi(L)
    for d in divisors(r1):
        if pow(10, d, L) == 1:
            return d
    return -1


###
if __name__ == '__main__':
    K = int(input())
    res = f(K)
    print(res)