Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()

class RL():
  def __init__(self, ind, r, l):
    self.ind = ind
    self.r = r
    self.l = l
  
  def calc(self):
      return [1 + self.r // 2 + (self.l // 2 + 1 if self.l % 2 == 1 else self.l // 2), 1 + self.l // 2 + (self.r // 2 + 1 if self.r % 2 == 1 else self.r // 2)]
  
  def __str__(self):
    return f'{self.ind}: r {self.r} l {self.l}'


r = 0
l = 0
ind = 0
rl = False

rls = {}

for i, c in enumerate(s):
  if c == 'R' and not rl:
    r += 1
    continue
  if c == 'R' and rl:
    rls[ind - 1] = RL(ind - 1, r - 1, l)
    r = 1
    l = 0
    rl = False
    continue
  if c == 'L' and not rl:
    ind = i
    rl = True
    continue
  if c == 'L' and rl:
    l += 1
    continue

rls[ind - 1] = (RL(ind - 1, r - 1, l))

ans = []

skip = False

for i in range(len(s)):
  if skip:
    skip = False
    continue
  if i in rls:
    skip = True
    ans += rls[i].calc()
  else:
    ans.append(0)

print(' '.join(map(str, ans)))



Fixed submission:
s = input()

class RL():
  def __init__(self, ind, r, l):
    self.ind = ind
    self.r = r
    self.l = l
  
  def calc(self):
      return [1 + self.r // 2 + (self.l // 2 + 1 if self.l % 2 == 1 else self.l // 2), 1 + self.l // 2 + (self.r // 2 + 1 if self.r % 2 == 1 else self.r // 2)]



r = 0
l = 0
ind = 0
rl = False

rls = {}

for i, c in enumerate(s):
  if c == 'R' and not rl:
    r += 1
    continue
  if c == 'R' and rl:
    rls[ind - 1] = RL(ind - 1, r - 1, l)
    r = 1
    l = 0
    rl = False
    continue
  if c == 'L' and not rl:
    ind = i
    rl = True
    continue
  if c == 'L' and rl:
    l += 1
    continue

rls[ind - 1] = (RL(ind - 1, r - 1, l))

ans = []

skip = False

for i in range(len(s)):
  if skip:
    skip = False
    continue
  if i in rls:
    skip = True
    ans += rls[i].calc()
  else:
    ans.append(0)

print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))

cnt = 0
d = 0

while(x >= d):
  d += l[cnt]
  cnt += 1

print(cnt)

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

cnt = 1
d = 0

while(True):
  if cnt - 1 == n:
    break
  d += l[cnt - 1]
  if d > x:
    break
  cnt += 1

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

nega = sorted(list(filter(lambda x: x < 0, a)))
posi = sorted(list(filter(lambda x: x >= 0, a)), reverse=True)

selected = []

for i in range(n - 1):
  if len(nega) == 0:
    (x, y) = posi[0], posi[-1]
    posi = posi[1:-1]
    selected.append((x, y))
    nega.append(x - y)
  elif len(posi) == 0:
    (x, y) = nega[0], nega[-1]
    nega = nega[1:-1]
    selected.append((x, y))
    posi.append(x - y)
  else:
    if len(nega) >= len(posi):
      (x, y) = posi.pop(), nega.pop()
      selected.append((x,y))
      posi.append(x - y)
    else:
      (x, y) = nega.pop(), posi.pop()
      selected.append((x, y))
      nega.append(x - y)

if len(nega) == 1:
  print(nega[0])
else:
  print(posi[0])

for (x, y) in selected:
  print(f'{x} {y}')


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

a.sort()

posi = [a[-1]]
nega = [a[0]]

for n in a[1:-1]:
  if n < 0:
    nega.append(n)
  else:
    posi.append(n)

selected = []
ans = nega[0]

for n in posi[1:]:
  (x, y) = ans, n
  ans = x - y
  selected.append((x, y))

nega.append(ans)

ans = posi[0]
for n in nega[1:]:
  (x, y) = ans, n
  ans = x - y
  selected.append((x, y))

print(ans)

for (x, y) in selected:
  print(str(x) + ' ' + str(y))

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

nega = sorted(list(filter(lambda x: x < 0, a)))
posi = sorted(list(filter(lambda x: x >= 0, a)), reverse=True)

selected = []

