Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
rows, cols = map(int, input().split())
mat = [input() for _ in range(rows)]

print_row = [False for _ in range(rows)]
print_col = [False for _ in range(cols)]

for i in range(rows):
  for j in range(cols):
    if mat[i][j] == '#':
      print_row[i] = True
      print_col[i] = True
      
for i in range(rows):
  for j in range(cols):
    if print_row[i] or print_col[j]:
      print(mat[i][j], end="")
  print()

Fixed submission:
rows, cols = map(int, input().split())
mat = [input() for _ in range(rows)]

print_row = [False for _ in range(rows)]
print_col = [False for _ in range(cols)]

for i in range(rows):
  for j in range(cols):
    if mat[i][j] == '#':
      print_row[i] = True
      print_col[j] = True

for i in range(rows):
  print_newline = False
  for j in range(cols):
    if print_row[i] and print_col[j]:
      print(mat[i][j], end="")
      print_newline = True
  if print_newline:
    print()
Buggy python submission (verdict: Runtime Error):
PRICE_CAKE = 4
PRICE_DOUGHNUT = 7

n = int(input())
max_cakes = n // PRICE_CAKES

valid = False
for i in range(max_cakes + 1):
  n_left = n - i * PRICE_CAKE
  if n_left % PRICE_DOUGHNUT == 0:
    valid = True
    break
    
print("Yes" if valid else "No")

Fixed submission:
PRICE_CAKE = 4
PRICE_DOUGHNUT = 7

n = int(input())
max_cakes = n // PRICE_CAKE

valid = False
for i in range(max_cakes + 1):
  n_left = n - i * PRICE_CAKE
  if n_left % PRICE_DOUGHNUT == 0:
    valid = True
    break
    
print("Yes" if valid else "No")
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
res = 0

for i in range(x):
  num = i * i
  while num <= x:
    res = max(res, num)
    num *= i

print(res)

Fixed submission:
x = int(input())
res = 1

for i in range(2, x):
  num = i * i
  while num <= x:
    res = max(res, num)
    num *= i
    
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

subs = set()
for i in range(len(s)):
  for len in range(1, min(4, len(s) - i + 1)):
    subs.add(s[i : i + len])
    if len(subs) == k:
      break
  if len(subs) == k:
    break

print(max(subs))

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

subs = set()
for i in range(len(s)):
  for l in range(1, min(k + 1, len(s) - i + 1)):
    subs.add(s[i : i + l])

print(sorted(list(subs))[k - 1])
Buggy python submission (verdict: Runtime Error):
(a, b, c, wanted_a, wanted_b) = (int(tok) for tok in input().split())

res = wanted_a * a + wanted_b * b
for both in range(max(wanted_a, wanted_b) * 2):
  left_a = wanted_a - both // 2
  left_b = wanteD_b - both // 2
  cost = both * c + max(0, left_a) * a + max(0, left_b) * b
  res = min(res, cost)

print(res)

Fixed submission:
(a, b, c, wanted_a, wanted_b) = (int(tok) for tok in input().split())

res = wanted_a * a + wanted_b * b
for both in range(max(wanted_a, wanted_b) * 2 + 1):
  left_a = wanted_a - both // 2
  left_b = wanted_b - both // 2
  cost = both * c + max(0, left_a) * a + max(0, left_b) * b
  res = min(res, cost)

print(res)
Buggy python submission (verdict: Runtime Error):
def is_palindrome(num):
  return str(num) == str(num)[-1::-1].lstrip("0")

(left, right) = (int(tok) for tok in input().split())
print(len(filter(is_palindrome, range(left, right + 1))))

Fixed submission:
def is_palindrome(num):
    return str(num) == str(num)[-1::-1].lstrip("0")

(left, right) = (int(tok) for tok in input().split())
print(len([i for i in range(left, right + 1) if is_palindrome(i)]))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from itertools import combinations, reduce

import operator

GOOD_LETTERS = "MARCH"
PEOPLE = 3

n = int(input())
c = Counter()

for _ in range(n):
  first = input()[0]
  if first in GOOD_LETTERS:
    c.update(first)
    
ways = 0
for tup in combinations(GOOD_LETTERS, PEOPLE):
  ways += reduce(operator.mul, [c[ch] for ch in tup], 1)

print(ways)

Fixed submission:
from collections import Counter
from functools import reduce
from itertools import combinations

import operator

GOOD_LETTERS = "MARCH"
PEOPLE = 3

n = int(input())
c = Counter()

for _ in range(n):
  first = input()[0]
  if first in GOOD_LETTERS:
    c.update(first)

ways = 0
for tup in combinations(GOOD_LETTERS, PEOPLE):
  ways += reduce(operator.mul, [c[ch] for ch in tup], 1)

print(ways)
Buggy python submission (verdict: Runtime Error):
(x, a, b) = (int(tok) for tok in input().split())
print((x - a) % b)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())

print((x - a) % b)
Buggy python submission (verdict: Runtime Error):
print(count(input(), '1'))

Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Runtime Error):
r1 = input()
r2 = reverse(input())
print("YES" if r1 == r2 else "NO")

