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

Fixed submission:
if eval(input().replace(' ','==')):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
ans = 0
for i in range(n):
  ans += l // a[i]
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
l %= mod
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a) % mod
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)
Problem p02817 (python)

Fixed submission:
st = input().split()
print(st[1]+st[0])

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
if a >= k:
  print('{} {}'.format(a-k.b))
elif a+b >= k:
  print('0 {}'.format(b-(k-a)))
else:
  print('0 0')
Problem p02818 (python)

Fixed submission:
a, b, k = map(int, input().split())
if a >= k:
  print('{} {}'.format(a-k,b))
elif a+b >= k:
  print('0 {}'.format(b-(k-a)))
else:
  print('0 0')

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
if a >= k:
  print('{} {}'.format(a-k.b))
elif a+b >= k:
  print('0 {}'.format(b-(k-a)))
else:
  print('0 0')
Problem p02823 (python)

Fixed submission:
n, a, b = map(int, input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  m = min(a,b)
  M = max(a,b)
  if M - m == 1:
    if m-1 < n-M:
      print((M-1))
    else:
      print((n-m))
  else:
    if m-1 < n-M:
      print((m-1)+1+(M-m-1)//2)
    else:
      print((n-M)+1+(M-m-1)//2)

Buggy submission (verdict: Runtime Error):
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  # 累積和
  cnt += a[i]
  c.append(cnt)
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  d = h * (i-p+1) - (c[i]-c[p-1]) # 余裕
  if d >= free*m:
    ans += 1
print(ans)
Problem p02841 (python)

Fixed submission:
m, d = map(int, input().split())
print(1 if int(input().split()[1])-d!=1 else 0)

Buggy submission (verdict: Runtime Error):
m, d = map(int, input().split())
print(1 if input().split()[1]-d!=1 else 0)
Problem p02886 (python)

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

print(sum(list(map(lambda x:(s-x)*x, d)))//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input()))
s = sum(d)

print(sum(list(map(lambda x:(s-x)*x, d))))
Problem p02899 (python)

Fixed submission:
n = int(input())
_ = list(map(int, input().split()))
a = []
for i in range(1,n+1):
  a.append([_[i-1], i])
  
ans = []
a_sort = (sorted(a, key=lambda x: x[0]))
for i in range(n):
  ans.append(a_sort[i][1])
  
print(' '.join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
n = int(input())
_ = list(map(int, input()))
a = []
for i in range(1,n+1):
  a.append(_[i-1], i)
  
ans = []
a_sort = (sorted(a, key=lambda x: x[0]))
for i in range(n):
  ans.append(a_sort[i][1])
  
print(' '.join(list(map(str, ans))))
Problem p02909 (python)

Fixed submission:
s = input()
if s == 'Sunny':
  print('Cloudy')
elif s == 'Cloudy':
  print('Rainy')
else:
  print('Sunny')

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

ans = 0
for i in range(n):
  for j in range(i, n):
    if s[i:j+1] in s[j+1:]:
      ans = max(ans, j-i+1)
    else:
      break
print(ans)
Problem p02937 (python)

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

for i in range(len(t)):
  if not t[i] in s:
    print(-1)
    break
else:
  j = -1
  counter = 0
  for i in range(len(t)):
    if t[i] in s[j+1:]:
      j = s[j+1:].find(t[i]) + j + 1
    else:
      counter += 1
      j = s.find(t[i])
  print(counter * len(s) + j + 1)

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

for i in range(len(t)):
  if not t[i] in s:
    print(-1)
    break
else:
  j = 0
  for i in rane(len(t)):
    j = s[j:].find(t[i])
    if j == -1:
      counter += 1
      j = s.find(t[i])
  print(counter * len(s) + j + 1)
Problem p02981 (python)

Fixed submission:
nab = input().split()

n = int(nab[0])
a = int(nab[1])
b = int(nab[2])

print(min(a*n, b))

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

a = []

x = []

for i in range(n):
  a.append(2*int(_a[i]))
  x.append(0)
  
for i in range(1, n):
  a[i] -= a[i-1]

x[n-1] = a[n-1] // 2

for i in range(n-2, -1, -1):
  if i%2==0:
    x[i] = a[i] - x[n-1]
  else:
    x[i] = a[i] + x[n-1]
    
ans = str(x[n-1]) + ' '
for i in range(n-1):
  ans += str(x[i]) + ' '
  

print(ans[:-1])
Problem p02983 (python)

Fixed submission:
lr = input().split()
l = int(lr[0])
r = int(lr[1])

mini = 2018

for i in range(l, r+1):
  for j in range(i+1, r+1):
    mini = min(mini, (i*j)%2019)

    if mini==0:
      break
  if mini==0:
    break
print(mini)

Buggy submission (verdict: Runtime Error):
lr = input().split()
l = int(lr[0])
r = int(lr[1])

mini = 2020
for i in range(l, r+1):
  j = i+1
  while j>i and j<=r:
    q = (i*j)%2019
    j = j + (2018-q)//i
    mini = min(mini, q)
    
print(mini)
Problem p02988 (python)

Fixed submission:
n = int(input())
p = input().split()

s = 0
for i in range(n-2):
  if max(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]) and min(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]):
    s += 1

print(s)

Buggy submission (verdict: Runtime Error):
n = input()
p = input().split()

s = 0
for i in range(n-2):
  if max(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]) and min(int(p[i]), int(p[i+1]), int(p[i+2])) != int(p[i+1]):
    s += 1

print(s)
Problem p03071 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(a+b, 2*a-1, 2*b-1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print(max(a+b, 2*a-1, 2*b-1))
Problem p03105 (python)

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

Buggy submission (verdict: Runtime Error):
print(eval('min('+input()[::-1].replace(' ',',',1).replace(' ','//')+')'))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input(9.split()))
print(max(b//a, c))
Problem p03109 (python)

Fixed submission:
print('Heisei' if int(input().replace('/',''))<=20190430 else 'TBD')

Buggy submission (verdict: Runtime Error):
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)
Problem p03112 (python)

Fixed submission:
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)

Buggy submission (verdict: Runtime Error):
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[b-1], t[b]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)

Buggy submission (verdict: Runtime Error):
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[b-1], t[b]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)
Problem p03126 (python)