for i in range(n - 1):
  if len(nega) == 0:
    (x, y) = posi[0], posi[-1]
    posi = posi[1:-1]
    selected.append((x, y))
    nega.append(x - y)
  elif len(posi) == 0:
    (x, y) = nega[0], nega[-1]
    nega = nega[1:-1]
    selected.append((x, y))
    posi.append(x - y)
  else:
    if len(nega) >= len(posi):
      (x, y) = posi.pop(), nega.pop()
      selected.append((x,y))
      posi.append(x - y)
    else:
      (x, y) = nega.pop(), posi.pop()
      selected.append((x, y))
      nega.append(x - y)

if len(nega) == 1:
  print(nega[0])
else:
  print(posi[0])

for (x, y) in selected:
  print(f'{x} {y}')


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

a.sort()

posi = [a[-1]]
nega = [a[0]]

for n in a[1:-1]:
  if n < 0:
    nega.append(n)
  else:
    posi.append(n)

selected = []
ans = nega[0]

for n in posi[1:]:
  (x, y) = ans, n
  ans = x - y
  selected.append((x, y))

nega.append(ans)

ans = posi[0]
for n in nega[1:]:
  (x, y) = ans, n
  ans = x - y
  selected.append((x, y))

print(ans)

for (x, y) in selected:
  print(str(x) + ' ' + str(y))
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = [0] * n

for i in range(0, n):
  a[i] = int(input())

a.sort()

c = 0

if len(a) == 2:
  print(abs(a[0] - a[1]))

if len(a) == 3:
  diff = abs(a[0] - a[1]) + abs(a[1] - a[2])
  diff = max(abs(a[0] - a[2]) + abs(a[1] - a[2]), diff)
  diff = max(abs(a[0] - a[2]) + abs(a[0] - a[1]), diff)
  print(diff)

mini = 0
maxi = len(a) - 1

if len(a) > 3:
  (l, r) = (a[maxi], a[maxi - 1])
  maxi -= 2
  diff = abs(a[0] - l) + abs(a[0] - r)
  mini += 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c < 2:
        diff += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c < 2:
        diff += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0
  
  maxi = len(a) - 1
  mini = 0
  (l, r) = (a[mini], a[mini + 1])
  mini += 2
  diff2 = abs(a[-1] - l) + abs(a[-1] - r)
  maxi -= 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c > 1:
        diff2 += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c > 1:
        diff2 += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0

  print(max(diff, diff2))



Fixed submission:
s = input()

if len(s) == 2:
  print(s)
else:
  print(s[2] + s[1] + s[0])
Buggy python submission (verdict: Runtime Error):
import statistics

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

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


a.sort()
med = statistics.median(a)

n = 0

for ai in a:
  n += abs(ai - med)

print(n)


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

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


a.sort()
med = a[len(a) // 2]

n = 0

for ai in a:
  n += abs(ai - med)

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

for i in range(N-1):
    if H[i] - H[i+1] > 1:
        print('No')
        exit()

print('Yes')

Fixed submission:
A,B,C = map(int, input().split())

print(C - min(A-B, C))
Buggy python submission (verdict: Time Limit Exceeded):
# 桁DP: 

S = input()
N = len(S)
mod = 10**9+7

# dp[前方からの桁数][13で割ったあまり] := 個数 
dp = [[0] * 13 for _ in range(N+1)]

dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k * 10 + int(S[i])) % 13] += dp[i][k] % mod

print(dp[N][5] % mod)


Fixed submission:
# 桁DP: 

S = input()
N = len(S)
mod = 10**9+7

# dp[前方からの桁数][13で割ったあまり] := 個数 
dp = [[0] * 13 for _ in range(N+1)]

dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k * 10 + int(S[i])) % 13] += dp[i][k] % mod

print(dp[N][5] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())

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


_max = max(A)

for i in range(N):
    if A[i] == _max:
        _A = copy.deepcopy(A)
        del _A[i]
        print(max(_A))

    else:
        print(_max)
        

Fixed submission:
import copy

N = int(input())

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


max1 = max(A)

max_i = A.index(max1)
max2 = max(A[:max_i] + A[max_i+1:])


for i in range(N):
    if A[i] == max1:
        print(max2)

    else:
        print(max1)
Buggy python submission (verdict: Runtime Error):
import bisect
from collections import deque

N = int(input())

tops = deque()

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        bisect.insort_left(tops, a)
    else:    
        tops[p-1] = a
        
print(len(tops))


Fixed submission:
import bisect
from collections import deque

N = int(input())

tops = deque() 

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        tops.appendleft(a)
    else:    
        tops[p-1] = a
        
print(len(tops))

Buggy python submission (verdict: Runtime Error):
import bisect
from collections import deque