Fixed submission:
r1 = input()
r2 = input()[::-1]

print("YES" if r1 == r2 else "NO")
Buggy python submission (verdict: Runtime Error):
(r, g) = (int(tok) for tok in input().split())
print(2 * g - r)

Fixed submission:
curr_rating = int(input())
final_rating = int(input())

print(2 * final_rating - curr_rating)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())

total = 0
for _ in range(n):
  x = int(input())
  total += min(x, k - x)

print(2 * total)

Fixed submission:
input()
k = int(input())
  
total = sum(min(int(tok), k - int(tok)) for tok in input().split())
print(2 * total)
Buggy python submission (verdict: Runtime Error):
(a, b) = (int(tok) for tok in input().split())
print("Possible" if any(s % 3 == 0 for s in [a, b, a + b] else "Impossible")

Fixed submission:
(a, b) = (int(tok) for tok in input().split())
print("Possible" if any(s % 3 == 0 for s in [a, b, a + b]) else "Impossible")
Buggy python submission (verdict: Runtime Error):
(nodes, roads) = (int(tok) for tok in input().split())

count = { i:0 for i in range(1, nodes + 1) }
for _ in range(roads):
	for tok in input().split():
		count[int(node)] += 1
          
for i in range(1, nodes + 1):
	print(count[i])

Fixed submission:
(nodes, roads) = (int(tok) for tok in input().split())

count = { i : 0 for i in range(1, nodes + 1) }
for _ in range(roads):
    for tok in input().split():
        count[int(tok)] += 1

for i in range(1, nodes + 1):
    print(count[i])
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _i in range(m)]

uf = UnionFind(n)
for i, j in ab:
    uf.union(i, j)
print(uf.group_count()-1)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _i in range(m)]

uf = UnionFind(n)
for i, j in ab:
    uf.union(i-1, j-1)
print(uf.group_count()-1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(input()) for _i in range(n)]

dp = [0]*300000
dp_nex = [0]*300000

for i in range(n):
    dp[a[i]] = max(dp[max(0,i-k):min(300000, i+k)])+1
print(max(dp))


Fixed submission:
_N, k = map(int, input().split())
a = [int(input()) for _i in range(_N)]

n = 300002

def init_max(init_max_val):
    #set_val
    for i in range(n):
        seg_max[i+num_max-1]=init_max_val[i]    
    #built
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = -1

#num_max:n以上の最小の2のべき乗
num_max =2**(n-1).bit_length()
seg_max=[ide_ele_max]*2*num_max

A = [0]*300002
init_max(A)

for i in range(_N):
    update_max(a[i], query_max(max(0, a[i]-k), min(300001, a[i]+k+1))+1)

print(query_max(0,300001))
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

h = True
checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1
    if sum(checker[i::i]) > 1:
        h = False
        break
    for j in range(i, 10**6+2, i):
        checker[j] += 1

if h == True:
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Fixed submission:
from math import gcd

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

checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1

if all(sum(checker[i::i])<2 for i in range(2,10**6+1)):
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

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

checker = [0 for _i in range(10**6+1)]
h = True
for i in a:
    if i == 1:
        continue
    num = i
    if num%2==0:
        checker[2] += 1
        if checker[2] >= 2:
            h = False
            break
    
    for j in range(3, int(i**0.5)+1):
        if num%j == 0:
            checker[j] += 1
            if checker[j] >= 2:
                h = False
                break
            num //= j
    if num == i:
        checker[num] += 1:
        if checker[num] >= 2:
            h = False
            break
if h == True:
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Fixed submission:
from math import gcd

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

checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1

if all(sum(checker[i::i])<2 for i in range(2,10**6+1)):
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')
Buggy python submission (verdict: Runtime Error):
s = input()
if s === 'RRR':
    print(3)
elif s[:2] == 'RR' or s[1:] == 'RR':
    print(2)
elif s.count('R') >= 1:
    print(1)
else:
    print(0)

Fixed submission:
s = input()
if s=='RRS' or s=='SRR':
    print(2)
elif s=='RRR':
    print(3)
elif s=='SSS':
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Fixed submission:
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    if middle==0:
        left=1
        break
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[i, 2] for i in a]
for _ in range(k):
    p = a.index(max(a))
    if b[p][0]%b[p][1] == 0:
        a[p] = b[p][0]//b[p][1]
    else:
        a[p] = b[p][0]//b[p][1] +1
    b[p][1] += 1
print(max(a))

Fixed submission:
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    if middle==0:
        left=1
        break
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[i, 2] for i in a]
for _ in range(k):
    p = a.index(max(a))
    if b[p][0]%b[p][1] == 0:
        a[p] = b[p][0]//b[p][1]
    else:
        a[p] = b[p][0]//b[p][1] +1
    b[p][1] += 1
print(max(a))

Fixed submission:
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    if middle==0:
        left=1
        break
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
from collections import Counter
x = Counter(a)
r = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    if b in x:
        m = x[b]
        x.pop(b)
        if c in x:
            x[c] += m
        else:
            x[c] = m
    r += m*(c-b)
    print(r)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
