Harryxun/testdata huggingface dataset:
Buggy python 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)

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 python 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)

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 python 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)

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 python 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)

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 python 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])


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 python submission (verdict: Time Limit Exceeded):
x,y = map(int,input().split())
d = y//x
ans = 0
while 0 < d:
  ans += 1
  d // 2
print(ans)

Fixed submission:
x,y = map(int,input().split())
d = y//x
ans = 0
while 0 < d:
  ans += 1
  d //= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
print(math.ceil((a+b) / 2)

Fixed submission:
import math
a,b = map(int, input().split())
print(math.ceil((a+b) / 2))
Buggy python 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))

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 python 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]


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 python submission (verdict: Runtime Error):
x,y = map(int,input().split())
if x < y:
  print('<')
elif x > y:
  print('>')
else:
  print('=')

Fixed submission:
x,y = input().split()
if x < y:
  print('<')
elif x > y:
  print('>')
else:
  print('=')
Buggy python submission (verdict: Runtime Error):
import math
print(int(math.sqrt(int(input())))

Fixed submission:
import math
n = int(input())
print(int(math.pow(int(math.sqrt(n)), 2)))
Buggy python 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)

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 python 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)

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 python 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')

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 python 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)

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 python 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))  

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 python submission (verdict: Runtime Error):
s = input()
for i in range(0, n, 2):
  print(s[i], end='')
print()

Fixed submission:
s = input()
for i in range(0, len(s), 2):
  print(s[i], end='')
print()
Buggy python 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)


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 python 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)

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 python 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)

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 python 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)

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 python submission (verdict: Runtime Error):
s = input()
print('{}{}{}'.format(s[0], len(s)-1, s[-1])

Fixed submission:
s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]))
Buggy python 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')

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 python 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')

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 python 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()

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 python 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)

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 python 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)

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 python 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)

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 python submission (verdict: Runtime Error):
from collections import defaultdict
import itertools

n,m = map(int,input().split())
e = [[False]*n for _ in range(n)]

for _ in range(m):
  a,b = map(int,input().split())
  e[a-1][b-1] = True
  e[b-1][a-1] = True

ans = 0
l = [i for i in range(1,n)]
for p in itertools.permutations(l):
  p = [0] + p
  reach = 1
  for i in range(n-1):
    if not e[p[i]][p[i+1]]:
      reach = 0
      break
  ans += reach

print(ans)

Fixed submission:
import itertools
n,m = map(int,input().split())
e = [[False]*n for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  e[a-1][b-1] = True
  e[b-1][a-1] = True

ans = 0
l = [i for i in range(1,n)]
for p in itertools.permutations(l):
  p = [0] + list(p)
  reach = 1
  for i in range(n-1):
    if not e[p[i]][p[i+1]]:
      reach = 0
      break
  ans += reach

print(ans)
Buggy python 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)

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 python 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)

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 python 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)

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 python 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)

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 python 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]

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 python 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)    

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 python 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)

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 python 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)

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 python submission (verdict: Runtime Error):
s = input()
b = 0
for i in range(n-1,-1,-1):
  if s[i] == 'B':
    b += 1
  else:
    if b > 0:
      b -= 1
    else:
      print(s[i], end='')
print()

Fixed submission:
s = input()
ans_rev = ''
b = 0
for i in range(len(s)-1,-1,-1):
  if s[i] == 'B':
    b += 1
  else:
    if b > 0:
      b -= 1
    else:
      ans_rev += s[i]
for i in range(len(ans_rev)-1, -1,-1):
  print(ans_rev[i], end='')
print()