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

Fixed submission:
a,b = map(int,input().split())
s = input()
for i in range(a+b+1):
  if i == a:
    if s[i] != '-':
      print('No')
      exit()
  else:
    if not '0' <= s[i] <= '9':
      print('No')
      exit()
  
print('Yes')

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n-1):
  ans = s[i]+c[i]
  for j in range(i+1, n-1):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
print(0)
Problem p03475 (python)

Fixed submission:
import math

n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    x, y, z = map(int, input().split())
    c += [x]
    s += [y]
    f += [z]

for i in range(n - 1):
    ans = s[i] + c[i]
    for j in range(i + 1, n-1):
        if ans < s[j]:
            ans = s[j] + c[j]
        else:
            ans = f[j] * math.ceil(ans / f[j]) + c[j]
    print(ans)
print(0)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n-1):
  ans = s[i]+c[i]
  for j in range(i+1, n-1):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
print(0)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n-1):
  ans = s[i]+c[i]
  for j in range(i+1, n):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
print(0)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
c = []
s = []
f = []
for i in range(n):
  x,y,z = map(int, input().split())
  c += [x]
  s += [y]
  f += [z]
  
for i in range(n):
  ans = s[i]+c[i]
  for j in range(i+1, n):
    ans = (ans//f[j]) * math.ceil(ans/f[j]) + c[j]
  print(ans)
Problem p03476 (python)

Fixed submission:
q = int(input())
l = []
r = []
for i in range(q):
    x, y = map(int, input().split())
    l += [x]
    r += [y]


def is_2017(x):
    if x % 2 == 0:
        return False
    return is_p[x] and is_p[(x + 1) // 2]

def is_prime(x):
    if x == 1:
        return False
    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1
    return True


is_p = [False] * 100000
n_2017 = [0] * 100000

for i in range(1, 100000):
    is_p[i] = is_prime(i)

for i in range(1, 100000):
    if is_2017(i):
        n_2017[i] = n_2017[i - 1] + 1
    else:
        n_2017[i] = n_2017[i - 1]

for i in range(q):
    print(n_2017[r[i]] - n_2017[l[i] - 1])

Buggy submission (verdict: Runtime Error):
q = int(input())
l = []
r = []
for i in range(q):
  x,y = map(int,input().split())
  l += [x]
  r += [y]


def is_2017(x):
  if x % 2 == 0:
    return False
  return is_p[x] && is_p[(x+1)//2]

def is_prime(x):
  if x == 1:
    return False
  i = 2
  while i * i <= x:
    if x % i == 0:
      return False
  return True
  
is_p = [False] * 100000
n_2017 = [0] * 100000

for i in range(1, 100000):
  is_p[i] = is_prime(i)

for i in range(1, 100000):
  if is_p[i]:
    n_2017[i] = n_2017[i-1] + 1

for i in range(q):
  print(n_2017[r]-n_2017[l-1])
Problem p03485 (python)

Fixed submission:
import math
a,b = map(int, input().split())
print(math.ceil((a+b) / 2))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
print(math.ceil((a+b) / 2)
Problem p03495 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int, input().split()))
s = dict()
for x in a:
  if x in s:
    s[x] += 1
  else:
    s[x] = 1
s_l = sorted(s.values())[0:max(0, len(s)-k)]
print(sum(s_l))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int, input().split()))
s = set()
for x in a:
  if x in s:
    s[x] += 1
  else:
    s[x] = 1
s_l = sorted(s.values())[0:max(0, len(s)-k)]
print(sum(s_l))
Problem p03546 (python)

Fixed submission:
h,w = map(int, input().split())
c = []
a = []
for i in range(10):
  c.append(list(map(int, input().split())))
for i in range(h):
  a.append(list(map(int, input().split())))
 
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j], c[i][k] + c[k][j])
      
ans = 0
for i in range(h):
  for j in range(w):
    if a[i][j] != -1:
      ans += c[a[i][j]][1]
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
c = []
a = []
for i in range(10):
  c.append(list(map(int, input().split())))
for i in range(h):
  a.append(list(map(int, input().split())))

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j]), c[i][k] + c[k][j])
      
