Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

def lcm(a, b):
  return a * b // gcd(a, b)

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return lcm(a[0],llcm(a[1:]))
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
flag = False
for a in A:
  if (a//2)%2 == 1 and (a//2) >=3:
    flag = True
  B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
if not flag:
  ans = max(ans-1,0)
print(ans)


Fixed submission:
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

def lcm(a, b):
  return a * b // gcd(a, b)

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return lcm(a[0],llcm(a[1:]))
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
flag = False
for a in A:
  if (a//2)%2 == 1 and (a//2) >=3:
    flag = True
  B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
if not flag:
  ans = max(ans-1,0)
print(ans)


Fixed submission:
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

def lcm(a, b):
  return a * b // gcd(a, b)

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return llcm(a[0],a[1:])
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
for a in A:
  if (a//2)%2 == 0:
    print(0)
    exit()
  else:
    B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
print(ans)


Fixed submission:
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
#print(A)

hq = [(-A[0]*2,0,0)]
used = [[False for _ in range(N)] for _ in range(N)]
used[0][0] = True
ans = 0
for i in range(M):
  a,p,q = heapq.heappop(hq)
  ans -= a
  if p+1 < N and not used[p+1][q]:
    heapq.heappush(hq, (-A[p+1]-A[q],p+1,q))
    used[p+1][q] = True
  if q+1 < N and not used[p][q+1]:
    heapq.heappush(hq, (-A[p]-A[q+1],p,q+1))
    used[p][q+1] = True
print(ans)

Fixed submission:
import bisect

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
#print(A)

# Aの累積和を求めておく。
csum = [A[0] for _ in range(N+1)]
for i in range(1,N):
  csum[i] = csum[i-1]+A[i]

# M回以上握手できるとなる最小の幸福度を求める。
# r:M回以上握手ができる最小の幸福度。
# l:M回以上握手が出来ない最大の幸福度。
l = 0
r = 10**6
while (l+1 < r):
  m = (l+r)//2
  p = 0 # 幸福度がm以上になる握手の回数
  for a in A:
    q = bisect.bisect_left(A,m-a)
    #print(q,m-a,A)
    p += N-q
  #print(l,m,r,p)
  if p >= M:
    l = m
  else:
    r = m
#print(l,m,r)

# 幸福度がlのときに握手ができる回数を求め、
# それとMとの差

ans = 0
cnt = 0
for a in A:
  q = bisect.bisect_right(A,l-a)
  if q == 0:
    ans += csum[N-1]+a*N
    cnt += N
  elif q < N:
    ans += csum[N-1]-csum[q-1]+a*(N-q)
    cnt += N-q
  #print(a,q,ans,cnt)
ans +=l*(M-cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
#print(A)

hq = [(-A[0]*2,0,0)]
used = [[False for _ in range(N)] for _ in range(N)]
used[0][0] = True
ans = 0
for i in range(M):
  a,p,q = heapq.heappop(hq)
  ans -= a
  if p+1 < N and not used[p+1][q]:
    heapq.heappush(hq, (-A[p+1]-A[q],p+1,q))
    used[p+1][q] = True
  if q+1 < N and not used[p][q+1]:
    heapq.heappush(hq, (-A[p]-A[q+1],p,q+1))
    used[p][q+1] = True
print(ans)

Fixed submission:
import bisect

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
#print(A)

# Aの累積和を求めておく。
csum = [A[0] for _ in range(N+1)]
for i in range(1,N):
  csum[i] = csum[i-1]+A[i]

# M回以上握手できるとなる最小の幸福度を求める。
# r:M回以上握手ができる最小の幸福度。
# l:M回以上握手が出来ない最大の幸福度。
l = 0
r = 10**6
while (l+1 < r):
  m = (l+r)//2
  p = 0 # 幸福度がm以上になる握手の回数
  for a in A:
    q = bisect.bisect_left(A,m-a)
    #print(q,m-a,A)
    p += N-q
  #print(l,m,r,p)
  if p >= M:
    l = m
  else:
    r = m
#print(l,m,r)

# 幸福度がlのときに握手ができる回数を求め、
# それとMとの差

ans = 0
cnt = 0
for a in A:
  q = bisect.bisect_right(A,l-a)
  if q == 0:
    ans += csum[N-1]+a*N
    cnt += N
  elif q < N:
    ans += csum[N-1]-csum[q-1]+a*(N-q)
    cnt += N-q
  #print(a,q,ans,cnt)
ans +=l*(M-cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)
#print(A)

ans = set()
i = 0
while(A[i] >= A[P-1]):
  ans.add(i)
  i += 1
#print(ans)

csum = [0 for _ in range(N)]
csum[P-1] = A[P-1]
for i in range(P,N):
  csum[i] = csum[i-1]+A[i]

for i in range(P,N):
  if A[i]+M >= (csum[i-1]+((V-P)*M-(N-1-i)*M)+1)//(i-(P-1)):
    ans.add(i)
#print(ans)

print(len(ans)-1)


Fixed submission:
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)

def check(i):
  if i <= P-1:
    return True
  vote = (V-1)*M
  vote -= (N-1-i)*M
  vote -= (P-1)*M
  if vote <= 0:
    return A[i]+M >= A[P-1]
  else:
    for j in range(i-1,P-1,-1):
      if A[j] > A[i]+M:
        return False
      v = min(A[i]+M-A[j],M,vote)
      vote -= v
      if vote <= 0:
        break
    if vote <= 0:
      return A[i]+M >= A[P-1]
    else:
      return A[i]+M >= A[P-1]+vote

ok = -1
ng = N
while(ok+1 < ng):
  md = (ok+ng)//2
  if check(md):
    ok = md
  else:
    ng = md
print(ok+1)

Buggy python submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)
#print(A)

ans = set()
i = 0
while(A[i] >= A[P-1]):
  ans.add(i)
  i += 1
#print(ans)

for i in range(P,N):
  if A[i]+M >= A[P-1]+((V-P+1)*M-(N-1-i)*M)//(i-(P-1)):
    ans.add(i)
#print(ans)

print(len(ans))


Fixed submission:
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)

def check(i):
  if i <= P-1:
    return True
  vote = (V-1)*M
  vote -= (N-1-i)*M
  vote -= (P-1)*M
  if vote <= 0:
    return A[i]+M >= A[P-1]
  else:
    for j in range(i-1,P-1,-1):
      if A[j] > A[i]+M:
        return False
      v = min(A[i]+M-A[j],M,vote)
      vote -= v
      if vote <= 0:
        break
    if vote <= 0:
      return A[i]+M >= A[P-1]
    else:
      return A[i]+M >= A[P-1]+vote

ok = -1
ng = N
while(ok+1 < ng):
  md = (ok+ng)//2
  if check(md):
    ok = md
  else:
    ng = md
print(ok+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)

N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
mx = 0
for du,dv in zip(DU,DV):
  if du < dv:
    mx = max(dv,mx)
print(mx-1)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
mx = 0
for du,dv in zip(DU,DV):
  if du < dv:
    mx = max(dv,mx)
print(mx-1)

Buggy python submission (verdict: Runtime Error):
N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
mx = 0
for du,dv in zip(DU,DV):
  if du < dv:
    mx = max(dv,mx)
print(mx-1)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
mx = 0
for du,dv in zip(DU,DV):
  if du < dv:
    mx = max(dv,mx)
print(mx-1)

Buggy python submission (verdict: Runtime Error):
N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
DX = []
for du,dv in zip(DU,DV):
  DX.append(dv-du)
#print(DX)
#print(max(max(DX)-1,0))
mx = max(DX)
#print(DX.index(mx))
if DU[DX.index(mx)]%2 == 1:
  print(max(mx,0))
else:
  print(max(mx-1,0))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

N,u,v = map(int,input().split())
u -= 1
v -= 1
E = [set() for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].add(b)
  E[b].add(a)

DU = [-1 for _ in range(N)]  
DV = [-1 for _ in range(N)]
def dfs(p,c,D):
  D[p] = c
  for q in E[p]:
    if D[q] == -1:
      dfs(q,c+1,D)
dfs(u,0,DU)
dfs(v,0,DV)
#print(DU)
#print(DV)
mx = 0
for du,dv in zip(DU,DV):
  if du < dv:
    mx = max(dv,mx)
print(mx-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007

C = [3] + [0 for i in range(N)]

ans = 1
for a in A:
  ans *= C[a]
  ans %= MOD
  C[a] -= 1
  C[a+1] += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007

C = [3] + [0 for i in range(N)]

ans = 1
for a in A:
  ans *= C[a]
  ans %= MOD
  C[a] -= 1
  C[a+1] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# F - Sugoroku
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
s = input()

r = []
mnr = [m for _ in range(n+1)]
mnl = n+1
def dfs(x,c):
  global mnr,mnl
  #print(x,c)
  if x == n:
    #print(r)
    if len(r) < mnl or (len(r) == mnl and r < mnr):
      mnr = r[:]
      mnl = len(r)
    return True
  if c >= mnl or x > n or s[x] == '1':
    return False
  for i in range(m,0,-1):
    r.append(i)
    dfs(x+i,c+1)
    r.pop()
dfs(0,0)
if mnl < n+1:
  print(*mnr)
else:
  print(-1)

Fixed submission:
# F - Sugoroku
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
s = input()

# r:sを後ろから見ていって、最小何手でゴールするかを求める。
INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
  while(idx-i > m or r[idx] == INF):
    idx -= 1
  if idx <= i:
    print(-1)
    exit()
  if s[i] == '0':
    r[i] = r[idx]+1
    p = r[i]
#print(r)

# rを先頭から見ていき、rの数字が変わる直前まで進むようにすれば
# 最短で辞書順最小なルートが求まる。
ans = []
c = 0
for i in range(n+1):
  if r[i] != INF and r[i] != p:
    p = r[i]
    ans.append(c)
    c = 1
  else:
    c += 1
print(*ans)

# mnr = [m for _ in range(n+1)]
# mnl = n+1
# def dfs(x,c):
#   global mnr,mnl
#   #print(x,c)
#   if x == n:
#     #print(r)
#     if len(r) < mnl or (len(r) == mnl and r < mnr):
#       mnr = r[:]
#       mnl = len(r)
#     return True
#   if c >= mnl or x > n or s[x] == '1':
#     return False
#   for i in range(m,0,-1):
#     r.append(i)
#     dfs(x+i,c+1)
#     r.pop()
# dfs(0,0)
# if mnl < n+1:
#   print(*mnr)
# else:
#   print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())

def ask1(n):
  s = ['?'] + [i for i in range(n,n+N)]
  print(*s)
  return input()

def ask2(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  else:
    s = ['?'] + [a] + [i for i in range(l,r+1)]
  print(*s)
  return input()

def ask3(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  elif l < 1:
    s = ['?'] + [a] + [i for i in range(N+2,N*2+1)]
  elif r > N*2:
    s = ['?'] + [a] + [i for i in range(1,N)]
  else:
    s = ['?'] + [a] + [i for i in range(1,l+1)] + [i for i in range(r,N*2+1)]
  print(*s)
  return input()

#print(ask1(10))
#print(ask2(1,4,7))
#print(ask3(7,4,11))
#exit()

ans = ['' for _ in range(N*2)]

a = ask1(1)
if a == 'Red':
  LC = 'Red'
else:
  LC = 'Blue'

l = 1
r = N+1
while(l+1 == r):
  m = (l+r)//2
  a = ask1(m)
  if a == LC:
    l = m
  else:
    r = m

sl = r
sr = l+N-1
for i in range(1,N*2+1):
  if sl <= i <= sr:
    a = ask3(i,sl-2,sr+2)
  else:
    a = ask2(i,sl,sr)
  if a == 'Red':
    ans[i-1] = 'R'
  else:
    ans[i-1] = 'B'
  
print('! '+''.join(ans))

Fixed submission:
N = int(input())

def ask1(n):
  s = ['?'] + [i for i in range(n,n+N)]
  print(*s)
  return input()

def ask2(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  else:
    s = ['?'] + [a] + [i for i in range(l,r+1)]
  print(*s)
  return input()

def ask3(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  elif l < 1:
    s = ['?'] + [a] + [i for i in range(N+2,N*2+1)]
  elif r > N*2:
    s = ['?'] + [a] + [i for i in range(1,N)]
  else:
    s = ['?'] + [a] + [i for i in range(1,l+1)] + [i for i in range(r,N*2+1)]
  print(*s)
  return input()

#print(ask1(10))
#print(ask2(1,4,7))
#print(ask3(7,4,11))
#exit()

ans = ['' for _ in range(N*2)]

a = ask1(1)
if a == 'Red':
  LC = 'Red'
else:
  LC = 'Blue'

l = 1
r = N+1
while(l+1 < r):
  m = (l+r)//2
  a = ask1(m)
  if a == LC:
    l = m
  else:
    r = m

sl = r
sr = l+N-1
for i in range(1,N*2+1):
  if sl <= i <= sr:
    a = ask3(i,sl-2,sr+2)
  else:
    a = ask2(i,sl,sr)
  if a == 'Red':
    ans[i-1] = 'R'
  else:
    ans[i-1] = 'B'
  
print('! '+''.join(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = sorted(list(map(int,input().split())))
MOD = 998244353

ans = 1
count = {}
for i in range(N):
  if i < D[i] or (i > 0 and D[i] == 0):
    print(0)
    exit()
  else:
    if D[i] in count:
      count[D[i]] += 1
    else:
      count[D[i]] = 1
    if D[i] > 0:
      ans *= count[D[i]-1]
      ans %= MOD
print(ans)

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

if D[0] != 0:
  print(0)
  exit()

D.sort()
ans = 1
count = {}
for i in range(N):
  if i > 0:
    if D[i]-1 in count:
      ans *= count[D[i]-1]
      ans %= MOD
    else:
      print(0)
      exit()
  if D[i] in count:
    count[D[i]] += 1
  else:
    count[D[i]] = 1
print(ans)

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

ans = 1
count = {}
for i in range(N):
  if i < D[i] or (i > 0 and D[i] == 0):
    print(0)
    exit()
  else:
    if D[i] in count:
      count[D[i]] += 1
    else:
      count[D[i]] = 1
    if D[i] > 0:
      ans *= count[D[i]-1]
print(ans)

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

if D[0] != 0:
  print(0)
  exit()

D.sort()
ans = 1
count = {}
for i in range(N):
  if i > 0:
    if D[i]-1 in count:
      ans *= count[D[i]-1]
      ans %= MOD
    else:
      print(0)
      exit()
  if D[i] in count:
    count[D[i]] += 1
  else:
    count[D[i]] = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import sys
  input = sys.stdin.readline

  N = int(input())
  S = input()

  ans = 0
  for i in range(N-1):
    for j in range(i+1,N):
      l = 0
      while(i+l < j and j+l < N and S[i+l] == S[j+l]):
        l += 1
      ans = max(l,ans)
  print(ans)

if __name__ == '__main__':
  main()

Fixed submission:
def z_algo(S):
  N = len(S)
  A = [0]*N
  i = 1; j = 0
  A[0] = l = len(S)
  while i < l:
    while i+j < l and S[j] == S[i+j]:
      j += 1
    if not j:
      i += 1
      continue
    A[i] = j
    k = 1
    while l-i > k < j - A[k]:
      A[i+k] = A[k]
      k += 1
    i += k; j -= k
  return A

N = int(input())
S = input()

ans = 0
for i in range(N):
  SS = S[i:]
  Z = z_algo(SS)
  #print(Z)
  for j in range(1,len(SS)):
    if Z[j] > j:
      l = j
    else:
      l = Z[j]
    ans = max(l,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    l = 0
    while(i+l < j and j+l < N and S[i+l] == S[j+l]):
      l += 1
    ans = max(l,ans)
print(ans)

Fixed submission:
def z_algo(S):
  N = len(S)
  A = [0]*N
  i = 1; j = 0
  A[0] = l = len(S)
  while i < l:
    while i+j < l and S[j] == S[i+j]:
      j += 1
    if not j:
      i += 1
      continue
    A[i] = j
    k = 1
    while l-i > k < j - A[k]:
      A[i+k] = A[k]
      k += 1
    i += k; j -= k
  return A

N = int(input())
S = input()

ans = 0
for i in range(N):
  SS = S[i:]
  Z = z_algo(SS)
  #print(Z)
  for j in range(1,len(SS)):
    if Z[j] > j:
      l = j
    else:
      l = Z[j]
    ans = max(l,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
ans = 1
while (B > 0):
  if ans == 1:
    B -= A
  else
    B -= A -1
  ans += 1
print(ans)

Fixed submission:
A,B = map(int,input().split())
if B == 1:
  print(0)
  exit()
ans = 0
while (B > 0):
  if ans == 0:
    B -= A
  else:
    B -= A -1
  ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
AB = []
for i in range(N-1):
  AB.append(list(map(int, input().split())))
P = []
for i in range(Q):
  P.append(list(map(int, input().split())))

Part = [[i] for i in range(N+1)]
tmp = {1}
while (tmp):
  tmp2 = set()
  for i in tmp:
    for j in range(len(AB)):
      if i == AB[j][0]:
        for k in range(1,N+1):
          if i in Part[k]:
            Part[k].append(AB[j][1])
        tmp2.add(AB[j][1])
  tmp = tmp2

Counter = [0] * (N+1)
for i in range(len(P)):
  for j in Part[P[i][0]]:
    Counter[j] += P[i][1]
print(*[Counter[i] for i in range(1,N+1)])  


Fixed submission:
N,Q = map(int, input().split())
Edge = [set() for _ in range(N+1)]
for i in range(N-1):
  e1,e2 = map(int, input().split())
  Edge[e1].add(e2)
  Edge[e2].add(e1)
Counter = [0] * (N+1)
for i in range(Q):
  p,x = map(int, input().split())
  Counter[p] += x

#print(Edge)
  
Visited = [False] * (N+1)
stack = {1}
while (stack):
  stack2 = set()
  for i in range(len(stack)):
    e1 = stack.pop()
    for e2 in Edge[e1]:
      if not Visited[e2]:
        Counter[e2] += Counter[e1]
        stack2.add(e2)
    Visited[e1] = True
  stack = stack2
  #print(Visited)

print(*[Counter[i] for i in range(1,N+1)])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
dp = [1] * len(S)
if len(S) % 2 == 0:
  c = len(S)
else:
  c = len(S) + 1
for i in range(c):
  nextdp = [0] * len(S)
  for j in range(len(S)):
    if S[j] == 'R':
      nextdp[j+1] += dp[j]
    else:
      nextdp[j-1] += dp[j]
  dp = nextdp
print(' '.join(map(str,dp)))

Fixed submission:
S = input()
L = [0] * len(S)
count = 0
for i in range(len(S)):
  if S[i] == 'L':
    count += 1
    L[i] = count
  else:
    count = 0
count = 0
for i in range(len(S)-1,-1,-1):
  if S[i] == 'R':
    count += 1
    L[i] = count
  else:
    count = 0
ans = [0] * len(S)
for i in range(len(S)):
  if S[i] == 'R':
    if L[i] % 2 == 0:
      ans[i+L[i]] += 1
    else:
      ans[i+L[i]-1] += 1
  else:
    if L[i] % 2 == 0:
      ans[i-L[i]] += 1
    else:
      ans[i-L[i]+1] += 1
print(' '.join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12
for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

Fixed submission:
S = input()
# S = '?'*100000

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12

for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12
for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
    for j in range(13):
      nextdp[j] %= num_mod
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
      nextdp[(j*10 + int(S[i]))%13] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

Fixed submission:
S = input()
# S = '?'*100000

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12

for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12
for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
        nextdp[(j*10 + k)%13] %= num_mod
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
      nextdp[(j*10 + int(S[i]))%13] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

Fixed submission:
S = input()
# S = '?'*100000

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12

for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = [10 ** 9 + 1]
for i in range(N):
  A = int(input())
  flag = True
  for j in range(len(B)):
    if A > B[j]:
      B[j] = A
      flag = False
      break
  if flag:
    B.append(A)
print(len(B) - 1)


Fixed submission:
r = int(input())
print(3 * r ** 2)
Buggy python submission (verdict: Runtime Error):
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, K = map(int, input().split())
mod_num = 10 ** 9 + 7
for i in range(1, K + 1):
  print(comb(N - K + 1, i) * comb(K - 1, i - 1) % mod_num)


Fixed submission:
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, K = map(int, input().split())
mod_num = 10 ** 9 + 7
for i in range(1, K + 1):
  if i > N - K + 1:
    print(0)
  else:
    print(comb(N - K + 1, i) * comb(K - 1, i - 1) % mod_num)
Buggy python submission (verdict: Runtime Error):
X, A = map(int, input().split)
print(0 if X < A else 10)

Fixed submission:
X, A = map(int, input().split())
print(0 if X < A else 10)