N = int(input())

tops = deque()

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        bisect.insort_left(tops, a)
    else:    
        tops[p-1] = a
        
print(len(tops))


Fixed submission:
import bisect
from collections import deque

N = int(input())

tops = deque() 

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        tops.appendleft(a)
    else:    
        tops[p-1] = a
        
print(len(tops))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())

tops = []

for i in range(N):
    a = int(input())
    # 二分探索
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        bisect.insort_left(tops, a)
    else:    
        tops[p-1] = a
        
print(len(tops))


Fixed submission:
import bisect
from collections import deque

N = int(input())

tops = deque() 

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        tops.appendleft(a)
    else:    
        tops[p-1] = a
        
print(len(tops))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())

tops = []

for i in range(N):
    a = int(input())
    # 二分探索
    # aより小さい値の中で最大値の添え字 + 1
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        bisect.insort_left(tops, a)
    else:    
        tops[p-1] = a
        
print(len(tops))


Fixed submission:
import bisect
from collections import deque

N = int(input())

tops = deque() 

for i in range(N):
    a = int(input())
    p = bisect.bisect_left(tops, a)
    
    if p == 0:
        tops.appendleft(a)
    else:    
        tops[p-1] = a
        
print(len(tops))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

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

a0 = A[0]
c = A[1]
b = a0 ^ a1

f = True

for i in range(3, N):
    if i % 3 == 0 and a != A[i]:
        f = False
    elif i % 3 == 1 and b != A[i]:
        f = False
    elif i % 3 == 2 and c != A[i]:
        f = False

if f:
    print('Yes')
else:
    print('No')


Fixed submission:
from collections import defaultdict

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

dic = defaultdict(int)


# 3の倍数個
if N % 3 == 0:
    
    for a in A:
        dic[a] += 1

    n_kind = len(dic.keys())
    values = list(dic.keys())
    cnts = list(dic.values())
        
    # 整数の種類数で分岐
    if n_kind == 3:
        is_xor = False    
        # 3つの整数で xorの関係を作れるか判定
        for i in range(n_kind-2):
            for j in range(i+1, n_kind-1):
                for k in range(j+1, n_kind):
                    if values[i] ^ values[j] ^ values[k] == 0:
                        is_xor = True

        
        # 3つの整数がそれぞれ N/3個であるか判定
        is_n_valid = True
        for cnt in cnts:
            if cnt != N/3:
                is_n_valid = False

            
        if is_xor and is_n_valid:
            print('Yes')
        else:
            print('No')
    
    elif n_kind == 2:
        
        # 2つの整数がそれぞれ 2N/3個であり、0がN/3子であるか判定
        is_n_valid = True
        if 0 in values:
            for k, v in dic.items():
                if k == 0:
                    if v != N/3:
                        is_n_valid = False
                else:
                    if v != N * (2/3):
                        is_n_valid = False
        else:
            is_n_valid = False

        if is_n_valid:
            print('Yes')
        else:
            print('No')


    elif n_kind == 1:
        all_zero = True
        for a in A:
            if a != 0:
                all_zero = False

        if all_zero:
            print('Yes')
        else:
            print('No')        

    else:
        print('No')

# 3の倍数個以外の場合は、全て0である必要がある
else:
    all_zero = True
    for a in A:
        if a != 0:
            all_zero = False

    if all_zero:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

mod = 2019
R = min(R, R + mod + 1)

ans = 100000000+5
for i in range(L, R):
    for j in range(i+1, R+1):
        ans = min(ans, i * j % mod)

print(ans)


Fixed submission:
# [i, j] の中に2019の倍数があれば、その倍数を選択すれば最小値を0

import math

L, R = map(int, input().split())
mod = 2019

# (A * B) % mod = (A % mod) * (B % mod) % mod
l = L % 2019
r = R % 2019

ans = None
# mod以上差があれば2019の倍数を含んでいる (ex. 2 & 2025)
if R - L >= mod:
    ans = 0
else:
    # mod以上差がなくても、あまりが0をまたぐ (ex. 2018 & 2025 => 2018 & 6) 場合
    if l > r:
        ans = 0
    else:
        _min = 2019 * 2019
        for i in range(l, r):
            for j in range(i+1, r+1):
                _min = min(_min, i*j%mod)
        ans = _min

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

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

A, B, C, D = map(int, input().split())

# 0 => A-1 で割りきれる
cnt_c = (A-1) // C
cnt_d = (A-1) // D

cnt_cd = (A-1) // lcm(C, D)

