Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter 

n = int(input())
li = list()
for _ in range(n):
    li.append(input())
a = Counter(li)
m = [x[0] for x in a.items() if x[1] == max(a.values())]
m.sort()
for i in m:
    print(i)

Fixed submission:
import collections

n = int(input())
mozi = list()
for i in range(n):
    mozi.append(input())

c = collections.Counter(mozi)
m = max(c.values())
c = sorted(c.items())

for i in c:
    if (i[1] == m):
        print(i[0])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mozi = list()
for i in range(n):
    mozi.append(input())
mozi.sort()
li = list()

for i in mozi:
    if not i in li:
        li.append(i)
kazu = list()

for i in li:
    kazu.append(mozi.count(i))

m = [i for i ,x in enumerate(kazu) if x == max(kazu)]

for i in m:
    print(li[i])

Fixed submission:
import collections

n = int(input())
mozi = list()
for i in range(n):
    mozi.append(input())

c = collections.Counter(mozi)
m = max(c.values())
c = sorted(c.items())

for i in c:
    if (i[1] == m):
        print(i[0])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mozi = list()
for i in range(n):
    mozi.append(input())
mozi.sort()
li = list()
for i in range(n):
    if not mozi[i] in li:
        li.append(mozi[i])
kazu = list()
for i in li:
    kazu.append(mozi.count(i))
m = [i for i ,x in enumerate(kazu) if x == max(kazu)]
for i in m:
    print(li[i],end=" ")

Fixed submission:
import collections

n = int(input())
mozi = list()
for i in range(n):
    mozi.append(input())

c = collections.Counter(mozi)
m = max(c.values())
c = sorted(c.items())

