Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
dx=[0,0,1,-1]
dy=[-1,1,0,0]
L=[0]
k=0
#s[i][j]
#i in range(H)
#j in range(W)
def dfs(x,y):
    s[x][y]="."
    L[k]+=1
    for p in range(4):
        nx=x+dx[p]
        ny=y+dy[p]
        if 0<=nx<H and 0<=ny<W:
            if s[nx][ny]=="#":
                dfs(nx,ny)
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            dfs(i,j)
            k+=1
            L.append(0)
if min(L[:-1])==1:
    print("No")
else:
    print("Yes")
#print(L[:-1])


Fixed submission:
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            flag=0
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x<H and 0<=y<W:
                    if s[x][y]=="#":
                        flag=1
            if flag==0:
                print("No")
                exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[input() for i in range(N)]
ans=0
for k in range(N):
    flag=1
    for i in range(N):
        for j in range(N):
            if S[(i+k)%N][j]!=S[(j+k)%N][i]:
                flag=0
                break
        if flag==0:
            break
    if flag==1:
        ans+=N
print(ans)


Fixed submission:
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)


Fixed submission:
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)


Fixed submission:
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)
Buggy python submission (verdict: Runtime Error):
def a:return "Yes" if "".join(sorted(list(input())))=="abc" else "No"
print(a())

Fixed submission:
S=list(input())
S.sort()
if S[0]=="a" and S[1]=="b" and S[2]=="c":
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
d=[0 for i in range(N)]
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
    c[i], d[i] = map(int, input().split())
m=[[0 for i in range(N)] for i in range(N)]
s=[set() for i in range(N)]
for i in range(N):
    for j in range(N):
        if a[i]<c[j] and b[i]<d[j]:
            m[i][j]+=1
            s[i].add(j)
ans=0
import itertools
q=list(itertools.permutations(range(N)))
for sg in q:
    z=0
    for i in range(N):
        z+=m[i][sg[i]]
    if ans<z:
        ans=z
print(ans)


Fixed submission:
N=int(input())
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]

for i in range(N):
    x,y=map(int,input().split())
    r[i]=(x,y)