ans = 0
for i in range(h):
  for j in range(w):
    if a[i][j] != -1:
      ans += c[a[i][j]][1]
Problem p03547 (python)

Fixed submission:
x,y = input().split()
if x < y:
  print('<')
elif x > y:
  print('>')
else:
  print('=')

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
if x < y:
  print('<')
elif x > y:
  print('>')
else:
  print('=')
Problem p03556 (python)

Fixed submission:
import math
n = int(input())
print(int(math.pow(int(math.sqrt(n)), 2)))

Buggy submission (verdict: Runtime Error):
import math
print(int(math.sqrt(int(input())))
Problem p03557 (python)

Fixed submission:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

dp_b = [0] * n
j = 0
for i in range(n):
    while j < n:
        if B[i] >= C[j]:
            dp_b[i] = j
            break
        j += 1
    if j == n:
        dp_b[i] = n

for i in range(1, n):
    dp_b[i] = dp_b[i] + dp_b[i - 1]

ans = 0
j = 0
for i in range(n):
    while j < n:
        if A[i] >= B[j]:
            if j == 0:
                break
            else:
                ans += dp_b[j - 1]
                break
        j += 1
    if j == n:
        ans += dp_b[n - 1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

dp_b = [0] * n
j = 0
for i in range(n):
  while j < n:
    if B[i] >= C[j]:
      dp_b[i] = j
      break
    j += 1
  if j == n:
    dp_b[i] = n

for i in range(1, n):
  dp_b[i] = dp_b[i] + dp_b[i-1]

ans = 0
j = 0
for i in range
  while j < n:
    if A[i] >= B[j]:
      if j == 0:
        break
      else:
        ans += B[j-1]
        break
    j += 1
    if j == n:
      ans += B[n-1]
  
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split())).sort(reverse=True)
B = list(map(int, input().split())).sort(reverse=True)
C = list(map(int, input().split())).sort(reverse=True)

dp_b = [0] * n
j = 0
for i in range(n):
  while j < n:
    if B[i] >= C[j]:
      dp_b[i] = j
      break
    j += 1
  if j == n:
    dp_b[i] = n

for i in range(1, n):
  dp_b[i] = dp_b[i] + dp_b[i-1]

ans = 0
j = 0
for i in range
  while j < n:
    if A[i] >= B[j]:
      if j == 0:
        break
      else:
        ans += B[j-1]
        break
    j += 1
    if j == n:
      ans += B[n-1]
  
print(ans)
Problem p03565 (python)

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

def match(i):
  for j in range(len(t)):
    if not s[i+j] == '?' and s[i+j] != t[j]:
      return False
  return True

for i in range(len(s) - len(t), -1, -1):
  if not match(i):
    continue

  for j in range(i):
    print('a' if s[j] == '?' else s[j], end='')
  print(t, end='')
  for j in range(i+len(t), len(s)):
    print('a' if s[j] == '?' else s[j], end='')
  print()
  exit()
    
print('UNRESTORABLE')

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

if len()

def match(i):
  for j in range(len(t)):
    if not s[i+j] == '?' and s[i+j] != t[j]:
      return False
  return True

for i in range(len(s) - len(t), -1, -1):
  if not match(i):
    continue

  for j in range(i):
    print('a' if s[j] == '?' else s[j], end='')
  print(t, end='')
  for j in range(i+len(t), len(s)):
    print('a' if s[j] == '?' else s[j], end='')
  print()
  exit()
    
print('UNRESTORABLE')
Problem p03598 (python)

Fixed submission:
n = int(input())
k = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += min(k-a[i], a[i]) * 2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += min(k-a, a) * 2
print(ans)
Problem p03599 (python)

