Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

flag = True
for i in range(n):
    if a[i+1] != 0:
        flag = False
        break

if n != 0 and a[0] != 0:
    print(-1)
    exit()
elif n == 0 and a[0] == 1:
    print(1)
    exit()

nleaf = 1
ans = 0
v = list()

for i in range(n):
    nleaf -= a[i]
    v.append(nleaf)
    nleaf *= 2

if nleaf < a[i]:
    print(-1)
    exit()

nleaf = a[n]
ans += a[n]
for i in range(n-1, -1, -1):
    if v[i]*2 < nleaf:
        print(-1)
        exit()
    if v[i] > nleaf:
        v[i] = nleaf
    nleaf = v[i] + a[i]
    ans += nleaf
print(ans)

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

flag = True
for i in range(n):
    if a[i+1] != 0:
        flag = False
        break

if n != 0 and a[0] != 0:
    print(-1)
    exit()
elif n == 0 and a[0] == 1:
    print(1)
    exit()

nleaf = 1
ans = 0
v = list()

for i in range(n):
    nleaf -= a[i]
    v.append(nleaf)
    nleaf *= 2

if nleaf < a[n]:
    print(-1)
    exit()

nleaf = a[n]
ans += a[n]
for i in range(n-1, -1, -1):
    if v[i]*2 < nleaf:
        print(-1)
        exit()
    if v[i] > nleaf:
        v[i] = nleaf
    nleaf = v[i] + a[i]
    ans += nleaf
print(ans)
Buggy python submission (verdict: Runtime Error):
ACGT = ["A", "C" ,"G", "T"]
s = input()
ans = 0, temp = 0
for i in s:
  ok = False
  for j in ACGT:
    if i == j:
      ok = True
      temp += 1
  if ok == False:
    ans = max(ans, temp)
    temp = 0
ans = max(ans, temp)
print(ans)

Fixed submission:
ACGT = ["A", "C" ,"G", "T"]
s = input()
ans = 0
temp = 0
for i in s:
  ok = False
  for j in ACGT:
    if i == j:
      ok = True
      temp += 1
  if ok == False:
    ans = max(ans, temp)
    temp = 0
ans = max(ans, temp)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = map(int,input().split())
if sum(l) > 2*max(l):
    print("Yes")
else:
    print("No")

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
if sum(l) > 2*max(l):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
cnt = 0
for i in range(1,400):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    prnt("No")

Fixed submission:
a,b = map(str,input().split())
cnt = 0
for i in range(1,400):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    print("No")

Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
cnt = 0
for i in range(1,101):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    prnt("No")

Fixed submission:
a,b = map(str,input().split())
cnt = 0
for i in range(1,400):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
sum = 0
n = int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans = math.gcd(i,j)
            ans = math.gcd(ans, k)
            sum += ans
print(sum)

Fixed submission:
import math
sum = 0
n = int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans = math.gcd(i,j)
            ans = math.gcd(ans, k)
            sum += ans
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
tmp = n
while True:
    tmp = n
    n = abs(n-k)
    if tmp<n:
        n = tmp
        break
print(n) 
    

Fixed submission:
n, k = map(int, input().split())
tmp = n
n = n%k
while True:
    tmp = n
    n = abs(n-k)
    if tmp<n:
        n = tmp
        break
print(n)
Buggy python submission (verdict: Runtime Error):
n,k = list(map(int, input().split()))
h = list(map(int, input().split()))
count = 0
for i in range(h):
    if h[i] >= k:
        count += 1
print(count)

Fixed submission:
n,k = list(map(int, input().split()))
h = list(map(int, input().split()))
count = 0
for i in range(len(h)):
    if h[i] >= k:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = input().split()
    b = input().split()
    c = input().split()
    score = 0
    for i in range(n):
        num = int(a[i])
        next = int(a[i-1])
        score += int(b[num-1])
        if next - num == 1:
            score += int(c[num-1])
    print(score)

if __name__ == "__main__":
    main()

Fixed submission:
n = int(input())
password = n**3
print(password)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))    
    score = 0
    pre = -1
    for i in a:
        score += b[i]
        if(i==pre+1):
            score += c[i-2]
            pre=i
    print(score)

if __name__ == "__main__":
    main()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))    
    score = 0
    pre = -1
    for i in a:
        score += b[i]
        if(i==pre+1):
            score += c[i-2]
            pre =i
    print(score)

if __name__ == "__main__":
    main()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = int(input().split())
    b = int(input().split())
    c = int(input().split())
    score = 0
    for i in range(n):
        score += b[a[i]]
        if a[i+1] - a[i] == 1:
            score += c[a[i]-1]
    print(score)

if __name__ == "__main__":
    main()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = input().split()
    b = input().split()
    c = input().split()
    score = 0
    for i in range(n):
        score += a[i]
        if a[i+1] - a[i] == 1:
            score += b[i]
    print(score)