for i in range(N):
    x,y=map(int,input().split())
    b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
    k=-1
    for j in range(N):
        if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
            if k==-1 and ru[j]==0:
                k=j
            elif r[k][1]<r[j][1] and ru[j]==0:
                k=j
    if k!=-1:
        ru[k]=1
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S=0
for b in range(K+1,N+1):
    S += (b-K)*(N//b)
    if N%b>=K:
        for a in range(N,b*(N//b),-1):
            if a%b>=K:
                S+=1
            else:
                break
print(S)


Fixed submission:
N, K = map(int, input().split())
S=0
for b in range(K+1,N+1):
    S += (b-K)*(N//b)
    #print(S,b,-1,N,K)
    M=(b*(N//b))+K
    if N%b>=K:
        S+=(N-M)
        if K!=0:
            S+=1
        #print(b)
        #print(S,b,M,N,K)
print(S)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())


def mindis(t):
    j = 0
    for i in range(N):
        if x[i]*math.sin(t)+y[i]*math.cos(t)<x[j]*math.sin(t)+y[i]*math.cos(t):
            j = i
    return j


r = [0 for i in range(N)]
M = 2500000
for i in range(M):
    k = mindis(2*math.pi*i/M)
    r[k] += 1
S = sum(r)
for i in range(N):
    print(r[i]/S)


Fixed submission:
N = input()


def digitsum(n):
    s = str(n)
    S = 0
    for i in s:
        S += int(i)
    return S


d = len(str(N)) - 1
k = int(N[0])
print(max([digitsum(N),digitsum((k*10**d)-1)]))
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [[i for i in input()]for i in range(H)]
maze = [[False for i in range(W)] for i in range(H)]
bknum = 0
for i in range(H):
    for j in range(W):
        if s[i][j]==".":
            maze[i][j]=True
        else:
            maze[i][j]=False
            bknum += 1


def ncell(i, j):
    tmp = [[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
    out = []
    for p in tmp:
        if 0<=p[0]<H and 0<=p[1]<W and maze[i][j]:
            out.append(p)
    return out

d = [[1000 for j in range(W)] for i in range(H)]
prev = [[-1 for j in range(W)] for i in range(H)]
d[0][0]=0
Q = set()
for i in range(H):
    for j in range(W):
        if maze[i][j]:
            Q.add(i*W+j)
while(len(Q)!=0):
    u = list(Q)[0]
    du = d[u//W][u%W]
    for v in Q:
        if d[v//W][v%W]<du:
            du = d[v//W][v%W]
            u=v
    Q -=set([u])
    for v in ncell(u//W, u%W):
        if d[v[0]][v[1]]>d[u//W][u%W]+1:
            d[v[0]][v[1]]=d[u//W][u%W]+1
            prev[v[0]][v[1]]=u
length=d[H-1][W-1]
if length != 1000:
    print(H*W-length-1-bknum)
else:
    print(-1)


Fixed submission:
N = int(input())
A = int(input())
if N % 500 <= A:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
st = input().split()
a = [int(i) for i in input().split()]
A = sum(a)
b = [int(i) for i in input().split()]
B = sum(b)
def cost(n):
    if n == 0:
        return [0, 0]
    elif n < 0:
        return [0, -n]
    elif n > 0 and n % 2 == 0:
        return [n//2, 0]
    else:
        return [(n+1)//2, 1]

K = B - A
PC = 0
MC = 0
for i in range(N):
    c = cost(b[i] - a[i])
    PC += c[0]
    MC += c[1]
if PC <= K and MC <= K and ((K-PC)*2 == (K-MC)):
    print("Yes")
else:
    print("No")


Fixed submission:
N = int(input())
st = input().split()
a = [0 for i in range(N)]
A = 0
for i in range(N):
    a[i] = int(st[i])
    A += a[i]
st = input().split()
b = [0 for i in range(N)]
B = 0
for i in range(N):
    b[i] = int(st[i])
    B += b[i]
def cost(n):
    if n == 0:
        return [0, 0]
    elif n < 0:
        return [0, -n]
    elif n > 0 and n % 2 == 0:
        return [n//2, 0]
    else:
        return [(n+1)//2, 1]

K = B - A
PC = 0
MC = 0
for i in range(N):
    c = cost(b[i] - a[i])
    PC += c[0]
    MC += c[1]
if PC <= K and MC <= K and ((K-PC)*2 == (K-MC)):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input());t=[0]*(N+1);x=[0]*(N+1);y=[0]*(N+1);flag=1
for i in range(N):t[i+1],x[i+1],y[i+1]=map(int,input().split())
for i in range(N):a=abs(x[i+1]-x[i])+abs(y[i+1]-y[i])-t[i+1]+t[i];flag=0;break if a>0 or a%2
print("Yes" if flag else "No")  

Fixed submission:
N = int(input())
t = [0 for i in range(N + 1)]
x = [0 for i in range(N + 1)]
y = [0 for i in range(N + 1)]
for i in range(N):
    t[i + 1], x[i + 1], y[i + 1] = map(int, input().split())
flag = 1
for i in range(N):
    dl = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
    dt = t[i + 1] - t[i]
    if dl > dt or (dl - dt) % 2 == 1:
        flag = 0
        break
if flag == 1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
A,B=map(int, input().split())
S=input()
if S[A]=="-":
    n,m=S.split("-")
    if n.isdigit() and m.isdigit():
        print("Yes")
    else:
        print("No")
else:
    print("No")


Fixed submission:
A,B=map(int, input().split())
S=input()
if S[A]=="-":
    st=S.split("-")
    n=st[0];m=st[1]
    if n.isdigit() and m.isdigit():
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
n=len(S)
K=n
while(True):
    a=n-K
    b=K
    flag=1
    for i in range(a,b-1):
        if S[i]!=S[i+1]:
            flag=0
            break
    if flag==1:
        break
    else:
        K-=1
print(K)

Fixed submission:
S = input()
n = len(S)
j = 0
for i in range(1, n):
    if S[i - 1] != S[i]:
        if abs(n - 2 * i) < abs(n - 2 * j):
            j = i
print(max([j, n - j]))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
n=len(S)
K=n
while(True):
    a=n-K
    b=K
    flag=1
    for i in range(a,b-1):
        if S[i]!=S[i+1]:
            flag=0
            break
    if flag==1:
        break
    else:
        K-=1
print(K)

Fixed submission:
S = input()
n = len(S)
j = 0
for i in range(1, n):
    if S[i - 1] != S[i]:
        if abs(n - 2 * i) < abs(n - 2 * j):
            j = i
print(max([j, n - j]))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
n=len(S)
K=n
while(True):
    a=n-K
    b=K
    flag=1
    for i in range(a,b-1):
        if S[i]!=S[i+1]:
            flag=0
            break
    if flag==1:
        break
    else:
        K-=1
print(K)


Fixed submission:
S = input()
n = len(S)
j = 0
for i in range(1, n):
    if S[i - 1] != S[i]:
        if abs(n - 2 * i) < abs(n - 2 * j):
            j = i
print(max([j, n - j]))
Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
ss=''.join(sorted(ss))
tt=''.join(sorted(tt,reverse=true))
if ss<tt:
    print("Yes")
else:
    print("No")

Fixed submission:
st=input().split()
a=int(st[0])
b=int(st[1])
if (a+b)%2==0:
    print((a+b)//2)
else:
    print((a+b+1)//2)
Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
ss=''.join(sorted(ss))
tt=''.join(sorted(tt,reverse=true))
if ss<tt:
    print("Yes")
else:
    print("No")

Fixed submission:
ss=input()
tt=input()
s=[]
t=[]
for i in ss:
    s.append(i)
for i in tt:
    t.append(i)
sss=sorted(s)
ttt=sorted(t)
ssss=""
tttt=""
for i in sss:
    ssss+=i
for i in range(len(ttt)):
    tttt+=ttt[len(ttt)-i-1]
if ssss<tttt:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
ss=''+join(sorted(ss))
tt=''+join(sorted(tt,reverse=true))
if ss<tt:
    print("Yes")
else:
    print("No")

Fixed submission:
ss=input()
tt=input()
s=[]
t=[]
for i in ss:
    s.append(i)
for i in tt:
    t.append(i)
sss=sorted(s)
ttt=sorted(t)
ssss=""
tttt=""
for i in sss:
    ssss+=i
for i in range(len(ttt)):
    tttt+=ttt[len(ttt)-i-1]
if ssss<tttt:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
st=input().split()
a=[0 for i in range(N)]
M=set([])
for i in range(N):
    a[i]=int(st[i])
    M.add(a[i])
Numlist=list(M)
b=[0 for i in range(len(M))]
def search(num):
    for k in range(len(M)):
        if Numlist[k]==num:
            return k
    return -1
for i in range(N):
    b[search(a[i])]+=1
count=0
for i in range(len(M)):
    if Numlist[i]<=b[i]:
        count+=b[i]-Numlist[i]
    else:
        count+=b[i]
print(count)

Fixed submission:
N=int(input())
a=[0 for i in range(N)]
st=input().split()
for i in range(N):
    a[i]=int(st[i])
aa=sorted(a)
count=0
nowp=aa[0]
aa.append(10**9+1)
nowcount=1
for i in range(1,N+1):
    if aa[i-1]==aa[i]:
        nowcount+=1
    else:
        nowp=aa[i]
        if nowcount<aa[i-1]:
            count+=nowcount
        else:
            count+=nowcount-aa[i-1]
        nowcount=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
st=input().split()
N=int(st[0]);K=int(st[1])
S=set([])
st=input().split()
P=[0]*(N+1)
for i in range(N):
    k=int(st[i])
    S.add(k)
    P[k]+=1
out=0
Q=list(sorted(np.array(P)))
while(True):
    if Q[0]==0:
        Q.remove(0)
    else:
        break
for i in range(max([len(S)-K,0])):
    out+=Q[i]
print(out)




Fixed submission:
import numpy as np
st=input().split()
N=int(st[0]);K=int(st[1])
S=set([])
st=input().split()
P=[0]*(N+1)
Q=[0]*(N+1)
for i in range(N):
    k=int(st[i])
    S.add(k)
    P[k-1]+=1
    Q[P[k-1]-1]-=1
    Q[P[k-1]]+=1
out=0
change=0
count=0
if len(S)<=K:
    print(0)
else:
    for i in range(1,N+1):
        flag=1
        for j in range(Q[i]):
            change+=i
            count+=1
            if count==max([len(S)-K,0]):
                flag=0
                break
        if flag==0:
            break
    print(change)
Buggy python submission (verdict: Runtime Error):
st=input().split()
N=int(st[0]);A=int(st[1]);B=int(st[2])
print min([N*A,B])

Fixed submission:
s=input().split()
N=int(s[0]);A=int(s[1]);B=int(s[2])
if (N*A<=B):
    print("{0}".format(N*A))
else:
    print("{0}".format(B))

Buggy python submission (verdict: Runtime Error):
st=input().split()
N=int(st[0]);A=int(st[1]);B=int(st[2])
print min(N*A,B)

Fixed submission:
s=input().split()
N=int(s[0]);A=int(s[1]);B=int(s[2])
if (N*A<=B):
    print("{0}".format(N*A))
else:
    print("{0}".format(B))

Buggy python submission (verdict: Runtime Error):
st=input().split()
N=int(st[0]);A=int(st[1]);B=int(st[2])
print("{0}".format(min(A*N,B))

Fixed submission:
s=input().split()
N=int(s[0]);A=int(s[1]);B=int(s[2])
if (N*A<=B):
    print("{0}".format(N*A))
else:
    print("{0}".format(B))

Buggy python submission (verdict: Runtime Error):
st=input().split()
N=int(st[0]);A=int(st[1]);B=int(st[2]);
print("{0}".format(min(A*N,B))

Fixed submission:
s=input().split()
N=int(s[0]);A=int(s[1]);B=int(s[2])
if (N*A<=B):
    print("{0}".format(N*A))
else:
    print("{0}".format(B))
Buggy python submission (verdict: Runtime Error):
st=input().split()
H=int(st[0]);W=int(st[1])
c=[[0 for i in range(10)] for i in range(10)]
A=[[0 for i in range(W)]for i in range(H)]
for i in range(10):
    st=input().split()
    for j in range(10):
        c[i][j]=int(st[j])
for i in range(H):
    st=input().split()
    for j in range(W):
        A[i][j]=int(st[j])
import math
def Dijkstra(s):
    d=[math.inf]*10
    d[s]=0
    Q=list(range(10))
    V=list(range(10))
    while(len(Q)>0):
        u=Q[0]
        for i in Q:
            if d[i]<d[u]:
                u=i
        Q.remove(u)
        Vtmp=list(range(10))
        Vtmp.remove(u)
        for v in Vtmp:
            if (d[v]>d[u]+c[u][v]):
                d[v]=d[u]+c[u][v]
    return d[1]
result=0
DD=[0]*10
for i in range(10):
    DD[i]=Dijkstra(i)
for i in range(H):
    for j in range(W):
        if A[i][j]!=-1:
            result+=DD[A[i][j]]
print(result)


Fixed submission:
N=input()
if N[0]==N[1] and N[1]==N[2]:
  print("Yes")
elif N[1]==N[2] and N[2]==N[3]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
st=input().split()
H=int(st[0]);W=int(st[1])
c=[[0 for i in range(10)] for i in range(10)]
A=[[0 for i in range(W)]for i in range(H)]
for i in range(10):
    st=input().split()
    for j in range(10):
        c[i][j]=int(st[j])
for i in range(H):
    st=input().split()
    for j in range(W):
        A[i][j]=int(st[j])
import math
def Dijkstra(s):
    d=[math.inf]*10
    d[s]=0
    Q=set(range(10))
    V=set(range(10))
    while(len(Q)>0):
        u=list(Q)[0]
        for i in Q:
            if d[i]<d[u]:
                u=i
        Q-={u}
        for v in V-{u}:
            if (d[v]>d[u]+c[u][v]):
                d[v]=d[u]+c[u][v]
    return d[1]
result=0
DD=[0]*10
for i in range(10):
    DD[i]=Dijkstra(i)
for i in range(H):
    for j in range(W):
        if A[i][j]!=-1:
            result+=DD[A[i][j]]
print(result)


Fixed submission:
N=input()
if N[0]==N[1] and N[1]==N[2]:
  print("Yes")
elif N[1]==N[2] and N[2]==N[3]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds() < 1.8):
    for x in range(100):
	    P = KSum(K*j)
    	if m > P:
        	m = P
    	j += 1
print(m)


Fixed submission:
S=input()
T=input()
if S==T[::-1]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds() < 1.8):
    for x in range(100):
	    P = KSum(K*j)
    	if m > P:
        	m = P
    	j += 1
print(m)


Fixed submission:
from collections import deque
K=int(input())
reached=[0 for i in range(K)]
reached[1]=1
dist=[0 for i in range(K)]
q=deque([])
q.append(1)
while(len(q)>0):
    r=q.popleft()
    v=(r+1)%K
    reached[r]=1
    if (reached[v]==0):
        q.append(v)
        dist[v]=dist[r]+1
    v=(r*10)%K
    if (reached[v]==0):
        q.appendleft(v)
        dist[v]=dist[r]
    if (reached[0]==1):
        break
print(dist[0]+1)

Buggy python submission (verdict: Runtime Error):
from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds() < 1.8):
  	for x in range(100):
	    P = KSum(K*j)
    	if m > P:
        	m = P
    	j += 1
print(m)


Fixed submission:
from collections import deque
K=int(input())
reached=[0 for i in range(K)]
reached[1]=1
dist=[0 for i in range(K)]
q=deque([])
q.append(1)
while(len(q)>0):
    r=q.popleft()
    v=(r+1)%K
    reached[r]=1
    if (reached[v]==0):
        q.append(v)
        dist[v]=dist[r]+1
    v=(r*10)%K
    if (reached[v]==0):
        q.appendleft(v)
        dist[v]=dist[r]
    if (reached[0]==1):
        break
print(dist[0]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds()<1.9):
    P = KSum(K*j)
    if m > P:
        m = P
    j += 1

print(m)


Fixed submission:
from collections import deque
K=int(input())
reached=[0 for i in range(K)]
reached[1]=1
dist=[0 for i in range(K)]
q=deque([])
q.append(1)
while(len(q)>0):
    r=q.popleft()
    v=(r+1)%K
    reached[r]=1
    if (reached[v]==0):
        q.append(v)
        dist[v]=dist[r]+1
    v=(r*10)%K
    if (reached[v]==0):
        q.appendleft(v)
        dist[v]=dist[r]
    if (reached[0]==1):
        break
print(dist[0]+1)
Buggy python submission (verdict: Runtime Error):
Sd = input()
T = input()
if len(Sd) < len(T):
    print("UNRESTORABLE")
else:
    D = []
    for i in range(len(Sd) - len(T) + 1):
        flag = 1
        S = Sd
        for j in range(len(T)):
            if Sd[i+j] == "?" or Sd[i+j] == T[j]:
                S = S[:i+j]+T[j]+S[i+j+1:]
            else:
                flag = 0
        if flag == 1:
            D.append(S.replace("?", "a"))
D.sort()
if len(D) == 0:
    print("UNRESTORABLE")
else:
    print(D[0])


Fixed submission:
Sd = input()
T = input()
if len(Sd) < len(T):
    print("UNRESTORABLE")
else:
    D = []
    for i in range(len(Sd) - len(T) + 1):
        flag = 1
        S = Sd
        for j in range(len(T)):
            if Sd[i+j] == "?" or Sd[i+j] == T[j]:
                S = S[:i+j]+T[j]+S[i+j+1:]
            else:
                flag = 0
        if flag == 1:
            D.append(S.replace("?", "a"))
    D.sort()
    if len(D) == 0:
        print("UNRESTORABLE")
    else:
        print(D[0])
Buggy python submission (verdict: Time Limit Exceeded):
def velsup(a,b,c,x):
    if a<=x<=b:
        return c
    elif x<a:
        return (a-x)+c
    else:
        return (x-b)+c

N=int(input())
t=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=t[i]+S[i]
TT=S[N]
vt=[0 for i in range(2*TT+1)]
for tt in range(TT*2+1):
    ta=tt/2
    va=min(velsup(-1,0,0,ta),velsup(TT,TT+1,0,ta))
    for i in range(N):
        va=min(va,velsup(S[i],S[i+1],v[i],ta))
    vt[tt]=va
ans=0
for i in range(2*TT):
    ans+=(vt[i]+vt[i+1])*0.25
print(ans)

Fixed submission:
def velsup(a,b,c,x):
    if a<=x<=b:
        return c
    elif x<a:
        return (a-x)+c
    else:
        return (x-b)+c

N=int(input())
t=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=t[i]+S[i]
TT=S[N]
vt=[0 for i in range(2*TT+1)]
for tt in range(TT*2+1):
    ta=tt/2
    va=min(velsup(-1,0,0,ta),velsup(TT,TT+1,0,ta))
    for i in range(N):
        va=min(va,velsup(S[i],S[i+1],v[i],ta))
    vt[tt]=va
ans=0
for i in range(2*TT):
    ans+=(vt[i]+vt[i+1])*0.25
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
		if B<=0:
			continue
		if A%B==0:
			print(h,n,A//B)
			exit()


Fixed submission:
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
		if B<=0:
			continue
		if A%B==0:
			print(h,n,A//B)
			exit()

Buggy python submission (verdict: Runtime Error):
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
        if B<0:
            continue
		if A%B==0:
			print(h,n,A//B)
			exit()


Fixed submission:
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
		if B<=0:
			continue
		if A%B==0:
			print(h,n,A//B)
			exit()

Buggy python submission (verdict: Runtime Error):
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
		if A%B==0 and B>0:
			print(h,n,A//B)
			exit()


Fixed submission:
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		A=N*h*n
		B=4*h*n-N*n-N*h
		if B<=0:
			continue
		if A%B==0:
			print(h,n,A//B)
			exit()