Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k=int(input())
if k==1:
  print(1)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")

Fixed submission:
k=int(input())
if k==1:
  print(1)
  exit()
if k==10:
  print(10)
  exit()
if k==36:
  print(100)
  exit()
if k==111:
  print(1000)
  exit()
if k==328:
  print(10000)
  exit()
if k==957:
  print(100000)
  exit()
if k==2783:
  print(1000000)
  exit()
if k==8090:
  print(10000000)
  exit()
if k==23528:
  print(100000000)
  exit()
if k==68469:
  print(1000000000)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(input())
s=deque(s)
q=int(input())
a=0
for i in range(q):
  A=list(input().split())
  if A[0]=="1":
    a=(a+1)%2
  else:
    if A[1]=="1":
      if a==0:
        s.appendleft(A[2])
      else:
        s.append(A[2])
    else:
      if a==0:
        s.append(A[2])
      else:
        s.appendleft(A[2])
if a==1:
  S=[]
  c=len(s)
  for i in range(c):
    S.append(s[c-i-1])
else:
  S=s
for i in range(len(S)):
  print(S[i],end="")
print()

Fixed submission:
from collections import deque
s=list(input())
s=deque(s)
q=int(input())
a=0
for i in range(q):
  A=list(input().split())
  if A[0]=="1":
    a=(a+1)%2
  else:
    if A[1]=="1":
      if a==0:
        s.appendleft(A[2])
      else:
        s.append(A[2])
    else:
      if a==0:
        s.append(A[2])
      else:
        s.appendleft(A[2])
if a==1:
  S=[]
  c=len(s)
  for i in range(c):
    S.append(s[-1])
    s.pop()
else:
  S=s
for i in range(len(S)):
  print(S[i],end="")
print()
Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
s=input()
if p==2:
  ans=0
  for i in range(n):
    if int(s[i])%2==0:
      ans=ans+i+1
  print(ans)
elif p==5:
  ans=0
  for i in range(n):
    if int(s[i])%5==0:
      ans=ans+i+1
  print(ans)
else:
  G=[[0]*p for i in range(2)]
  G[0]=[i for i in range(p)]
  for i in range(p):
    G[1][i]=G[0][i]*10%p
  R=[[0]*p for i in range(3)]
  a=0
  b=1
  c=2
  for i in range(n):
    x=int(s[i])
    for j in range(p):
      y=(G[1][j]+x)%p
      R[a][y]=R[c][j]+R[c][y]-R[b][j]
    R[a][x%p]+=1
    a=b
    b=c
    c=(c+1)%3
  print(R[c][0])

Fixed submission:
n,p=map(int,input().split())
s=input()
if p==2:
  ans=0
  for i in range(n):
    if int(s[i])%2==0:
      ans=ans+i+1
  print(ans)
elif p==5:
  ans=0
  for i in range(n):
    if int(s[i])%5==0:
      ans=ans+i+1
  print(ans)
else:
  R=[0]*p
  x=0
  y=1
  for i in range(n-1,-1,-1):
    a=int(s[i])
    b=(a*y+x)%p
    R[b]=R[b]+1
    y=y*10%p
    x=b
  ans=R[0]*(R[0]+1)//2
  for i in range(1,p):
    ans=ans+(R[i]*(R[i]-1))//2
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
A=[[0]*3 for i in range(3)]
for i in range(3):
  A[i]=list(map(int,input().split()))
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k]==b:
        A[j][k]=10**10
for i in range(3):
  if sum(A[i])==3*10**10:
    print("Yes")
    sys.exit()
a=0
for i in range(3):
  a=a+A[i][0]
if a==3**10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][1]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][2]
if a==3*10**10:
  print("Yes")
  sys.exit()
if A[0][0]+A[1][1]+A[2][2]==3*10**10 or A[0][2]+A[1][1]+A[2][0]==3*10**10:
  print("Yes")
  sys.exit()
print("No")

Fixed submission:
import sys
A=[[0]*3 for i in range(3)]
for i in range(3):
  A[i]=list(map(int,input().split()))
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k]==b:
        A[j][k]=10**10
for i in range(3):
  if sum(A[i])==3*10**10:
    print("Yes")
    sys.exit()
a=0
for i in range(3):
  a=a+A[i][0]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][1]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][2]
if a==3*10**10:
  print("Yes")
  sys.exit()