if __name__ == "__main__":
    main()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)
Buggy python submission (verdict: Runtime Error):
corners = input()
sides = list(map(int, input().split))
sides = sorted(sides)
for i in (corners-1):
    nums += sides[i+1]
if nums > sides[0]:
    print("Yes")
else:
    print("No")

Fixed submission:
corners = int(input())
sides = list(map(int, input().split()))
re_sides = sorted(sides, reverse=True)
nums = 0
for i in range(corners-1):
    nums += re_sides[i+1]
if nums > re_sides[0]:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
corners = input()
sides = list(map(int, input().split))
sides = sorted(sides)
for i in (corners-1):
    nums += sides[i+1]
if nums > sides[0]:
    print("Yes")
else:
    print("No")

Fixed submission:
corners = int(input())
sides = list(map(int, input().split()))
re_sides = sorted(sides, reverse=True)
nums = 0
for i in range(corners-1):
    nums += re_sides[i+1]
if nums > re_sides[0]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = int(input())
if s == s.lower():
    print('a')
else:
    print('A')


Fixed submission:
s = input()
if s == s.lower():
    print('a')
else:
    print('A')
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = []
for _ in range(N): S.append(input()))

print('AC x', S.count('AC'))
print('WA x', S.count('WA'))
print('TLE x', S.count('TLE'))
print('RE x', S.count('RE'))


Fixed submission:
N = int(input())
S = []
for _ in range(N): S.append(input())

print('AC x', S.count('AC'))
print('WA x', S.count('WA'))
print('TLE x', S.count('TLE'))
print('RE x', S.count('RE'))
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
A = int(A)
B = float(B)
ans = int(A * B)
print(ans)
A, B = input().split()
A = int(A)
B = float(B)
ans = int(A * B)
print(ans)


Fixed submission:
A, B = input().split()
A = int(A)
B = int(B.replace('.', ''))
ans = A * B // 100
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
r = int(str(N)[:-1])

if r in [2, 4, 5, 7]:
    print('hon')
elif r in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')



Fixed submission:
import sys
from collections import deque
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
r = -1
if 0 < N < 10:
    r = N
else:
    r = int(str(N)[-1])

if r in [2, 4, 5, 7, 9]:
    print('hon')
elif r in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')
Buggy python submission (verdict: Runtime Error):
def inp_list(): return list(map(int, sys.stdin.readline().split()))


X, Y, Z = inp_list()
print(Z, X, Y)


Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


X, Y, Z = inp_list()
print(Z, X, Y)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N, M = inp_list()
A = inp_list()
A.sort(reverse=True)
total = sum(A)

bd = total // (4 * M) + 1
if A[M - 1] <= bd:
    print('No')
else:
    print('Yes')


Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N, K = inp_list()

mod = N % K
sho = N // K

if mod == 0:
    print(0)
else:
    ans = min(abs(sho * K - N), abs((sho + 1) * K - N))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
        continue
    counts[a] = 1

# print(counts)

ans_memory = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    print(ans)


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

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1

# print(counts)