Fixed submission:
n, m = map(int, input().split())
likes = [0 for i in range(m + 1)]

for i in range(n):
  for food in list(map(int, input().split()))[1:]:
    likes[food] += 1
print(len(list(filter(lambda x: x==n, likes))))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())
a = list(map(int, input().split()))[1:]
for i in range(n - 1):
  foods = list(map(int, input().split()))[1:]
  for food in a:
    if not food in foods:
      a.remove(food)
print(len(a))
Problem p03145 (python)

Fixed submission:
a=sorted(list(map(int,input().split())))
print(a[0]*a[1]//2)

Buggy submission (verdict: Runtime Error):
a=sorted(list(map(int,input().split())))
print(a*b//2)
Problem p03238 (python)

Fixed submission:
if input()=='1':
  print('Hello World')
else:
  print(int(input())+int(input()))

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if infos[i][2] == 0:
    xy.remove(infos[i][0], infos[i][1])
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))
Problem p03241 (python)

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

ans = 1
for i in range(1, int(m**0.5)+2):
  if m % i == 0:
    if i * n <= m:
      ans = max(ans, i)
    if (m // i) * n <= m:
      ans = max(ans, m//i)
    
print(ans)

Buggy submission (verdict: Runtime Error):
# 求める出力は，mの約数iのうち n*i <= m を満たす最大の整数n．

N, M = map(int, input().split())
fracs = []
i = 2
m = M
# mの素因数分解を求める
while m > 1 and M**0.5:
  while m % i == 0:
    m //= i
    if len(fracs)==0:
      fracs.append([i, 1])
    elif fracs[-1][0] == i:
      fracs[-1][1] += 1
    else:
      fracs.append([i, 1])    
  i += 1

if m != 1:
  fracs.append(m, 1)

# 約数を全て列挙する
divisors = []
def search(i, p):
  for j in range(fracs[i][1]+1):
    if i != len(fracs)-1:
      new_p = p * fracs[i][0] ** j
      search(i+1, new_p)
    else:
      divisors.append(p * fracs[i][0] ** j)
search(0, 1)

print(sorted(list(filter(lambda x: x*N <= M, divisors)))[-1])
Problem p03251 (python)

Fixed submission:
n, m, x, y = map(int, input().split())
x_max = max(list(map(int, input().split()))+[x])
y_min = min(list(map(int, input().split()))+[y])

if x_max < y_min:
  print('No War')
else:
  print('War')

Buggy submission (verdict: Runtime Error):
n, m, x, y = map(int, input().split())
x_max = max(list(map(int, input().split())))
y_min = min(list(map(int, input().split())))

if x_max < y and x_max < y_min:
  print('No War')
else:
  print('War)
Problem p03274 (python)

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

ans = 10**9
for i in range(n-k+1):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)

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

ans = 0
for i in range(n):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)

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

if k == 1:
  print(min(list(map(abs, x))))
  
else:

  if 0 in x:
    k -= 1
  ans = 10**9

  x_p = list(filter(lambda x: x > 0, x))
  x_n = list(filter(lambda x: x < 0, x))

  if len(x_p) >= k and k != 0:
    ans = min(ans, x_p[k-1])
  if len(x_n) >= k and k != 0:
    ans = min(ans, -x_n[-k])
  
  for i in range(n):
    if x[i] < 0 and x[i+k-1] > 0:
      d = x[i+k-1] - x[i] + min(-x[i], x[i+k-1])
      ans = min(ans, d)
    
  print(ans)
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
print((a - 1) * (b - 1))

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

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)
Problem p03282 (python)

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