for i in c:
    if (i[1] == m):
        print(i[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = [int(x) for x in input().split()]

sub = list()
for i in li:
    if i in sub:
        print("NO")
        break
    sub.append(i)
else:
    print("YES")

Fixed submission:
n = int(input())
li = [int(x) for x in input().split()]

nozoki = list(set(li))
nozoki.sort()
li.sort()
if (nozoki == li):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
h = int(input())


li = list()
ans = 0
def dfs(x):
    global ans
    ans += 1
    if x == 1:
        return
    else:
        dfs(x//2)
        dfs(x//2)

dfs(h)
print(ans)

Fixed submission:
h = int(input())

ans = 0
count = 0
while h>=1:
    count += 1
    ans += 2 ** (count-1)
    h //= 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = [int(x) for x in input().split()]
ans = 1
for i in range(1,n):
    if min(li[:i+1])>=li[i]:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
li = [int(x) for x in input().split()]
ans = 1
m = li[0]
for i in range(1,n):
    if m>li[i]:
        m = li[i]
    if m==li[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()

def mod_nCr(n,k,mod):
    a = 1
    for i in range(n-k+1,n+1):
        a = a*i%mod
    b = 1
    for i in range(1,k+1):
        b = b*pow(i,mod-2,mod)%mod
    return a*b%mod

mod = 10**9+7
ans = 0
for i in range(k-1,n)[::-1]:
    ans += a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
a.reverse()
for i in range(k-1,n)[::-1]:
    ans -= a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
print(ans%mod)

Fixed submission:
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()

def mod_nCr(n,k,mod):
    r = min(k,n-k)
    return fact[n]*factinv[k]*factinv[n-k]%mod

mod = 10**9+7
fact = [1,1]
inv = [0,1]
factinv = [1,1]
for i in range(2,n+1):
    fact.append(fact[-1]*i%mod)
    inv.append((-inv[mod%i]*(mod//i))%mod)
    factinv.append((factinv[-1]*inv[-1])%mod)
    
ans = 0
for i in range(k-1,n)[::-1]:
    ans += a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
a.reverse()
for i in range(k-1,n)[::-1]:
    ans -= a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

d0 = [0]*100
d1 = [0]*100
for i in range(n):
    for j in range(61):
        if a[i] & (1<<j):
            d1[j] += 1
        else:
            d0[j] += 1

x = 1
ans = 0
mod = 10**9+7
for i in range(100):
    ans += x * d0[i] * d1[i] %mod
    x = x * 2 % mod
    ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

d0 = [0]*100
d1 = [0]*100
for i in range(n):
    for j in range(61):
        if a[i] & (1<<j):
            d1[j] += 1
        else:
            d0[j] += 1

x = 1
ans = 0
mod = 10**9+7
for i in range(100):
    ans += x * d0[i] * d1[i] %mod
    x = x * 2 % mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g = [[] for x in range(n+1)]
s = []
for _ in range(n-1):
    a,b = [int(x) for x in input().split()]
    g[a].append(b)
    g[b].append(a)
    s.append([a,b])

from collections import deque
color = [[-1]*(n+1) for x in range(n+1)]
index = []
q = deque()
q.append([1,0])
ans = 0
while q:
    num = 0
    p = q.popleft()
    for i in g[p[0]]:
        if color[p[0]][i]==-1:
            num += 1
            if p[1]==num:
                num += 1
            color[p[0]][i] = num
            color[i][p[0]] = num
            q.append([i,num])
            ans = max(ans,num)

print(ans)
for a,b in s:
    print(color[a][b])
    

Fixed submission:
n = int(input())
g = [[] for _ in range(n)]
z = []
for _ in range(n-1):
    a,b = [int(x)-1 for x in input().split()]
    g[a].append(b)
    g[b].append(a)
    if a<b:
        z.append((a,b))
    else:
        z.append((b,a))

from collections import deque

parent = [0]*n
mc = 0
en = dict()

q = deque()
used = [0]*n
q.append(0)
used[0] = 1
while q:
    p = q.popleft()
    color = 0
    for i in g[p]:
        if used[i] != 1:
            color += 1
            used[i] = 1
            if color==parent[p]:
                color += 1
            if p<i:
                en[(p,i)]=color
            else:
                en[(i,p)]=color
            parent[i] = color
            q.append(i)
    mc = max(mc,color)

print(mc)
for i in z:
    print(en[i])
Buggy python submission (verdict: Runtime Error):
import math
import fractions
import sys

sys.setrecursionlimit(10**8)
a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)

Fixed submission:
from fractions import gcd

a,b = [int(x) for x in input().split()]

def prime_factor(n):
    x = int(n**0.5)
    res = [1]
    for i in range(2,x+1):
        if n%i==0:
            while n%i==0:
                n //= i
            res.append(i)
    if n!=1:
        res.append(n)
    return res

z = gcd(a,b)
print(len(prime_factor(z)))

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

a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)

Fixed submission:
from fractions import gcd

a,b = [int(x) for x in input().split()]

def prime_factor(n):
    x = int(n**0.5)
    res = [1]
    for i in range(2,x+1):
        if n%i==0:
            while n%i==0:
                n //= i
            res.append(i)
    if n!=1:
        res.append(n)
    return res

z = gcd(a,b)
print(len(prime_factor(z)))

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

a,b = [int(x) for x in input().split()]
x = fractions.gcd(a,b)

is_prime = [1]*(x+1)
is_prime[0] = 0
is_prime[1] = 0
ans = 1
for i in range(2,x+1):
    if is_prime[i]:
        if x%i==0:
            ans += 1
        for j in range(2*i,x+1,i):
            is_prime[j] = 0
print(ans)

Fixed submission:
from fractions import gcd

a,b = [int(x) for x in input().split()]

def prime_factor(n):
    x = int(n**0.5)
    res = [1]
    for i in range(2,x+1):
        if n%i==0:
            while n%i==0:
                n //= i
            res.append(i)
    if n!=1:
        res.append(n)
    return res

z = gcd(a,b)
print(len(prime_factor(z)))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = list(input())
R = []
L = []
flag = 1 #1...R 0...L
lf = 1
rf = 1
if s[0]=="L":
    flag = 0
    lf = 0
if s[-1]=="L":
    rf = 0
count = 1
for i in range(n):
    if i==n-1:
        if flag==1:
            R.append(count*(-1))
            break
        else:
            L.append(count*(-1))
            break
    if s[i]==s[i+1]:
        count += 1
    elif flag==1:
        R.append(count*(-1))
        flag = 0
        count = 1
    else:
        L.append(count*(-1))
        flag = 1
        count = 1

import heapq
ans = 0
if s.count("R")>s.count("L"):
    ans += sum(R)*(-1)-len(R)
    copy_L = [x for x in L]
    heapq.heapify(L)
    for i in range(k):
        x = heapq.heappop(L)
        if lf==0 and x==copy_L[0] and copy_L.count(x)==1:
            ans += x*(-1)
        elif rf==0 and x==copy_L[-1] and copy_L.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) +1
else:
    ans += sum(L)*(-1)-len(L)
    copy_R = [x for x in R]
    heapq.heapify(R)
    for i in range(k):
        x = heapq.heappop(R)
        if lf==1 and x==copy_R[0] and copy_R.count(x)==1:
            ans += x*(-1)
        elif rf==1 and x==copy_R[-1] and copy_R.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) + 1 

print(ans)

Fixed submission:
n,k = [int(x) for x in input().split()]
s = input()
count = 1
for i in range(n-1):
    if s[i]!=s[i+1]:
        count += 1
print(n-max(1,count-2*k))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(x) for x in input().split()]
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = [int(x)-1 for x in input().split()]
    G[a].append(b)
    G[b].append(a)
count = [0]*n
for _ in range(q):
    a,b = [int(x) for x in input().split()]
    a -= 1
    count[a] += b

from collections import deque
ans = [0]*n
q = deque()
used = [0]*n
q.append(0)
used[0]=1
ans[0] += count[0]

while q:
    p = q.popleft()
    for i in G[p]:
        if used[i]!=1:
            used[i]=1
            ans[i]+=ans[p]+count[i]
            q.append(i)

an = ""
for i in ans:
    an += str(i) + " "
print(an)

Fixed submission:
n,q = [int(x) for x in input().split()]
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = [int(x)-1 for x in input().split()]
    G[a].append(b)
    G[b].append(a)
count = [0]*n
for _ in range(q):
    a,b = [int(x) for x in input().split()]
    a -= 1
    count[a] += b

from collections import deque
ans = [0]*n
q = deque()
used = [0]*n
q.append(0)
used[0]=1
ans[0] += count[0]

while q:
    p = q.popleft()
    for i in G[p]:
        if used[i]!=1:
            used[i]=1
            ans[i]+=ans[p]+count[i]
            q.append(i)

for i in ans:
    print(i,end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

dp = [float("inf")]*(n+k)
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+k+1):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[min(j,n-1)]))
print(dp[n-1])

Fixed submission:
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if i>=j:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]
dp = [float("inf")]*(n+10)
dp[0] = 0
for i in range(n):
    if i<n-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i<n-2:      
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[n-1])