ans_memory = {}
ans_memory_val = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue
    if counts[A[k]] in ans_memory_val:
        print(ans_memory_val[counts[A[k]]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    ans_memory_val[counts[A[k]]] = ans
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
        continue
    counts[a] = 1

# print(counts)

for k in range(N):
    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    print(ans)


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

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1

# print(counts)

ans_memory = {}
ans_memory_val = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue
    if counts[A[k]] in ans_memory_val:
        print(ans_memory_val[counts[A[k]]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    ans_memory_val[counts[A[k]]] = ans
    print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if 4 * a * b < (c - a - b) ** 2):
    print('Yes')
else:
    print('No')


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

x = c - a - b
if x > 0 and 4 * a * b < x ** 2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
A = [[0] * 3] * 3

for i in range(3):
    a, b, c = map(int, input().split())
    A[i][0], A[i][1], A[i][2] = a, b, c

N = int(input())
B = [0] * N
for i in range(N):
    B[i] = int(input())

# input ここまで
import itertools
def flatten_list(l):
    return list(itertools.chain.from_iterable(l))

mark_list = [False] * 9

flatten_A = flatten_list(A)
for b in B:
    if not b in flatten_A: continue
    # 選ばれた数が自分のビンゴに含まれている
    for i in range(9):
        if flatten_A[i] == b:
            mark_list[i] = True

"""
[0, 1, 2], [3, 4, 5], [6, 7, 8]
[0, 3, 6], [1, 4, 7], [2, 5, 8]
[0, 4, 8], [2, 4, 6]
"""
def judge_bingo(l):
    yes = "Yes"
    no = "No"
    if l.count(True) < 3:
        return no
    if l[0] == 1:
        if (l[1] and l[2]) or (l[3] and l[6]) or (l[4] and l[8]):
            return yes
    if l[3] and l[4] and l[5]:
        return yes
    if l[1] and l[4] and l[7]:
        return yes
    if l[2]:
        if l[4] and l[6]: return yes
        if l[5] and l[8]: return yes
    if l[6] and l[7] and l[8]:
        return yes
    return no
        

ans = judge_bingo(mark_list)
print(ans)


Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N, M = inp_list()
s = [0] * M
c = [0] * M
for i in range(M): s[i], c[i] = inp_list()

if M == 0:
    if N == 1:
        print(0)
        exit()
    else:
        print(10 ** (N - 1))
        exit()


# N 桁の整数 10 ** (N - 1) ~ 10 ** N - 1 を全探索
for i in range(10 ** (N - 1) - 1, 10 ** N):
    if N != 1 and i == 10 ** (N - 1) - 1: continue
    i_str = str(i)
    for m in range(M):
        if i_str[s[m] - 1] != str(c[m]):
            break
        if m == M - 1:
            print(i)
            exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [''] * N
for i in range(N):
    S[i] = input()

dic = {'': 1, '': 1}
for i in range(N):
    if S[i] not in dic:
        dic[S[i]] = 1
    else:
        dic[S[i]] += 1

max_kv_list = [kv for kv in dic.items() if kv[1] == max(dic.values())]
max_k_list = sorted([t[0] for t in max_kv_list])

for w in max_k_list:
    print(w)



Fixed submission:
N = int(input())
ss = []
for _ in range(N): ss.append(input())

from collections import Counter

ctr = Counter(ss)
counted = ctr.most_common()
# print(counted)
ans = []
for i in range(len(counted)):
    tup = counted[i]
    if i == 0:
        ans.append(tup[0])
        continue
    if counted[i][1] != counted[i - 1][1]:
        break
    ans.append(tup[0])

ans.sort()
for a in ans: print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

frst_idx = 0
MAX = 0
for i in range(N - K + 1):
    MAX = max(MAX, (sum(p[i : i + K]) + K) * 0.5)
print(MAX)


Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

MAX = 0
# dp[i] i 番目から i + K - 1 番目までのサイコロの期待値の和
dp = [0] * N
for i in range(N - K + 1):
    if i < 1:
        dp[i] = 0.5 * (sum(p[:K]) + K)
    else:
        dp[i] = dp[i - 1] - 0.5 * p[i - 1] + 0.5 * p[i + K - 1]

    MAX = max(MAX, dp[i])
print(MAX)
Buggy python submission (verdict: Runtime Error):
k, x = mao(int, inout().split())
if 500*k < x: print("No")
else: print("Yes")
  

Fixed submission:
k, x = map(int, input().split())
if 500*k < x: print("No")
else: print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

count=0
for i in range(n-2):
  if s[i] = "A":
    if s[i+1] = "B":
      if s[i+2]="C":
        count += 1
print(count)

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

count = 0
for i in range(n - 2):
    if s[i] == 'A':
        if s[i + 1] == 'B':
            if s[i + 2] == 'C':
                count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)


Fixed submission:
from collections import  deque
import sys
import bisect
# import math
import itertools
from queue import deque
# from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

# def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for x in range(1, 50_000):
    if int(x * 1.08) == N:
        print(x)
        exit()
print(":(")


Fixed submission:
N = int(input())
for x in range(1, 50000):
    if int(x * 1.08) == N:
        print(x)
        exit()
print(":(")
Buggy python submission (verdict: Runtime Error):
s = input()
ww = ["Sunny", "Cloudy", "Rainy"]
for w in ww:
  if s == w[i]:
    if i == 2: j = 0
    else: j = i + 1
    print(w[j])
    break


Fixed submission:
s = input()
w = ["Sunny", "Cloudy", "Rainy"]
for i in range(3):
  if s == w[i]:
    if i == 2: j = 0
    else: j = i + 1
    print(w[j])
    break
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s1 = sum(a)
for i in range(n + 1):
    if i == 0:
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
    elif i == n:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
            b[i] = 0
    else:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
print(s1 - sum(a))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s1 = sum(a)
for i in range(n + 1):
    if i == 0:
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
    elif i == n:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
            b[i - 1] = 0
    else:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
print(s1 - sum(a))
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

for i in range(N):
    tmp = A[0:i] + A[i + 1:len(A)]
    print(max(tmp))


Fixed submission:

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

srtd = sorted(A)
for i in range(N):
    # print(str(i) + '番目')
    if srtd[-1] != A[i]:
        print(srtd[-1])
    else:
        print(srtd[-2])

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

for i in range(N):
    tmp = A[0:i] + A[i + 1:len(A)]
    print(max(tmp))


Fixed submission:

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

srtd = sorted(A)
for i in range(N):
    # print(str(i) + '番目')
    if srtd[-1] != A[i]:
        print(srtd[-1])
    else:
        print(srtd[-2])