for i in map(int, s[:k]):
  if i != 1:
    print(i)
    break
else:
  print(1)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 15) - 1

import math

i = 0
while k > 0:
  
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  
print(s[i-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 15) - 1

import math

i = 0
while k > 0:
  print(s[i])
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  print(k)
  
print(s[i-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
infinity = 5 * (10 ** 11) - 1

import math

i = 0
while k > 0:
  k -= math.floor(infinity * math.log(int(s[i]), 10)) + 1
  i += 1
  
print(s[i-1])
Problem p03284 (python)

Fixed submission:
n, k = map(int, input().split())
if n % k == 0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input())
if n % k == 0:
  print(0)
else:
  print(1)
Problem p03293 (python)

Fixed submission:
s = input()
if s in input() * 2:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s = input()
if s in t = input() * 2:
  print('Yes')
else:
  print('No')
Problem p03351 (python)

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

if abs(a - c) <= d:
  print('Yes')
  
elif abs(a - b) <= d and abs(b - c) <= d:
  print('Yes')
  
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import math

x = int(input())

ans = 1
for i in range(2, 9):
  d = (math.floor(x ** (1 / i))) ** i
  if d <= x:
    ans = max(ans, d)
  
print(ans)
Problem p03360 (python)

Fixed submission:
abc = sorted(list(map(int, input().split())))
k = int(input())

print(abc[0] + abc[1] + abc[2] * (2 ** k))

Buggy submission (verdict: Runtime Error):
abc = sorted(list(map(int, input().split())))
k = int(input())

print(a + b + c * (2 ** k))
Problem p03380 (python)

Fixed submission:
n = int(input())

a = sorted(list(map(int, input().split())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))

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

a = sorted(list(map(int, input())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))
Problem p03399 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b) + min(c,d))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b) + min(c+d))
Problem p03408 (python)

Fixed submission:
n = int(input())
dic = {}
for i in range(n):
  s = input()
  if s in dic.keys():
    dic[s] += 1
  else:
    dic[s] = 1

m = int(input())
for i in range(m):
  t = input()
  if t in dic.keys():
    dic[t] -= 1
    
ans = 0
for key in dic.keys():
  ans = max(ans, dic[key])
  
print(max(ans, 0))

Buggy submission (verdict: Runtime Error):
n = int(input())
dic = {}
for i in range(n):
  s = input()
  if s in dic.keys():
    dic[s] += 1
  else:
    dic[s] = 1

m = int(input())
for i in range(n):
  t = input()
  if t in dic.keys():
    dic[t] -= 1
    
ans = 0
for key in dic.keys():
  ans = max(ans, dic[key])
  
print(max(ans, 0))
Problem p03425 (python)

Fixed submission:
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0].lower()
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += march[key1] * march[key2] * march[key3]
print(ans//6)

Buggy submission (verdict: Runtime Error):
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0]
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += key1 * key2 * key3
print(ans)
Problem p02640 (python)

Fixed submission:
x,y = map(int,input().split())
if x*2 <= y <= x*4 and y % 2 == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
print("Yes" if (lambda x: x[0] * 2 <= x[1] <= x * 4)(list(map(int,input().split()))) else "No")
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
p = list(map(int,input().split()))
flag = [True] * 102

for i in p:
    flag[i] = False