if A[0][0]+A[1][1]+A[2][2]==3*10**10 or A[0][2]+A[1][1]+A[2][0]==3*10**10:
  print("Yes")
  sys.exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
if n==2:
  print(((x[0]-x[1])**2+(y[0]-y[1])**2)**(1/2)/2)
else:
  ans=10**5
  A=[0]*3
  B=[0]*3
  for i in range(n-2):
    for j in range(i+1,n-1):
      A[0]=x[j]-x[i]
      A[1]=y[j]-y[i]
      A[2]=A[0]*(x[i]+x[j])/2+A[1]*(y[i]+y[j])/2
      for k in range(j+1,n):
        B[0]=x[k]-x[i]
        B[1]=y[k]-y[i]
        B[2]=B[0]*(x[i]+x[k])/2+B[1]*(y[i]+y[k])/2
        if A[0]*B[1]==A[1]*B[0] and A[0]*B[1]!=0:#三点が同一直線状に存在1
          r=((max(x[i],x[j],x[k])-min(x[i],x[j],x[k]))**2+(max(y[i],y[j],y[k])-min(y[i],y[j],y[k]))**2)**(1/2)/2
          xc=(max(x[i],x[j],x[k])+min(x[i],x[j],x[k]))/2
          yc=(max(y[i],y[j],y[k])+min(y[i],y[j],y[k]))/2
        elif A[0]==B[0]==0:#2
          r=(max(y[i],y[j],y[k])-min(y[i],y[j],y[k]))/2
          xc=x[i]
          yc=(max(y[i],y[j],y[k])+min(y[i],y[j],y[k]))/2
        elif A[1]==B[1]==0:#3
          r=(max(x[i],x[j],x[k])-min(x[i],x[j],x[k]))/2
          yc=y[i]
          xc=(max(x[i],x[j],x[k])+min(x[i],x[j],x[k]))/2
        else:
          xc=(A[2]*B[1]-A[1]*B[2])/(A[0]*B[1]-A[1]*B[0])
          yc=(A[0]*B[2]-A[2]*B[0])/(A[0]*B[1]-A[1]*B[0])
          r=((x[i]-xc)**2+(y[i]-yc)**2)**(1/2)
        aa=0
        r=min(r*1.000000999,r+0.000000999)
        for l in range(n):
          if ((x[l]-xc)**2+(y[l]-yc)**2)**(1/2)>r:
            aa=1
        if aa==0:
          if r<ans:
            ans=r
  print(ans)

Fixed submission:
print(chr(ord(input())+1))
Buggy python submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
ans=0
for sx in range(1,h+1):
  for sy in range(1,w+1):
    B=[[0]*(w+2) for i in range(h+2)]
    for i in range(h+2):
      for j in range(w+2):
        if G[i][j]=="#":
          B[i][j]=1
    INF=10**4
    A=[[INF]*(w+2) for i in range(h+2)]
    C=[-1,1,0,0]
    D=[0,0,-1,1]
    A[sx][sy]=0
    E=deque([sx,sy])
    while len(E)>0:
      x=E[0]
      E.popleft()
      y=E[0]
      E.popleft()
      for i in range(4):
        if B[x+C[i]][y+D[i]]==0:
          A[x+C[i]][y+D[i]]=A[x][y]+1
          a=A[x+C[i]][y+D[i]]
          B[x+C[i]][y+D[i]]=1
          E.append(x+C[i])
          E.append(y+D[i])
    if ans<a:
      ans=a
print(ans)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
ans=0
for sx in range(1,h+1):
  for sy in range(1,w+1):
    if G[sx][sy]==".":
      B=[[0]*(w+2) for i in range(h+2)]
      for i in range(h+2):
        for j in range(w+2):
          if G[i][j]=="#":
            B[i][j]=1
      INF=10**4
      A=[[INF]*(w+2) for i in range(h+2)]
      C=[-1,1,0,0]
      D=[0,0,-1,1]
      A[sx][sy]=0
      E=deque([sx,sy])
      while len(E)>0:
        x=E[0]
        E.popleft()
        y=E[0]
        E.popleft()
        B[x][y]=1
        for i in range(4):
          if B[x+C[i]][y+D[i]]==0:
            A[x+C[i]][y+D[i]]=A[x][y]+1
            a=A[x+C[i]][y+D[i]]
            B[x+C[i]][y+D[i]]=1
            E.append(x+C[i])
            E.append(y+D[i])
      if ans<a:
        ans=a
    else:
      continue
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=[[]for i in range(n)]
A[0].append(1)
for i in range(2,n+1):
  for j in range(i-1):
    A[i-1].append(A[i-2][j]*i)
  A[i-1].append(A[i-1][-1]+A[i-2][0])