Fixed submission:
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for j in range(1,k+1):
        if i>=j:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,wei = [int(x) for x in input().split()]
w = []
v = []
for _ in range(n):
    a,b = [int(x) for x in input().split()]
    w.append(a)
    v.append(b)
dp = [[-1]*(wei+1) for x in range(n+1)]
for i in range(wei+1):
    dp[0][i] = 0

for i in range(n):
    for j in range(wei+1):
        if j<w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])

print(dp[n][wei])

Fixed submission:
n,wei = [int(x) for x in input().split()]
w = []
v = []
for _ in range(n):
    a,b = [int(x) for x in input().split()]
    w.append(a)
    v.append(b)
dp = [[-1]*(wei+1) for x in range(n+1)]
for i in range(wei+1):
    dp[0][i] = 0

for i in range(n):
    for j in range(wei+1):
        if j<w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])

print(dp[n][wei])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
b = [0]
for i in range(n):
    b.append(a[i] + b[i])
s = set(b)
ans = 0
for i in s:
    x = b.count(i)
    ans += x * (x-1) /2
print(int(ans))

Fixed submission:
import numpy as np
from collections import Counter

n = int(input())
a = [0]+[int(x) for x in input().split()]

b = np.cumsum(a)
count = Counter(b)
ans = 0
for i in count.values():
    ans += i*(i-1)/2
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy

def is_prime(n):
    if (n==1):
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if (n % i == 0):
            return 0
    return 1

prime = [0]*(10**5+1)
for i in range(1,10**5+1):
    prime[i] = is_prime(i)

q = int(input())
li = [0]*(10**5+1)
for i in range(1,10**5+1):
    if (i%2 == 1):
        if (prime[i] and prime[int((i+1)/2)]):
            li[i] = 1

com = numpy.cumsum(li)
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(com[r]-com[l-1])

Fixed submission:
import math
import numpy

def is_prime(n):
    if (n==1):
        return 0
    if (n==2):
        return 1
    for i in range(3,int(math.sqrt(n))+1,2):
        if (n % i == 0):
            return 0
    return 1

prime = [0]*(10**5+1)
for i in range(1,10**5+1,2):
    prime[i] = is_prime(i)
prime[2] = 1

q = int(input())
li = [0]*(10**5+1)
for i in range(1,10**5+1):
    if (i%2 == 1):
        if (prime[i] and prime[int((i+1)/2)]):
            li[i] = 1