cnt_a = cnt_c + cnt_d - cnt_cd

# 0 => Bで割りきれる
cnt_c2 = B // C
cnt_d2 = B // D
cnt_cd2 = B // lcm(C, D)

cnt_b = cnt_c2 + cnt_d2 - cnt_cd2

cnt_ab = cnt_b - cnt_a

cnt_n = B - A + 1

print(cnt_n - cnt_ab)

Fixed submission:
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

A, B, C, D = map(int, input().split())

# 0 => A-1 で割りきれる
cnt_c = (A-1) // C
cnt_d = (A-1) // D

cnt_cd = (A-1) // lcm(C, D)

cnt_a = cnt_c + cnt_d - cnt_cd

# 0 => Bで割りきれる
cnt_c2 = B // C
cnt_d2 = B // D
cnt_cd2 = B // lcm(C, D)

cnt_b = cnt_c2 + cnt_d2 - cnt_cd2

cnt_ab = cnt_b - cnt_a

cnt_n = B - A + 1

print(cnt_n - cnt_ab)
Buggy python submission (verdict: Runtime Error):
from collections import deque


def Fibonacci(n): 
    if n<0: 
        print("Incorrect input") 
    # First Fibonacci number is 0 
    elif n==1: 
        return 1
    # Second Fibonacci number is 1 
    elif n==2: 
        return 2
    else: 
        return Fibonacci(n-1)+Fibonacci(n-2) 
        

N, M = map(int, input().split())

A = deque()

for _ in range(M):
    A.append(int(input()))

pos = 0
diff = []
la = None

for a in A:
    if la and a - la == 1:
        print(0)
        exit()
    d = (a) - pos
    diff.append(d)
    pos = a
    la = a

# 最後の階段
diff.append(N - pos)
diff = list(filter(lambda x: False if x <= 0 else True, diff))
F = [Fibonacci(d) for d in diff]

_sum = 1
for f in F:
    _sum *= f

print(_sum // 1000000007)

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

broken = [0 for _ in range(n+1)]
for i in range(m):
    a = int(input())
    broken[a] = True

    
mod = 1000000007
dp = [0 for _ in range(n+2)]

dp[n] = 1
for i in range(n-1, -1, -1):
    if(broken[i]):
        dp[i] = 0
        continue

    dp[i] = (dp[i+1] + dp[i+2]) % mod

print(dp[0])

Buggy python submission (verdict: Runtime Error):
from collections import deque


def Fibonacci(n): 
    if n<0: 
        print("Incorrect input") 
    # First Fibonacci number is 0 
    elif n==1: 
        return 1
    # Second Fibonacci number is 1 
    elif n==2: 
        return 2
    else: 
        return Fibonacci(n-1)+Fibonacci(n-2) 
        

N, M = map(int, input().split())

A = deque()

for _ in range(M):
    A.append(int(input()))

pos = 0
diff = []

for a in A:
    d = (a - 1) - pos
    diff.append(d)
    pos = a + 1

# 最後の階段
diff.append(N - pos)

diff = list(filter(lambda x: False if x <= 0 else True, diff))

F = [Fibonacci(d) for d in diff]

_sum = 1
for f in F:
    _sum *= f

print(_sum)

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

broken = [0 for _ in range(n+1)]
for i in range(m):
    a = int(input())
    broken[a] = True

    
mod = 1000000007
dp = [0 for _ in range(n+2)]

dp[n] = 1
for i in range(n-1, -1, -1):
    if(broken[i]):
        dp[i] = 0
        continue

    dp[i] = (dp[i+1] + dp[i+2]) % mod

print(dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

gates = []
for i in range(M):
    gates.append(tuple(map(int, input().split())))


s = set(range(gates[0][0], gates[0][-1] + 1)) 
for g in gates[1:]:
    tmp_s = set(range(g[0], g[-1] + 1))
    s = s.intersection(tmp_s)

print(len(s))

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

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

l_max = max(L)
r_min = min(R)

if l_max <= r_min:
    print(r_min - l_max + 1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()


BC = [[bc[1]] * bc[0] for bc in BC]
BC = [flat_bc for bc in BC for flat_bc in bc]

BC.sort(key=lambda x:x[1])
BC = BC[-N:]


for i in range(N):
    if A[i] < BC[-1]:
        A[i] = BC[-1]
        BC.pop()
        if not BC:
            break

print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1], reverse=True)

D = deque([])
for bc in BC:
    b = bc[0]
    c = bc[1]

    for _ in range(b):
        D.append(c)

    if len(D) >= N: 
        break

for i in range(N):
    if A[i] < D[0]:
        A[i] = D[0]
        D.popleft()
        if not D:
            break

print(sum(A))

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

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1])