X=list(map(int,input().split()))
Y=[X[1]-X[0]]
for i in range(2,n):
  Y.append(X[i]-X[i-1])
ans=0
for i in range(n-1):
  ans=(ans+A[n-2][i]*Y[i])%(10**9+7)
print(ans)


Fixed submission:
n=int(input())
A=[[0]*2 for i in range(n)]
for i in range(n):
  A[i][0],A[i][1]=input().split()
  A[i][1]=int(A[i][1])
x=input()
for i in range(n):
  if A[i][0]==x:
    break
ans=0
for j in range(i+1,n):
  ans=ans+A[j][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list([28,40,35]))

Fixed submission:
import copy
import fractions
import sys
n,m=map(int,input().split())
A=list(map(int,input().split()))
a=copy.copy(A[0])
c=0
while a%2==0:
  a=a//2
  c=c+1
d=2**c
for i in range(n):
  if A[i]//d!=float(A[i])/d or A[i]//(2*d)==float(A[i])/(2*d):
    print(0)
    sys.exit()
B=[]
for i in range(n):
  B.append(A[i]//2)
b=1
for i in range(n):
  b=b*B[i]//fractions.gcd(b,B[i])
  if b>m:
    print(0)
    sys.exit()
if b>m:
  print(0)
else:
  print(1+(m-b)//(2*b))
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[[0]*w for i in range(h)]
for i in range(h):
  A[i]=list(map(int,input().split()))
B=[[0]*w for i in range(h)]
for i in range(h):
  B[i]=list(map(int,input().split()))
C=[[0]* w for i in range(h)]
for i in range(h):
  for j in range(w):
    C[i][j]=abs(A[i][j]-B[i][j])
dp=[[[0]*6401 for j in range(h+1)] for i in range(h+w+1)]
dp[0][0][C[0][0]]=1
for i in range(h+w):
  for j in range(max(0,i-w),min(i,h)+1):
    for k in range(6401):
      if dp[i][j][k]==1:
        if i-j<w-1:
          if k+C[j][i-j]<6400:
            dp[i+1][j][k+C[j][i-j+1]]=1
          dp[i+1][j][abs(k-C[j][i-j+1])]=1
        if j<h-1:
          if k+C[j+1][i-j]<6400:
            dp[i+1][j+1][k+C[j+1][i-j]]=1
          dp[i+1][j+1][abs(k-C[j+1][i-j])]=1
for k in range(6400):
  if dp[h+w-2][h-1][k]==1:
    print(k)
    exit()

Fixed submission:
h,w=map(int,input().split())
A=[[0]*w for i in range(h)]
for i in range(h):
  A[i]=list(map(int,input().split()))
B=[[0]*w for i in range(h)]
for i in range(h):
  B[i]=list(map(int,input().split()))
C=[[0]* w for i in range(h)]
for i in range(h):
  for j in range(w):
    C[i][j]=abs(A[i][j]-B[i][j])
dp=[[[0]*6401 for j in range(h+1)] for i in range(h+w+1)]
dp[0][0][C[0][0]]=1
for i in range(h+w):
  for j in range(max(0,i-w),min(i,h)+1):
    for k in range(6401):
      if dp[i][j][k]==1:
        if i-j<w-1:
          if k+C[j][i-j+1]<6400:
            dp[i+1][j][k+C[j][i-j+1]]=1
          dp[i+1][j][abs(k-C[j][i-j+1])]=1
        if j<h-1:
          if k+C[j+1][i-j]<6400:
            dp[i+1][j+1][k+C[j+1][i-j]]=1
          dp[i+1][j+1][abs(k-C[j+1][i-j])]=1
for k in range(6400):
  if dp[h+w-2][h-1][k]==1:
    print(k)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=input()
a=0
for i in range(n+1):
  if s[i]=="1":
    a=a+1
    if a==m:
      print(-1)
      break
  else:
    a=0
if a==0:
  b=[]
  d=n
  while d>0:
    if d<=m:
      b.insert(0,d)
      d=0
    else:
      i=m
      while i>0:
        if s[d-i]=="1":
          i=i-1
        else:
          b.insert(0,str(i))
          d=d-i
          break
  for i in range(len(b)):
    print(b[i],end=" ")

Fixed submission:
from collections import deque
n,m=map(int,input().split())
s=deque(input())
a=0
for i in range(n+1):
  if s[i]=="1":
    a=a+1
    if a==m:
      print(-1)
      break
  else:
    a=0
if a==0:
  b=deque([])
  d=n
  while d>0:
    if d<=m:
      b.appendleft(d)
      d=0
    else:
      i=m
      while i>0:
        if s[d-i]=="1":
          i=i-1
        else:
          b.appendleft(i)
          d=d-i
          for j in range(i):
            s.pop()
          break
  for i in range(len(b)):
    print(b[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=input()
a=[]
b=len(s)
c=0
d=n
e=0
while d>0:
  if d<=m:
    a.insert(0,d)
    d=0
  else:
    i=m
    while i>0:
      if s[d-i]=="1":
        i=i-1
      else:
        a.insert(0,i)
        d=d-i
        i=-1
    if i==0:
        e=1
        break
    else:
      continue
    break
if e==1:
  print(-1)
else:
  for i in range(len(a)):
    print(a[i],end=" ")

Fixed submission:
from collections import deque
n,m=map(int,input().split())
s=deque(input())
a=0
for i in range(n+1):
  if s[i]=="1":
    a=a+1
    if a==m:
      print(-1)
      break
  else:
    a=0
if a==0:
  b=deque([])
  d=n
  while d>0:
    if d<=m:
      b.appendleft(d)
      d=0
    else:
      i=m
      while i>0:
        if s[d-i]=="1":
          i=i-1
        else:
          b.appendleft(i)
          d=d-i
          for j in range(i):
            s.pop()
          break
  for i in range(len(b)):
    print(b[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m=map(int,input().split())
s=input()
a=[]
b=len(s)
c=0
d=n
e=0
while d>0:
  if d<=m:
    a.insert(0,d)
    d=0
  else:
    i=m
    while i>0:
      if s[d-i]=="1":
        i=i-1
      else:
        a.insert(0,i)
        d=d-i
        i=-1
    if i==0:
        e=1
        break
    else:
      continue
    break
if e==1:
  print(-1)
else:
  for i in range(len(a)):
    print(a[i],end=" ")

Fixed submission:
from collections import deque
n,m=map(int,input().split())
s=deque(input())
a=0
for i in range(n+1):
  if s[i]=="1":
    a=a+1
    if a==m:
      print(-1)
      break
  else:
    a=0
if a==0:
  b=deque([])
  d=n
  while d>0:
    if d<=m:
      b.appendleft(d)
      d=0
    else:
      i=m
      while i>0:
        if s[d-i]=="1":
          i=i-1
        else:
          b.appendleft(i)
          d=d-i
          for j in range(i):
            s.pop()
          break
  for i in range(len(b)):
    print(b[i],end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)
ng=-1
ok=10**12+10
while ok-ng>1:
  mid=(ok+ng)//2
  a=0
  for i in range(n):
    a=a+max(0,A[i]-mid//F[i])
  if a>k:
    ng=mid
  else:
    ok=mid
print(ok)

Fixed submission:
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)
ng=-1
ok=10**12+10
while ok-ng>1:
  mid=(ok+ng)//2
  a=0
  for i in range(n):
    a=a+max(0,A[i]-mid//F[i])
  if a>k:
    ng=mid
  else:
    ok=mid
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if a[k]>=a[i]+a[j]:
        continue
      b=b+1
print(b)

Fixed submission:
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=a+bisect.bisect_left(l,l[i]+l[j])-j-1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
def W(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n,w,l= map(int,input().split()) #n:頂点数　w:辺の数

d = [[10**14]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
D=W(d)
G=[[10**4]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1
WW=W(G)
for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1)

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

##############################
n,w,l= map(int,input().split()) #n:頂点数　w:辺の数

d = [[10**14]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
D=W(d)
G=[[10**4]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1
WW=W(G)
for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
A=[]
for _ in range(q):
  A.append(input())
i=1
while i<n+1:
  i=str(i)
  x=A.count(i)
  if k>q-x:
    print("Yes")
  else:
    print("No")
  i=int(i)
  i=i+1

Fixed submission:
n,k,q=map(int,input().split())
A=[]
for _ in range(q):
  A.append(int(input())-1)
B=[0]*n
for i in range(q):
  B[A[i]]+=1
for i in range(n):
  if B[i]<=q-k:
    print("No")
  else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
A=[[0]*n for i in range(n)]
for i in range(n-1):
  for j in range(i+1,n):
    if S[i]==S[j]:
      A[i][j]=1
dp=[[0]*(n+1) for i in range(n+1)]#i文字目まで、j文字目までの長さ
for i in range(1,n):
  for j in range(i+1,n+1):
    if A[i-1][j-1]==1:
      if j-i<dp[i-1][j-1]+1:
        dp[i][j]=dp[i-1][j-1]
      else:
        dp[i][j]=dp[i-1][j-1]+1
ans=0
for i in range(n+1):
  for j in range(n+1):
    if dp[i][j]>ans:
      ans=dp[i][j]
print(ans)

Fixed submission:
n=int(input())
S=list(input())
dp=[[0]*(n+1) for i in range(n+1)]#i文字目まで、j文字目までの長さ
for i in range(1,n):
  for j in range(i+1,n+1):
    if S[i-1]==S[j-1]:
      if j-i<dp[i-1][j-1]+1:
        dp[i][j]=dp[i-1][j-1]
      else:
        dp[i][j]=dp[i-1][j-1]+1
ans=0
for i in range(n+1):
  for j in range(n+1):
    if dp[i][j]>ans:
      ans=dp[i][j]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,q=map(int,input().split())
A=[[] for i in range(n)] #繋がっている頂点
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  A[a].append(b)
  A[b].append(a)
B=[0]*n #コスト
for i in range(q):
  p,q=map(int,input().split())
  p=p-1
  B[p]=B[p]+q
#BFSの時間じゃああああ!!!!!!
C=deque([0])
D=[] #visited枠
while len(C)>0:
  c=C[0]
  C.popleft()
  D.append(c)
  for i in range(len(A[c])):
    if A[c][i] not in D:
      C.append(A[c][i])
      B[A[c][i]]+=B[c]
for i in range(n):
  print(B[i],end=" ")
print()

Fixed submission:
n,m=map(int,input().split())
graph=[[]for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  graph[a].append(b)
  graph[b].append(a)
cost=[0]*n
visited=[False]*n
for i in range (m):
  p,x=map(int,input().split())
  p=p-1
  cost[p]=cost[p]+x
from collections import deque
quest=deque([0])
visited[0]=True
while len(quest)!=0:
  a=quest.popleft()
  for i in graph[a]:
    if visited[i]==True:
      continue
    quest.append(i)
    visited[i]=True
    cost[i]=cost[i]+cost[a]
print(*cost)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,q=map(int,input().split())
A=[[] for i in range(n)] #繋がっている頂点
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  A[a].append(b)
  A[b].append(a)
B=[0]*n #コスト
for i in range(q):
  p,q=map(int,input().split())
  p=p-1
  B[p]=B[p]+q
#BFSの時間じゃああああ!!!!!!
C=deque([0])
D=[] #visited枠
while len(C)>0:
  c=C[0]
  C.popleft()
  D.append(c)
  for i in range(len(A[c])):
    if A[c][i] not in D:
      C.append(A[c][i])
      B[A[c][i]]+=B[c]
for i in range(n):
  print(B[i],end=" ")
print()

Fixed submission:
n,m=map(int,input().split())
graph=[[]for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  graph[a].append(b)
  graph[b].append(a)
cost=[0]*n
visited=[False]*n
for i in range (m):
  p,x=map(int,input().split())
  p=p-1
  cost[p]=cost[p]+x
from collections import deque
quest=deque([0])
visited[0]=True
while len(quest)!=0:
  a=quest.popleft()
  for i in graph[a]:
    if visited[i]==True:
      continue
    quest.append(i)
    visited[i]=True
    cost[i]=cost[i]+cost[a]
print(*cost)
Buggy python submission (verdict: Runtime Error):
import bisect
n=int(input())
A=[int(input())]
for i in range(n-1):
  a=int(input())
  b=bisect.bisect_right(A,a,lo=0,hi=len(A))
  if b!=0 and A[b-1]<a:
    A[b-1]=a
  elif A[b-1]==a:
    b=bisect.bisect_right(A,a-1,lo=0,hi=len(A))
    if b!=0:
      A[b-1]=a
    else:
      A.insert(0,a)
  else:
    A.insert(0,a)
print(len(A))


Fixed submission:
r=int(input())
print(3*r*r)