com = numpy.cumsum(li)
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(com[r]-com[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy

def is_prime(n):
    if (n==1):
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if (n % i == 0):
            return 0
    return 1

q = int(input())
li = [0]*(10**5+1)
for i in range(1,10**5+1):
    if (i%2 == 1):
        if (is_prime(i) and is_prime((i+1)/2)):
            li[i] = 1

com = numpy.cumsum(li)
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(com[r]-com[l-1])

Fixed submission:
import math
import numpy

def is_prime(n):
    if (n==1):
        return 0
    if (n==2):
        return 1
    for i in range(3,int(math.sqrt(n))+1,2):
        if (n % i == 0):
            return 0
    return 1

prime = [0]*(10**5+1)
for i in range(1,10**5+1,2):
    prime[i] = is_prime(i)
prime[2] = 1

q = int(input())
li = [0]*(10**5+1)
for i in range(1,10**5+1):
    if (i%2 == 1):
        if (prime[i] and prime[int((i+1)/2)]):
            li[i] = 1

com = numpy.cumsum(li)
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(com[r]-com[l-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N<(10**6):
	a=(10**N)%(10**9+7)
	b=(9**N)%(10**9+7)
	c=(8**N)%(10**9+7)
	print((a+c-2*b)%(10**9+7))
else:
	print((a+c-2*b)%(10**9+7))
	




Fixed submission:
N = int(input())
a=(10**N)%(10**9+7)
b=(9**N)%(10**9+7)
c=(8**N)%(10**9+7)
print((a+c-2*b)%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans=0
for i in range(1,N+1):
	n=N//i
	ans+=int(i*(n+1)*n/2)

print(ans)

# 2darray [[0] * 4 for i in range(3)]
# import itertools

Fixed submission:
N = int(input())

ans=0
for i in range(1,N+1):
	n=N//i
	ans+=i*(n+1)*n/2

print(int(ans))

# 2darray [[0] * 4 for i in range(3)]
# import itertools
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
a_ls=list(map(int, input().split()))

j=1
step=0
s=set([])
l=[]
loop_s=-1
loop_g=-1

while True:
	s.add(j)
	l+=[j]
	j=a_ls[j-1] #update
	if j in l:
		loop_s=l.index(j)
		loop_g=len(l)
		break


#print(l)
#print(loop_s)
#print(loop_g)

if K<loop_s:
	print(l[K])
elif (K+1-loop_s)%(loop_g-loop_s)!=0:
	print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1])
else:
	print(l[-1])



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

j=1
step=0
s=set([])
l=[]
loop_s=-1
loop_g=-1

while True:
	s.add(j)
	l+=[j]
	j=a_ls[j-1] #update
	if j in s:
		loop_s=l.index(j)
		loop_g=len(l)
		break


#print(l)
#print(loop_s)
#print(loop_g)

if K<loop_s:
	print(l[K])
elif (K+1-loop_s)%(loop_g-loop_s)!=0:
	print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1])
else:
	print(l[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
import numpy as np
a_ls=np.array(list(map(int, input().split())))


t=1
track=[]
while not(t in set(track)):
	track+=[t]
	t=a_ls[t-1]

#print(track)
#print(t)
#print(track.index(t)) #dokokara loop ga hajimaruka

if track.index(t)>K:
	print(track[K])
else:
	s=(K-track.index(t))%(len(track)-track.index(t))
	print(track[s+track.index(t)])



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

j=1
step=0
s=set([])
l=[]
loop_s=-1
loop_g=-1

while True:
	s.add(j)
	l+=[j]
	j=a_ls[j-1] #update
	if j in s:
		loop_s=l.index(j)
		loop_g=len(l)
		break


#print(l)
#print(loop_s)
#print(loop_g)

if K<loop_s:
	print(l[K])
elif (K+1-loop_s)%(loop_g-loop_s)!=0:
	print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1])
else:
	print(l[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
import numpy as np
a_ls=np.array(list(map(int, input().split())))


t=1
track=[]
while not(t in track):
	track+=[t]
	t=a_ls[t-1]

#print(track)
#print(t)
#print(track.index(t)) #dokokara loop ga hajimaruka

if track.index(t)>K:
	print(track[K])
else:
	s=(K-track.index(t))%(len(track)-track.index(t))
	print(track[s+track.index(t)])


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

j=1
step=0
s=set([])
l=[]
loop_s=-1
loop_g=-1

while True:
	s.add(j)
	l+=[j]
	j=a_ls[j-1] #update
	if j in s:
		loop_s=l.index(j)
		loop_g=len(l)
		break


#print(l)
#print(loop_s)
#print(loop_g)

if K<loop_s:
	print(l[K])
elif (K+1-loop_s)%(loop_g-loop_s)!=0:
	print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1])
else:
	print(l[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q=map(int, input().split())

a_ls=[]
b_ls=[]
c_ls=[]
d_ls=[]

for vnwrjvnwakn in range(Q):
	abcd=list(map(int, input().split()))
	a_ls+=[abcd[0]]
	b_ls+=[abcd[1]]
	c_ls+=[abcd[2]]
	d_ls+=[abcd[3]]



import itertools
As=itertools.combinations_with_replacement(range(1,M+1),N)
ans=0
for A in As:
	score=0
	for i in range(Q):
		if list(A)[b_ls[i]-1]-list(A)[a_ls[i]-1]==c_ls[i]:
			score+=d_ls[i]
	
	ans=max(ans,score)


print(ans)


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

a_ls=[]
b_ls=[]
c_ls=[]
d_ls=[]

for vnwrjvnwakn in range(Q):
	abcd=list(map(int, input().split()))
	a_ls+=[abcd[0]]
	b_ls+=[abcd[1]]
	c_ls+=[abcd[2]]
	d_ls+=[abcd[3]]



import itertools
As=itertools.combinations_with_replacement(range(1,M+1),N)
ans=0
for A in As:
	score=0
	Als=list(A)
	for i in range(Q):
		if Als[b_ls[i]-1]-Als[a_ls[i]-1]==c_ls[i]:
			score+=d_ls[i]
	
	ans=max(ans,score)


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

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = deque(a)
b = deque(b)
t = 0
ans = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        if t+b[0] > k:
            break
        ans += 1
        t += b.popleft()
    elif len(b) == 0:
        if t+a[0] > k:
            break
        ans += 1
        t += a.popleft()
    else:
        if a[0] < b[0]:
            if t+a[0] > k:
                break
            ans += 1
            t += a.popleft()
        elif a[0] > b[0]:
            if t+b[0] > k:
                break
            ans += 1
            t += b.popleft()
        else:
            if len(a) == 1:
                if t+b[0] > k:
                    break
                ans += 1
                t += b.popleft()
            elif len(a) == 1:
                if t+a[0] > k:
                    break
                ans += 1
                t += a.popleft()
            else:
                if a[1] < b[1]:
                    if t+a[0] > k:
                        break
                    ans += 1
                    t += a.popleft()
                else:
                    if t+b[0] > k:
                        break
                    ans += 1
                    t += b.popleft()
print(ans)

Fixed submission:
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = deque(a)
b = deque(b)
t = 0
book = deque()
while len(b):
    if b[0]+t <= k:
        t += b[0]
        book.append(b.popleft())
    else:
        break
nn = len(book)
# 逆じゅん
new_book = deque()
for i in range(nn):
    new_book.append(book.pop())
book = new_book
# aも詰め込めるだけ
while len(a):
    if a[0]+t <= k:
        t += a[0]
        book.append(a.popleft())
    else:
        break
ans = len(book)
for i in range(nn):
    t -= book.popleft()
    while len(a) and t+a[0]<=k:
        ta = a.popleft()
        t += ta
        book.append(ta)
    ans = max(ans, len(book))

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

n, m = map(int, input().split())
to = [[] for _ in range(m)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b)
    to[b].append(a)

visited = [False for _ in range(n)]

visited[0] = True
ans = [-1 for _ in range(n)]
d = deque()
d.append(0)
while len(d) > 0:
    now = d.popleft()
    for v in to[now]:
        if ans[v] > -1:
            continue
        ans[v] = now
        d.append(v)

print("Yes")
for i in range(1, len(ans)):
    print(ans[i]+1)





Fixed submission:
from collections import deque

n, m = map(int, input().split())
to = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b)
    to[b].append(a)

ans = [-1 for _ in range(n)]
d = deque()
d.append(0)
while len(d) > 0:
    now = d.popleft()
    for v in to[now]:
        if ans[v] > -1:
            continue
        ans[v] = now
        d.append(v)

print("Yes")
for i in range(1, len(ans)):
    print(ans[i]+1)
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N, M = map(int, input().split())
candi = [True for _ in range(101010)]
for d in make_divisors(N):
    if d > 1:
        candi[d] = False

ans = []
l, r = 1, N
for i in range(M):
    if not candi[r-l]:
        while not candi[r-l]:
            r -= 1
    ans.append([l, r])
    l += 1
    r -= 1

for i in range(M):
    print(" ".join(map(str, ans[i])))

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

ans = []
if M%2 == 0:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
        ans.append([M+i, 2*M+2-i])
else:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
    for i in range(1, (M+1)//2+1):
        ans.append([M+i, 2*M+2-i])

for i in range(len(ans)):
    print(*ans[i])