from collections import Counter
x = Counter(a)
r = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    m = 0
    if b in x:
        m = x[b]
        x.pop(b)
        if c in x:
            x[c] += m
        else:
            x[c] = m
    r += m*(c-b)
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
from collections import Counter
x = Counter(a)
for i in range(q):
    b, c = map(int, input().split())
    if b in x:
        m = x[b]
        x.pop(b)
        if c in x:
            x[c] += m
        else:
            x[c] = m
    print(sum(i*j for i, j in x.items()))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
from collections import Counter
x = Counter(a)
r = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    m = 0
    if b in x:
        m = x[b]
        x.pop(b)
        if c in x:
            x[c] += m
        else:
            x[c] = m
    r += m*(c-b)
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6:
        checker[a[i]*x] = 0
        x += 1
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i-1]:
        continue
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6:
        checker[a[i]*x] = 0
        x += 1
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+10)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6+10:
        checker[a[i]*x] = 0
        x += 1
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i-1]:
        continue
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6:
        checker[a[i]*x] = 0
        x += 1
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6+1:
        checker[a[i]*x] = 0
        x += 1
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
checker = [1 for _i in range(10**6+1)]
a.sort()
a.append(-1)
result = 0
for i in range(n):
    if a[i] == a[i-1]:
        continue
    if a[i] == a[i+1]:
        checker[a[i]] = 0
    result += checker[a[i]]
    checker[a[i]] = 0
    x = 2
    while a[i]*x <= 10**6:
        checker[a[i]*x] = 0
        x += 1
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(50, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()+[0]
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(100, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()+[0]
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(50, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(100, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()+[0]
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(10**4, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))+[0]
s = [0 for _i in range(n+1)]
for i in range(n):
    s[max(0, i-a[i])] += 1
    s[min(n, i+a[i]+1)] -= 1   
a = s.copy()+[0]
for j in range(min(100, k-1)):
    t = [0 for _i in range(n+1)]
    for i in range(n):
        a[i] += a[i-1]
        t[max(0, i-a[i])] += 1
        t[min(n, i+a[i]+1)] -= 1
    a = t.copy()+[0]
for i in range(1, n):
    a[i] += a[i-1]
print(*a[:n])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

tree = [0 for _i in range(n+2)]
tree[0] = 1
for i in range(1,n+1):
    tree[i] = tree[i-1]*2
    tree[i] -= a[i]
tree[n] += a[i]
for i in range(n, 0, -1):
    if tree[i-1]*2 < a[i]:
        import sys
        print(-1)
        sys.exit()
    x = min(tree[i-1], a[i])
    a[i-1] += x
if a[0]>1:
    print(-1)
else:
    print(sum(a))

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))
if n==0:
    if a[0]<2:
        print(a[0])
    else:
        print(-1)
    sys.exit()
tree = [0 for _i in range(n+2)]
tree[0] = 1
for i in range(1,n+1):
    tree[i] = tree[i-1]*2
    tree[i] -= a[i]
tree[n] += a[i]
for i in range(n, 0, -1):
    if tree[i-1]*2 < a[i]:
        print(-1)
        sys.exit()
    x = min(tree[i-1], a[i])
    a[i-1] += x
if a[0]>1:
    print(-1)
else:
    print(sum(a))
Buggy python submission (verdict: Runtime Error):
s

Fixed submission:
s = input()
t = input()
if s==t[:-1]:
    print('Yes')
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [-1]+a
v = [-1 for _ in range(n+1)]
v[1] = 0
x = a[1]
c = 0
while k > 0 and v[x] < 0:
    y = a[x]
    v[y] = v[x]+1
    x = y
    k -= 1
    c += 1

if k==0:
    print(x)
else:
    z = c - v[x]
    if z != 0:
        k = k%z
    else:
        k = k%c
    while k > 0:
        k -= 1
        x = a[x]
    print(x)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
v = [-1 for _ in range(n)]
p = 0
x = 0
c = 0
while k > 0 and v[x] < 0:
    v[x] = p+1
    p = v[x]
    x = a[x]
    c += 1
    k -= 1

z = c-v[x]+1
k = k%z

while k > 0:
    k -= 1
    x = a[x]
print(x+1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [-1]+a
v = [-1 for _ in range(n+1)]
v[1] = 0
x = a[1]
c = 0
while k > 0 and v[x] < 0:
    y = a[x]
    v[y] = v[x]+1
    x = y
    k -= 1
    c += 1

if k==0:
    print(x)
else:
    z = c - v[x]
    k = k%z
    while k > 1:
        k -= 1
        x = a[x]
    print(x)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
v = [-1 for _ in range(n)]
p = 0
x = 0
c = 0
while k > 0 and v[x] < 0:
    v[x] = p+1
    p = v[x]
    x = a[x]
    c += 1
    k -= 1

z = c-v[x]+1
k = k%z

while k > 0:
    k -= 1
    x = a[x]
print(x+1)