Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

if x == 1:
    ans = 1
elif x == 2:
    ans = 2
else:    
    num = [3]
    for i in range(3, x, 2):
        for j in num:
            if (i % j) == 0:
                break
        else:
            num.append(i)
    last_num = i
    k = i + 1
    while True:
        for j in num:
            if (k % j) == 0:
                k += 1
                break
        else:
            ans = k
            break
print(ans)

Fixed submission:
# ABC149C
import math

def check_prime(num):
    for i in range(2, math.ceil(math.sqrt(num))):
        if num % i == 0:
            return False
    else:
        return True

x = int(input())
while True:
    if check_prime(x):
        print(x)
        break
    x += 1
Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
g = gcd(a, b)
ans = int(a * b / g)
print(ans)

Fixed submission:
# from math import gcd
from fractions import gcd

a, b = map(int, input().split())
g = gcd(a, b)
ans = int(a * b / g)
print(ans)

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

a, b = map(int, input().split())
g = math.gcd(a, b)
ans = int(a * b / g)
print(ans)

Fixed submission:
# from math import gcd
from fractions import gcd

a, b = map(int, input().split())
g = gcd(a, b)
ans = int(a * b / g)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

xy_arr = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = int(map(int, input().split()))
        xy_arr[i].append(x, y)
        
max_res = 0
for i in range(2 ** n):           
    ok_flg = True
    bin_i = format(i, "015b")[::-1]
                                    
        for j in range(n):
            for x, y in xy_arr[j]:　
                if bin_i[j] == 1 and y != int(bin_i[x - 1]):
                    ok_flg = False
                    break
            else:
                continue
            break
        
    if ok_flg:
        res = sum(int(x) for x in bin_i)
        mas_res = (max_res, res)
        
print(max_res)

Fixed submission:
n = int(input())

xy_arr = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        xy_arr[i].append((x, y))

max_res = 0
for i in range(2 ** n):           
    ok_flg = True
    bin_i = format(i, "015b")[::-1] 
                                    
    for j in range(n):
        for x, y in xy_arr[j]: 
            if bin_i[j] == "1" and y != int(bin_i[x - 1]):
                ok_flg = False
                break
        else:
            continue
        break
        
    if ok_flg:
        res = sum(int(x) for x in bin_i)
        max_res = max(max_res, res)
        
print(max_res)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n + 1))   
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)

Fixed submission:
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n) + 1)
x = np.arange(1, n_2)
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input()) 
s = input()

t = []
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        continue
    else:
        t.append(s[i - 1])
t.append(s[i])
print(len(t))

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

t = ""
cnt = 0
for i in s:
    if i != t:
        cnt += 1
        t = i
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = []
for _ in range(q):
    a.append(int(input()))

for i in range(n):
    num = 0
    for  cp in a:
        if cp == i + 1:
            num += 1
    if k <= q - num:
        print("No")
    else:
        print("Yes")

Fixed submission:
n, k, q = map(int, input().split())
a = [0] * n

for _ in range(q):
    a[int(input()) - 1] += 1

for i in range(n):
    if k - (q - a[i]) > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1, n):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        cnt += 1
print(cnt)

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

cnt = 0
for i in range(1, n - 1):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        cnt += 1
print(cnt)

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

cnt = 0
for i in range(1, n):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        print("==", i, "==")
        cnt += 1
print(cnt)

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

cnt = 0
for i in range(1, n - 1):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        cnt += 1
print(cnt)

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

cnt = 0
for i in range(1, n):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        print("==", i, "==")
        cnt += 1
print(cnt)


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

cnt = 0
for i in range(1, n - 1):
    if (p[i] - p[i - 1] > 0 and p[i + 1] - p[i] >= 0) or (p[i] - p[i - 1] <= 0 and p[i + 1] - p[i] < 0):
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math

n=int(input())
a_array=list(map(int,input().split()))
next_xor=[0 for _ in range(n-1)]
max_dig=math.floor(math.log2(a_array[0]))
for i in range(n-1):
    next_xor[i]=a_array[i]^a_array[i+1]
    max_dig=math.floor(math.log2(a_array[i+1]))