BC = [[bc[1]] * bc[0] for bc in BC]
BC = [flat_bc for bc in BC for flat_bc in bc]

for i in range(N):
    if A[i] < BC[-1]:
        A[i] = BC[-1]
        BC.pop()
        if not BC:
            break

print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1], reverse=True)

D = deque([])
for bc in BC:
    b = bc[0]
    c = bc[1]

    for _ in range(b):
        D.append(c)

    if len(D) >= N: 
        break

for i in range(N):
    if A[i] < D[0]:
        A[i] = D[0]
        D.popleft()
        if not D:
            break

print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1])

BC = [[bc[1]] * bc[0] for bc in BC]
BC = [flat_bc for bc in BC for flat_bc in bc]

for i in range(N):
    if A[i] < BC[-1]:
        A[i] = BC[-1]
        BC.pop()

print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1], reverse=True)

D = deque([])
for bc in BC:
    b = bc[0]
    c = bc[1]

    for _ in range(b):
        D.append(c)

    if len(D) >= N: 
        break

for i in range(N):
    if A[i] < D[0]:
        A[i] = D[0]
        D.popleft()
        if not D:
            break

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque

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

max_a = max(a)

def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)

ans = 0

if len(a) == 1:
    print(a[0])
    exit()

for i in range(n):
    _a = copy.deepcopy(a)

    del _a[i]

    que = deque(_a)

    while len(que) > 1:
        n = que.pop()
        m = que.pop()
        l = gcd(n, m)
        
        que.append(l)

    tmp_max = que.pop()
    ans = max(ans, tmp_max)

print(ans)

Fixed submission:
import copy

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

max_a = max(a)


def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)


# 事前処理
# あらかじめ、左端からi個でgcdを計算しておく
# 同様に右からも
l = [0] * n
r = [0] * n

l[0] = a[0]
r[-1] = a[-1]

for i in range(0, n-1):
    l[i+1] = gcd(l[i], a[i+1])

for i in range(n-1, 0, -1):
    r[i-1] = gcd(r[i], a[i-1])


tmp = 0
ans = 0

for i in range(n):
    if i == 0:
        tmp = r[i+1]
    elif i == n-1:
        tmp = l[i-1]
    else:
        tmp = gcd(l[i-1], r[i+1])
    
    ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = map(int, input())

now = 1
cnt = 0
nums = []

for i in range(n):
    if s[i] == now: cnt+=1
    else:
        nums.append(cnt)
        now = 1 - now  # 0, 1の切り替え
        cnt = 1  # カウントを始める

if cnt != 0: nums.append(cnt)

# 計算しやすさのため、1の個数-0の個数...1の個数という配列が欲しい
if (len(nums) % 2 == 0): nums.append(0)

add = 2 * k + 1
tmp_sum = 0

left = 0
right = 0

ans = 0

for i in range(0, n, 2):

    next_right = i
    next_left = min(i + add, n)

    while left < next_left:
        tmp_sum -= nums[left]
        left++

    while right < next_right:
        tmp_sum += nums[right]
        right++

    ans = max(tmp_sum, ans)

print(ans)


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

now = 1
cnt = 0
nums = []

for i in range(n):
    if s[i] == now: cnt+=1
    else:
        nums.append(cnt)
        now = 1 - now  # 0, 1の切り替え
        cnt = 1  # カウントを始める

if cnt != 0: nums.append(cnt)

# 計算しやすさのため、1の個数-0の個数...1の個数という配列が欲しい
if (len(nums) % 2 == 0): nums.append(0)

add = 2 * k + 1
tmp_sum = 0

left = 0
right = 0

ans = 0

for i in range(0, len(nums), 2):

    next_left = i
    next_right = min(i + add, len(nums))

    while left < next_left:
        tmp_sum -= nums[left]
        left+=1

    while right < next_right:
        tmp_sum += nums[right]
        right+=1

    ans = max(tmp_sum, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))[:k]

e = []

for va in a:
    for vb in b:
        e.append(va+vb)

e.sort(reverse=True)

e = e[:k]

d = []
for vc in c:
    for ve in e:
        d.append(vc+ve)

d.sort(reverse=True)
d = d[:k]

for vd in d:
    print(vd)

Fixed submission:
import math

n = int(input())

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

bn = min(a, b, c, d, e)

print(4 + math.ceil(n / bn))