Fixed submission:
a,b,c,d,e,f = map(int,input().split())
ans_per, ans_w, ans_s = -1,0,0
for i in range(f//(100*a) + 1):
  for j in range((f-100*i)//(100*b) + 1):
    if i == j == 0:
      continue
    w = i*a*100 + j*b*100
    r = min(f-w, w//100 * e)
    for x in range(r//c + 1):
      for y in range((r-x*c)//d + 1):
        s = x*c + y*d
        if s / w > ans_per:
          ans_per = s/w
          ans_w = w
          ans_s = s
print('{} {}'.format(ans_w+ans_s, ans_s))

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int,input().split())
ans_per, ans_w, ans_s = 0,0,0
for i in range(f//(100*a) + 1):
  for j in range(, (f-100*i)//(100*b) + 1):
    w = i*a*100 + j*b*100
    r = min(f-w, w//100 * e)
    for x in range(r//c + 1):
      for y in range((r-x*c)//d + 1):
        s = x*c + y*d
        if s / w > ans_per:
          ans_per = s/w
          ans_w = w
          ans_s = s
print('{} {}'.format(ans_w+ans_s, ans_s))
Problem p03608 (python)

Fixed submission:
import itertools
n,m,R = map(int,input().split())
r = list(map(int,input().split()))
cost = [[-1]*n for i in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if k == i or k == j or cost[i][k] == -1 or cost[k][j] == -1:
                continue
            if cost[i][j] == -1:
                cost[i][j] = cost[i][k]+cost[k][j]
            else:
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])

ans = -1
for p in itertools.permutations(r):
    c = 0
    for i in range(R-1):
        c += cost[p[i]-1][p[i+1]-1]
    if ans == -1:
        ans = c
    else:
        ans = min(c, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m,R = map(int,input().split())
r = list(map(int,input().split()))
cost = [[-1]*n for i in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if cost[i][k] == -1 or cost[k][j] == -1:
                continue
            if cost[i][j] == -1:
                cost = cost[i][k]+cost[k][j]
            else:
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])

ans = -1
for p in itertools.permutations(r):
    c = 0
    for i in range(R-1):
        c += cost[p[i]-1][p[i+1]-1]
    if ans == -1:
        ans = c
    else:
        ans = min(c, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m,R = map(int,input().split())
r = list(map(int,input().split()))
cost = {}
for i in range(m):
  a,b,c = map(int,input().split())
  cost[(a,b)] = c

ans = 1000000
for p in itertools.permutations(r):
  c = 0
  for i in range(len(r)-1):
    c += cost[(p[i], p[i+1])]
  ans = min(c, ans)
print(ans)
Problem p03610 (python)

Fixed submission:
s = input()
for i in range(0, len(s), 2):
  print(s[i], end='')
print()

Buggy submission (verdict: Runtime Error):
s = input()
for i in range(0, n, 2):
  print(s[i], end='')
print()
Problem p03625 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

sq = False
top, sec = 0,0
for k,v in c.items():
    if v < 2:
        continue
    if k > top:
        sq = v >= 4
        sec = top
        top = k
    elif k > sec:
        sec = k

if sq:
    print(top * top)
else:
    print(top * sec)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

top, sec = 0,0
for k,v in c:
  if n < 2:
    continue
  if k > top:
    sec = top
    top = k
  elif k > sec:
    sec = k

print(top * sec)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

top, sec = 0,0
for k,v in c:
  if n < 2:
    continue
  if k > top:
    sec = top
    top = k
  elif k > sec:
    sec = k

print(top * sec)
Problem p03633 (python)

Fixed submission:
n = int(input())
t = [int(input()) for _ in range(n)]


def gcd(x,y):
  if y == 0:
    return x
  return gcd(y, x % y)


ans = t[0]
for x in t[1:]:
  ans = ans * x // gcd(ans, x)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for _ in range(n)]


def gcd(x,y):
  if y == 0:
    return x
  return gcd(y, x % y)


ans = t[0]
for x in t[1:]:
  ans = ans * t[i] // gcd(ans, t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for _ in range(n)]

def gcd(x,y):
  if x % y == 0:
    return y
  return gcd(y, x % y)

for i in range(n):
  for j in range(i+1, n):
    if t[i] == 1:
      break
    t[i] //= gcd(t[i], t[j])

ans = 1
[ans *= x for x in t]
print(ans)
Problem p03636 (python)

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))

Buggy submission (verdict: Runtime Error):
s = input()
print('{}{}{}'.format(s[0], len(s)-1, s[-1])
Problem p03645 (python)

Fixed submission:
n,m = map(int,input().split())
s = set()
t = set()
for i in range(m):
  a,b = map(int,input().split())
  if a == 1 and b != n:
    s.add(b)
  if a != 1 and b == n:
    t.add(a)
 
if len(s&t) > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = set()
t = set()
for i in range(m):
  a,b = map(int,input().split())
  if a == 1 and b != n:
    s.add(b)
  if a != 1 and b == n:
    t.add(a)
 
for x in a:
  if x in b:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = set()
t = set()
for i in range(m):
  a,b = map(int,input().split())
  if a == 1 and b != n:
    s.add(b)
  if a != 1 and b == n:
    t.add(a)

if len(a&b) > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
Problem p03673 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s1 = []
s2 = []
for i in range(n):
  if i % 2 == 0:
    s1.append(a[i])
  else:
    s2.append(a[i])

if n % 2 == 0:
  for x in list(reversed(s2)) + s1:
    print(x, end=' ')
else:
  for x in list(reversed(s1)) + s2:
    print(x, end=' ')
print()

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
s1 = []
s2 = []
for i in range(n):
  if i % 2 == 0:
    s1.append(a[i])
  else:
    s2.append(a[i])

if n % 2 == 0:
  for x in reversed(s2) + s1:
    print(x, end=' ')
else:
  for x in reversed(s1) + s2:
    print(x, end=' ')
print()
Problem p03696 (python)

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

num = 0
lmax = 0
rmax = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    lmax = max(lmax, num)

num = 0
for i in range(n-1, -1, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    rmax = max(rmax, num)

print("("*lmax + s + ")"*rmax)

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

num = 0
lmax = 0
rmax = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    if num == -1:
        
    lmax = max(lmax, num)

num = 0
for i in range(n-1, -1, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    rmax = max(rmax, num)

print("("*lmax + s + ")"*rmax)

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

num = 0
l = 0
r = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    if num == -1:
        l += 1
        num = 0

num = 0
for i in range(n-1, 0, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    if num == 01:
        r += 1
        num = 0

print("("*l + s + ")"*r)
Problem p03731 (python)

Fixed submission:
n,t = map(int,input().split())
a = list(map(int,input().split()))
 
ans = t
for i in range(n-1):
  ans += min(t, a[i+1] - a[i])
print(ans)

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

ans = t
for i in range(0,n-1):
  ans += min(t, s[i+1] - s[i])
print(ans)
Problem p03739 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    ans -= 1
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and (a[j] == abs(a[j])) != (s == abs(s)):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and (a[j] == abs(a[j])) != (s == abs(s)):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and a[j] // abs(a[j]) != s // abs(s):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
s, ans, i = 0,0,0
while a[i] == 0 and i < n:
  ans += 2
  i += 1
ans = max(0, ans - 1)
if i == n:
  print(ans)
  exit()

if ans > 0:
  if abs(a[i]) == 1:
    ans += 1
    s = a[i] // abs(a[i])
else:
  s = a[0]

i += 1
for j in range(i,n):
  if abs(a[j]) > abs(s) and a[j] // abs(a[j]) != s // abs(s):
    s += a[j]
  else:
    s = -1 * s // abs(s)
    ans += abs(abs(a[j]) - 2)
  
  
print(ans)
Problem p03846 (python)

Fixed submission:
mod = 10**9 + 7
n = int(input())
a = sorted(list(map(int,input().split())))
 
if n % 2 == 0:
  for i in range(n//2):
    if not a[2*i] == a[2*i+1] == 2*i+1:
      print(0)
      exit()
else:
  if a[0] != 0:
    print(0)
    exit()
  for i in range(n//2):
    if not a[2*i+1] == a[2*i+2] == 2*i+2:
      print(0)
      exit()
print(pow(2, n//2) % mod)

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
n = int(input())
a = sorted(list(map(int,input().split())))

if n % 2 == 0:
  for i in range(n//2):
    if not a[2*i] == a[2*i+1] == 2*i+1:
      print(0)
      exit()
else:
  if a[0] != 0:
    print(0)
    exit()
  for i in range(n//2):
    if not a[2*i+1] == a[2*i+2] == 2*i+2
    print(0)
    exit()
print(pow(2, n//2) % mod)
Problem p03862 (python)

Fixed submission:
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = [a[i] + a[i+1] for i in range(n-1)] + [0]
 
ans = max(0, a[0] - x)
b[0] -= ans
 
for i in range(n-1):
  diff = max(0, b[i] - x)
  ans += diff
  b[i] -= diff
  b[i+1] -= diff
print(ans)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = [a[i] + a[i+1] for i in range(n-1)]

ans = max(0, a[0] - x)
b[0] -= ans

for i in range(n-1):
  diff = max(0, b[i] - x)
  ans += diff
  b[i] -= diff
  b[i+1] -= diff
print(ans)
Problem p03964 (python)

Fixed submission:
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
    a,b = map(int,input().split())
    aa = 0
    bb = 0
    if A % a == 0:
        aa = A // a
    else:
        aa = A // a + 1
    if B % b == 0:
        bb = B // b
    else:
        bb = B // b + 1
    m = max(aa, bb)
    A,B = a * m, b * m
print(A+B)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
  a,b = map(int,input().split())
  m = max(math.ceil(A/a), math.ceil(B/b))
  A,B = A * m, B * m
print(A+B)

Buggy submission (verdict: Runtime Error):
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
  a,b = map(int,input().split())
  m = max(math.ceil(A/a), math.ceil(B/b))
  A,B = A * m, B * m
print(A+B)
Problem p03998 (python)

Fixed submission:
s = [input() for i in range(3)]
t = {'a':0, 'b':1, 'c':2}
winner = {0:'A', 1:'B', 2:'C'}
index = [0,0,0]
length = [len(s[i]) for i in range(3)]
turn = 0
while True:
  if index[turn] >= length[turn]:
    print(winner[turn])
    exit()
  c = s[turn][index[turn]]
  index[turn] += 1
  turn = t[c]

Buggy submission (verdict: Runtime Error):
s = [input() for i in range(3)]
t = {'a':0, 'b':1, 'c':2}
winner = {0:'A', 1:'B', 2:'C'}
index = [0,0,0]
length = [len(s[i]) for i in range(3)]
turn = 0
while True:
  if index[turn] >= length[turn]:
    print(winner[turn])
  c = s[turn][index[turn]]
  index[turn] += 1
  turn = t[c]
Problem p03999 (python)

Fixed submission:
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  plus = [0]
  for j in range(n-1):
    if (i >> j) & 1 == 1:
      plus += [j+1]
  plus += [n]
  for j in range(len(plus)-1):
    ans += int(s[plus[j]:plus[j+1]])
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  plus = [0]
  for j in range(n-1):
    if (i >> j) & 1 = 1:
      plus += [j+1]
  for j in range(len(plus)-1):
    ans += int(s[plus[j]:plus[j+1]])
print(ans)
Problem p04013 (python)

Fixed submission:
n,a = map(int,input().split())
x = list(map(int,input().split()))
t = [[[0] * (50*(j+1)+1) for j in range(i+2)] for i in range(n+1)]
ans = 0
t[0][0][0] = 1

for i in range(1, n+1):
    for j in range(i+1):
        for k in range(50*j + 1):
            if j >= 1 and k >= x[i-1]:
                t[i][j][k] = t[i - 1][j - 1][k - x[i-1]] + t[i - 1][j][k]
            else:
                t[i][j][k] = t[i - 1][j][k]
for i in range(1,n+1):
    ans += t[n][i][i*a]
print(ans)

Buggy submission (verdict: Runtime Error):
n,a = map(int,input().split())
x = list(map(int,input().split()))
t = [[0]*5001 for _ in range(n+1)]
ans = 0
for i in range(1, n+1):
  for y in x:
    for z in t[i-1]:
      t[i][z+y-a] += 1
  ans += t[i][0]
print(ans)

Buggy submission (verdict: Runtime Error):
n,a = map(int,input().split())
x = list(map(int,input().split()))
t = [[0]*5001 for _ in range(n+1)]
ans = 0
for i in range(1, n+1):
  for y in x:
    for z in t[i-1]:
      t[z+y-a] += 1
  ans += t[i][0]
print(ans)