for i in range(101):
    low = max(x-i, 0)
    high = min(x+i, 101)
    if flag[low]:
        print(low)
        break
    elif flag[high]:
        print(high)
        break

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
p = list(map(int,input().split()))
flag = [True] * 101

for i in p:
    flag[i] = False

for i in range(101):
    if flag[x-i]:
        print(x-i)
        break
    elif flag[x+i]:
        print(x+i)
        break
Problem p02678 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2*100000)
n, m = map(int,input().split())
mark = [-2] * (n-1)
dist = [0] * (n-1)
path = [[] for _ in range(n-1)]
path0 = []

for _ in range(m):
    a, b = map(lambda x: int(x)-2, input().split())
    if a == -1:
        path0.append(b)
        dist[b] = 1
        mark[b] = -1
    elif b == -1:
        path0.append(a)
        dist[a] = 1
        mark[a] = -1
    else:
        path[a].append(b)
        path[b].append(a)

while len(path0) > 0:
    i = path0.pop(0)
    d = dist[i]
    for p in path[i]:
        if dist[p] > d + 1 or dist[p] == 0:
            dist[p] = d + 1
            mark[p] = i
            path0.append(p)

print("Yes")
for i in mark: print(i+2)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
n, m = map(int,input().split())
mark = [-2] * (n-1)
dist = [0] * (n-1)
path = [[] for _ in range(n-1)]
path0 = []

def search(i):
    d = dist[i]
    for p in path[i]:
        if dist[p] > d or dist[p] == 0:
            dist[p] = d + 1
            mark[p] = i
            search(p)

for _ in range(m):
    a, b = map(lambda x: int(x)-2, input().split())
    if a == -1:
        path0.append(b)
        dist[b] = 1
        mark[b] = -1
    elif b == -1:
        path0.append(a)
        dist[a] = 1
        mark[a] = -1
    else:
        path[a].append(b)
        path[b].append(a)

for p in path0:
    search(p)

if mark.count(-2) > 0:
    print("No")
else:
    print("Yes")
    for i in mark: print(i+2)
Problem p02696 (python)

Fixed submission:
from math import floor
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))
Problem p02936 (python)

Fixed submission:
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    nodes[p-1][1] += q

search_node = [0]

while len(search_node) > 0:
    n = search_node.pop()
    for i in nodes[n][0]:
        nodes[i][1] += nodes[n][1]
        search_node.append(i)


op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)

Buggy submission (verdict: Runtime Error):
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

def add(idx, val):
    global nodes
    nodes[idx][1] += val
    for n in nodes[idx][0]:
        add(n, val)

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    add(p-1, q)
op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)
Problem p02972 (python)

Fixed submission:
from collections import deque
n = int(input())
a = list(input().split())

ball = []
for i in range(n, 0, -1):
    c = 2
    while i * c <= n:
        if a[i*c-1] == "1":
            a[i-1] = "1" if a[i-1] == "0" else "0"
        c += 1
    if a[i-1] == "1":
        ball.append(str(i))

print(len(ball))
if ball != []: print(" ".join(ball))

Buggy submission (verdict: Runtime Error):
n, a = input(), input()
print(" ".join(["0"]*n))
Problem p02995 (python)

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x,y)
a,b,c,d = map(int,input().split())
a -= 1
e = lcm(c,d)
print(b-a-b//c-b//d+b//e+a//c+a//d-a//e)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x,y)
a,b,c,d = map(int,input().split())
a -= 1
e = lcm(c,d)
print(b-a-b//c-b//d+b//e+a//c+a//d-a//e)
Problem p03043 (python)

Fixed submission:
n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    # x = math.ceil(math.sqrt(k/i)) if k > i else 0
    x = 0
    t = i
    while t < k:
        t *= 2
        x += 1
    # per += float("{:.20g}".format(1/(2**x)))
    per += 2**-x

print(per/n)

Buggy submission (verdict: Runtime Error):
import math, decimal

memo = [1,2,4,8,16,32,64,128,256,512,1024,2048]
def twopow(f):
    if len(memo) < f:
        return memo[f]
    else:
        repeat = f - len(memo) + 1
        for _ in range(repeat):
            memo.append(memo[len(memo)-1]*2)
        return memo[f]

n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    x = math.ceil(math.sqrt(k/i)) if k > i else 0
    per += 1/twopow(x)

print(per/n)