flag_1=True
ans_1=[0]
ans_2=[2<<max_dig]
SUP=10**9
for xo in next_xor:
    if ans_1[-1]^xo >= SUP:
        flag_1=False
    ans_1.append(ans_1[-1]^xo)
    ans_2.append(ans_2[-1]^xo)
print(" ".join(map(str,ans_1 if flag_1 else ans_2)))

Fixed submission:
n=int(input())
a_array=list(map(int,input().split()))
all_xor=0
for a in a_array:
    all_xor^=a
print(" ".join([str(all_xor^a) for a in a_array]))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7


def mod_pow(m, p):
    if p == 1:
        return m % mod
    return (mod_pow(m, p // 2) % mod) * (mod_pow(m, p - p // 2) % mod)


n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = mod_pow(k // i, n)
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % mod) * (gcd_dp[i] % mod)
    ret %= mod
print(ret)


Fixed submission:
Mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = pow(k // i, n, Mod)
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % Mod) * (gcd_dp[i] % Mod)
    ret %= Mod
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = (k // i) ** n
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % mod) * (gcd_dp[i] % mod)
    ret %= mod
print(ret)

Fixed submission:
Mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = pow(k // i, n, Mod)
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % Mod) * (gcd_dp[i] % Mod)
    ret %= Mod
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
magics = []
for i in range(n):
    a, b = map(int, input().split())
    magics.append((a, b))
h_table = [float("inf") for _ in range(h + 1)]
h_table[0] = 0
for i in range( h + 1):
    for a, b in magics:
        h_table[min(i + a, h)] = min(h_table[min(i + a, h)], h_table[i] + b)
print(h_table[h])


Fixed submission:
h, n = map(int, input().split())
magics = []
for i in range(n):
    a, b = map(int, input().split())
    magics.append((a, b))
h_table = [float("inf") for _ in range(h + 1)]
h_table[0] = 0
for i in range( h + 1):
    for a, b in magics:
        h_table[min(i + a, h)] = min(h_table[min(i + a, h)], h_table[i] + b)
print(h_table[h])
Buggy python submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
print((a * b) // math.gcd(a, b))

Fixed submission:
def gcd(n, m):
    r = n % m
    if r == 0:
        return m
    else:
        return gcd(m, r)


a, b = map(int, input().split())
print((a * b) // gcd(a, b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 2 == 1:
    print(0)
else:
    ans = 0
    n //= 2
    frac = 1
    for i in range(1, 26):
        frac *= 5
        ans += n // frac
print(ans)

Fixed submission:
n = int(input())
if n % 2 == 1:
    print(0)
else:
    ans = 0
    n //= 2
    frac = 1
    for i in range(1, 26):
        frac *= 5
        ans += n // frac
    print(ans)
Buggy python submission (verdict: Runtime Error):
h, w, a, b = map(int, input().split())
for i in ragne(b):
    for j in range(a):
        print(1,end="")
    for j in range(w-a):
        print(0,end="")
    print()
for i in range(w-b):
    for j in range(a):
        print(0,end="")
    for j in range(w-a):
        print(1,end="")
    print()

Fixed submission:
h, w, a, b = map(int, input().split())
for i in range(b):
    for j in range(a):
        print(0, end="")
    for j in range(w - a):
        print(1, end="")
    print()
for i in range(h - b):
    for j in range(a):
        print(1, end="")
    for j in range(w - a):
        print(0, end="")
    print()
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
p = map(int, input().split())
size = math.ceil(math.sqrt(n))
array = []
square = []
for i in range(size ** 2):
    if i < n:
        array.append(p.__next__())
    else:
        array.append(0)
for i in range(size):
    m1, m2 = max(array[i * size], array[i * size + 1]), min(array[i * size], array[i * size + 1])
    for j in range(2, size):
        if m1 < array[i * size + j]:
            m1, m2 = array[i * size + j], m1
        elif m2 < array[i * size + j]:
            m2 = array[i * size + j]
    square.append((m1, m2))
def second(l, r):
    _m1, _m2 = 0, 0
    for i in range(l, l + (-l % size)):
        if _m1 < array[i]:
            _m1, _m2 = array[i], _m1
        elif _m2 < array[i]:
            _m2 = array[i]
    for i in range(math.ceil(l / size), r // size):
        if _m1 < square[i][0]:
            _m1, _m2 = square[i][0], _m1
        elif _m2 < square[i][0]:
            _m2 = square[i][0]
        if _m1 < square[i][1]:
            _m1, _m2 = square[i][1], _m1
        elif _m2 < square[i][1]:
            _m2 = square[i][1]
    for i in range((r // size) * size, r):
        if _m1 < array[i]:
            _m1, _m2 = array[i], _m1
        elif _m2 < array[i]:
            _m2 = array[i]
    return _m2


ans = 0
for i in range(n - 1):
    for j in range(i + 2, n + 1):
        ans += second(i, j)
print(ans)

Fixed submission:
n=int(input())
print(n**3)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
cell = map(lambda x: {"B": True, "W": False}[x], input())
section = 0
ans = 1
for val in cell:
    if section % 2 == 0:
        buf = val
    else:
        buf = not val
    if buf:
        section += 1
    else:
        ans *= section
        section -= 1
if section == 0:
    print(((math.factorial(n) % (10 ** 9 + 7)) * (ans % (10 ** 9 + 7))) % (10 ** 9 + 7))
else:
    print(0)

Fixed submission:
import math

n = int(input())
cell = map(lambda x: {"B": True, "W": False}[x], input())
section = 0
ans = 1
for val in cell:
    if section % 2 == 0:
        buf = val
    else:
        buf = not val
    if buf:
        section += 1
    else:
        ans *= section
        ans %= 10 ** 9 + 7
        section -= 1
if section == 0:
    print(((math.factorial(n) % (10 ** 9 + 7)) * ans) % (10 ** 9 + 7))
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
cell = list(map(lambda x: {"B": True, "W": False}[x], input()))
section = 0
ans = 1
flag = True
for val in cell:
    buf = val if section % 2 == 0 else not val
    if buf:
        section += 1
    else:
        if section > 0:
            ans *= section
            section -= 1
        else:
            flag = False
            break
if section== 0 and flag:
    print((math.factorial(n)*ans)%(10**9+7))
else:
    print(0)

Fixed submission:
import math

n = int(input())
cell = map(lambda x: {"B": True, "W": False}[x], input())
section = 0
ans = 1
for val in cell:
    if section % 2 == 0:
        buf = val
    else:
        buf = not val
    if buf:
        section += 1
    else:
        ans *= section
        ans %= 10 ** 9 + 7
        section -= 1
if section == 0:
    print(((math.factorial(n) % (10 ** 9 + 7)) * ans) % (10 ** 9 + 7))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2*10**5)
def parent(array,count,index,root):
    array[index-1].remove(root)
    count[index-1]+=count[root-1]
    for i in array[index-1]:
        parent(array,count,i,index)
num,q=map(int,input().split())
counter=[0 for _ in range(num)]
roots=[set() for _ in range(num)]
for _ in range(num-1):
    a,b=map(int,input().split())
    roots[a-1].add(b)
    roots[b-1].add(a)
for _ in range(q):
    p,x=map(int,input().split())
    counter[p-1]+=x
for ele in roots[0]:
    parent(roots,counter,ele,1)
print(" ".join([str(counter[i]) for i in range(num)]))

Fixed submission:
a=int(input())
s=input()
if a >= 3200:
    print(s)
else:
    print("red")
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
exi={chr(97+i): False for i in range(26)}
jump={chr(97+i): [] for i in range(26)}
length=len(s)
pointer=0
flag=True
for i,ch in enumerate(s*2):
    exi[ch]=True
    jump[ch].append(i)
for i in range(26):
    if jump[chr(97+i)] !=[]:
        buf=[min(filter(lambda x:x>=j,jump[chr(97+i)]))-j+1 for j in range(length)]
    else:
        buf=0
    jump[chr(97+i)]=buf
for ch in t:
    if exi[ch]:
        pointer+=jump[ch][pointer%length]
    else:
        flag=False
        break
if flag:
    print(pointer)
else:
    print(-1)    

Fixed submission:
s=input()
t=input()
length=len(s)
exi={chr(97+i): False for i in range(26)}
jump={chr(97+i): [0 for _ in range(2*length)] for i in range(26)}
cru={chr(97+i):0 for i in range(26)}
pointer=0
flag=True
for i,ch in enumerate(s*2):
    exi[ch]=True
    for j in range(cru[ch],i+1):
        jump[ch][j]=1+i-j
    cru[ch]=i+1
for ch in t:
    if exi[ch]:
        pointer+=jump[ch][pointer%length]
    else:
        flag=False
        break
if flag:
    print(pointer)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
length=len(s)
pointer=0
flag=True
for string in t:
    count=0
    while flag and (string != s[pointer%length]):
        pointer+=1
        count+=1
        flag= not(count==length)
    if not flag:
        break
    count+=1
if flag:
    if pointer<length*10**100
    print(pointer+1)
else:
    print(-1)

Fixed submission:
s=input()
t=input()
length=len(s)
exi={chr(97+i): False for i in range(26)}
jump={chr(97+i): [0 for _ in range(2*length)] for i in range(26)}
cru={chr(97+i):0 for i in range(26)}
pointer=0
flag=True
for i,ch in enumerate(s*2):
    exi[ch]=True
    for j in range(cru[ch],i+1):
        jump[ch][j]=1+i-j
    cru[ch]=i+1
for ch in t:
    if exi[ch]:
        pointer+=jump[ch][pointer%length]
    else:
        flag=False
        break
if flag:
    print(pointer)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
k = int(input())
s = list(input())
if k=>len(s):
    print(s)
else print(s[for k i in range k+1]+"...")

Fixed submission:
k = int(input())
s =input()
if k>=len(s):
    print(s)
else:
    for i in range (k):
        print(s[i],end="")
    print("...")
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
if len(s)+1 ==len(t):
	if all(s[i]==t[i] for i in range(len(s))):
    	print("Yes")
else: print("No")


Fixed submission:
s = input()
t = input()
if len(s)+1 ==len(t) and all(s[i]==t[i] for i in range(len(s))):
    print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
if len(s)+1 ==len(t)
	if all(s[i]==t[i] for i in range(len(s))):
    	print("Yes")
else: print("No")

Fixed submission:
s = input()
t = input()
if len(s)+1 ==len(t) and all(s[i]==t[i] for i in range(len(s))):
    print("Yes")
else: print("No")

Buggy python submission (verdict: Runtime Error):
s = input()
p = input()
if p == s + -:
    print("Yes")
else: print("No")

Fixed submission:
s = input()
t = input()
if len(s)+1 ==len(t) and all(s[i]==t[i] for i in range(len(s))):
    print("Yes")
else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env Python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
modnum = 998244353

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

def mod(num):
    return num % modnum

S = []

for l, r in LR:
    for i in range(l, r + 1):
        if not i in S:
            S.append(i)

dp = [0] * N

dp[0] = 1

for i in range(1, N):
    for s in S:
        if not s > i:
            dp[i] = mod(dp[i] + dp[i - s])

print(dp[N-1])



Fixed submission:
#!/usr/bin/env Python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
modnum = 998244353

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

def mod(num):
    return num % modnum

dp = [0] * (N + 1)
sdp = [0] * (N + 1)

dp[1] = 1
sdp[1] = 1

for i in range(2, N + 1):
    for l, r in LR:
        ri = max(0, i - l)
        li = max(0, i - r - 1)

        dp[i] += sdp[ri] - sdp[li]
        dp[i] = mod(dp[i])

    sdp[i] = sdp[i - 1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
modnum = 998244353

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

def mod(num):
    return num % modnum

S = []

for l, r in LR:
    for i in range(l, r + 1):
        if not i in S:
            S.append(i)

dp = [0] * N

dp[0] = 1

for i in range(1, N):
    for s in S:
        if not s > i:
            dp[i] = mod(dp[i] + dp[i - s])

print(dp[N-1])



Fixed submission:
#!/usr/bin/env Python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
modnum = 998244353

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

def mod(num):
    return num % modnum

dp = [0] * (N + 1)
sdp = [0] * (N + 1)

dp[1] = 1
sdp[1] = 1

for i in range(2, N + 1):
    for l, r in LR:
        ri = max(0, i - l)
        li = max(0, i - r - 1)

        dp[i] += sdp[ri] - sdp[li]
        dp[i] = mod(dp[i])

    sdp[i] = sdp[i - 1] + dp[i]

print(dp[N])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, X, M = map(int, input().split())

def mod(x):
    return x % M

a = X

i = 0

ans = 0
last = -1

dic = []

while a != 0 and i < N:
    ans += a
    a = mod(a * a)
    i += 1    

    if a in dic:
        last = dic.index(a)
        break

    dic.append(a)


if i != N and dic[last] != 0:
    tdic = dic[last:]
    if N - i >= len(tdic):
        sdic = sum(tdic)
        ans += sdic * ((N - i) // len(tdic))

    for j in range((N - i) % len(tdic)):
        ans += tdic[j]

print(ans)

Fixed submission:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, X, M = map(int, input().split())

def mod(x):
    return x % M

a = X

i = 0

ans = 0
last = -1

dic = []

while a != 0 and i < N:
    ans += a
    a = mod(a * a)
    i += 1

    if a in dic:
        last = dic.index(a)
        break

    dic.append(a)


if i != N and a != 0:
    tdic = dic[last:]
    if N - i >= len(tdic):
        sdic = sum(tdic)
        ans += sdic * ((N - i) // len(tdic))

    for j in range((N - i) % len(tdic)):
        ans += tdic[j]

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

maxA = max(A) + 1

C = [0] * maxA

g = 0

for a in A:
    C[a] += 1
    g = math.gcd(g, a)

pairwise = True

for i in range(2, maxA):
    cnt = 0
    for j in range(i, maxA, i):
        cnt += C[j]

    if cnt > 1:
        pairwise = False

if pairwise:
    print("pairwise coprime")
    exit()

if g == 1:
    print("setwise coprime")

else:
    print("not coprime")

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

maxA = max(A) + 1

C = [0] * maxA

g = 0

for a in A:
    C[a] += 1
    g = math.gcd(g, a)

pairwise = True

for i in range(2, maxA):
    cnt = 0
    for j in range(i, maxA, i):
        cnt += C[j]

    if cnt > 1:
        pairwise = False

if pairwise:
    print("pairwise coprime")
    exit()

if g == 1:
    print("setwise coprime")

else:
    print("not coprime")
Buggy python submission (verdict: Runtime Error):
N = int(input())

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

money = 1000

for i in range(N):
    t = money + (A[i + 1] - A[i]) * (money // A[i])
    money = max(money, t)

print(money)

Fixed submission:
N = int(input())

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

money = 1000
kabu = 0

for i in range(len(A)-1):
    if kabu != 0:
        if A[i] >= A[i + 1]:
            money += kabu * A[i]
            kabu = 0

    else:
        if A[i] < A[i + 1]:
            kabu = money // A[i]
            money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

c = 0

while (True):
    if A[0] < B[0] and A[0] <= K:
        K -= A.pop(0)
        c += 1

    elif B[0] <= K:
        K -= B.pop(0)
        c += 1

    else:
        break

print(c)

Fixed submission:
def is_ok(arg):
    return not Alist[arg] <= t
    

def bisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

Alist = [0]
for i in range(N):
    Alist.append(Alist[i] + A[i])

ans = 0
for i in range(N+1):
    if Alist[i] <= K:
        ans = i
    else:
        break

b = 0
for i in range(M):
    b += B[i]
    t = K - b

    if t >= 0:
        res = bisect(N + 1, -1)
        ans = max(ans, i + res)

    else:
        break

print(ans)