Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=[int(input())  for i in  range(m)]
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Fixed submission:
n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=[int(input())  for i in  range(m)]
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  
print(dp[-1]%x)

Fixed submission:
n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=[int(input())  for i in  range(m)]
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
    
  if i-1 not in a:
    dp[i]+=dp[i-1]
  if i-2 not in a:
    dp[i]+=dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Fixed submission:
n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=[int(input())  for i in  range(m)]
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    if i+1 in a:
      print(0)
      exit()
    dp[i]=0
    continue
    
  if i-1 not in a:
    dp[i]+=dp[i-1]
  if i-2 not in a:
    dp[i]+=dp[i-2]
  
print(dp[-1]%x)

Fixed submission:
n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)
Buggy python submission (verdict: Runtime Error):
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]


for i in range(32):
    x = '{:0>6}'.format(bin(i).split('b')[1])
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)

Fixed submission:
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]

r = 2 ** n

for i in range(r):
    x = str(bin(i).split('b')[1]).zfill(n + 1)
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)

Buggy python submission (verdict: Runtime Error):
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]


for i in range(32):
    x = '{:0>6}'.format(bin(i).split('b')[1])
    s=list(x)
    s= [int(s) for s in s]
    #print(i, l)
    if check(m) == 1:
            inc +=1
    
print(inc)

Fixed submission:
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]

r = 2 ** n

for i in range(r):
    x = str(bin(i).split('b')[1]).zfill(n + 1)
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int, input().split())
ans=0
for i in range(3001):
  for j in range(3001):
    v=i*r + j*g
    #print((n-v)/b)
    if n>=v:
      if (n-v)%b == 0:
        ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int, input().split())
ans=0
for i in range(3001):
  for j in range(3001):
    v=i*r + j*g
    #print((n-v)/b)
    if n>=v:
      if (n-v)%b == 0:
        ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int, input().split())
ans=0
for i in range(3001):
  for j in range(3001):
    v=i*r + j*g
    #print((n-v)/b)
    if n>=v and (n-v)%b == 0:
      ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int, input().split())
ans=0
for i in range(3001):
  for j in range(3001):
    v=i*r + j*g
    #print((n-v)/b)
    if n>=v:
      if (n-v)%b == 0:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
s=input()
check="keyence"
tmp=0
if check in s:
  print("YES")
  exit()
for i in s:
  if i == check[tmp]:
    tmp+=1
  else:
    break
tmp2=copy.copy(tmp)
for i in s[tmp:]:
  if i != check[tmp]:
    tmp2+=1
  else:
    break

if tmp2 == len(s):
  print("NO")
  exit()

for i in s[tmp2:]:
  if i == check[tmp]:
    tmp+=1
  else:
    print("NO")
    exit()
print("YES")

Fixed submission:
import copy
s=input()
check="keyence"
tmp=6
sNow=0
cNow=0
#一度目のチェック
for i in s:
  sNow+=1
  if i == check[cNow]:
    cNow+=1
  else:
    break
#最初に見つかれば終了
if cNow == 7:
  print("YES")
  exit()

#print(check[cNow:], s[-1*(7-cNow):])
"""
sの最後が"keyence"の残りの文字と一致すればOK
例：keyaence
最初の"key"は合っているので，残りは"aence"の内"a"を除いたもの
cNow=3, 7-cNow=4
後ろの４文字が"ence"ならばYESとなる
"""
if check[cNow:] == s[-1*(7-cNow):]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[0]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])

for i in range(k,n):
  min=abs(h[i]-h[i-k])+dp[i-k]
  
  for ik in range(i-1,i-k-1,-1):
    if min >= abs(h[i]-h[ik])+dp[ik]:  
      min=abs(h[i]-h[ik])+dp[ik]
  dp[i]=min
  
print(dp[-1])

Fixed submission:
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[0]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
  
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])

for i in range(k,n):
  li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
  dp[i]=min(li)
  
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[(10**4)+1]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])

for i in range(n):
  if i+k+1<=n:
    max=k+1
  else:
    max=n-i
  for ik in range(1,max):
    if dp[i+ik] == (10**4)+1:
      dp[i+ik]=dp[i]+abs(h[i]-h[i+ik])
      continue
      
    if dp[i]+abs(h[i]-h[i+ik])<=dp[i+ik]:
      dp[i+ik]=dp[i]+abs(h[i]-h[i+ik])
    #print(dp)
    
print(dp[-1])

Fixed submission:
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[0]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
  
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])

for i in range(k,n):
  li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
  dp[i]=min(li)
  
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as C
s=list(input())
l=[]
ans=0
for i in range(len(s)):
  if s[i] == "W":
    l.append(i)
for i in l:
  #print(s[:i], C(s[:i])["B"])
  s[i]="_"
  ans+=C(s[:i])["B"]
print(ans)

Fixed submission:
s=list(input())
l=[]
ans=0
b=0
for i in range(len(s)):
  if s[i] == "W":
    ans+=b
  else:
    b+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]
#print(l)

s=set(l)
ans=0
s=set([i for i in s if l.count(i) > 1])
#print(s)
for i in s:
  ans+=comb(l.count(i), 2, exact=True)
print(ans)

Fixed submission:
from scipy.special import comb
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))

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

c=C(l)
ans=0

for v in c.values():
  ans+=comb(v, 2, exact=True)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]
#print(l)

s=set(l)
ans=0
for i in s:
  ans+=comb(l.count(i), 2, exact=True)
print(ans)

Fixed submission:
from scipy.special import comb
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))

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

c=C(l)
ans=0

for v in c.values():
  ans+=comb(v, 2, exact=True)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()

l=len(n)
if int(n)>9:
  ans=[9]
else:
  print(int(n))
  exit()
tmp=n[l-1]
for i in range(2,l+1):
  #print(tmp, int(n[l-i]))
  if int(tmp) != 9:
    tmp=int(n[l-i])-1
    #print("tmp:",tmp)
  if i==l:
    ans.append(tmp)
  else:
    ans.append(9)
  #print(ans)
print(sum(ans))

Fixed submission:
n=input()

l=len(n)
if int(n)>9:
  ans=[9]
else:
  print(int(n))
  exit()
tmp=n[l-1]
for i in range(2,l+1):
  #print(tmp, int(n[l-i]))
  if int(tmp) != 9:
    tmp=int(n[l-i])-1
    #print("tmp:",tmp)
  else:
    tmp=int(n[l-i])
  if i==l:
    ans.append(int(tmp))
  else:
    ans.append(9)
  #print(ans)
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
def otoshi(n, y):
    x=0
    for i in range(n+1):
        x = i*1000
        if x >= y :
            break
        for i2 in range(n+1 - i):
            x = i*1000 + i2 * 5000
            if x >= y :
                break
            for i3 in range(n+1 - (i+i2)):
                x =  i*1000 + i2 * 5000 + i3 *10000
                if x > y :
                    break
                
                if i + i2 + i3 != n :
                    pass
                else :
                    if x  == y :
                        print(i3, i2, i1)
                        return 
    
    print(-1, -1, -1)
    return 

n, y = [int(i)  for i in input().split()]

otoshi(n, y)

Fixed submission:
def otoshi(n, y):
    x=0
    for i in range(n+1):
        x = i*10000
        if x >y :
            break
        for i2 in range(n+1 - i):
            x = i*10000 + i2 * 5000
            if x > y :
                break
                
            i3 = n - i - i2
            x =  i*10000 + i2 * 5000 + i3 *1000
            if x > y :
                break

            if i + i2 + i3 != n :
                pass
            else :
                if x  == y :
                    print(i, i2, i3)
                    return 

    print(-1, -1, -1)
    return 

n, y = [int(i)  for i in input().split()]

otoshi(n, y)
Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
lr=[list(map(int,input().split())) for i in  range(q)]
MAX=10**5+1
l=[0]*MAX

def  is_prime(n):
	if n == 1:
		return  False

	for i in  range(2,int(n**0.5)+1):
		if n % i == 0:
			return  False
	return  True
  
for i in range(1, MAX, 2):
  if is_prime(i) and is_prime((i+1)/2):
    l[i]=1


for i in range(q):
  #print(l[:lr[i][1]+1],l[:lr[i][0]])
  print(sum(l[:lr[i][1]+1]) - sum(l[:lr[i][0]]))

Fixed submission:
q=int(input())
#lr=[list(map(int,input().split())) for i in  range(q)]
MAX=10**5+1
l=[0]*MAX

def  is_prime(n):
	if n == 1:
		return  False

	for i in  range(2,int(n**0.5)+1):
		if n % i == 0:
			return  False
	return  True
cnt=0
for i in range(1, MAX, 2):
  if is_prime(i) and is_prime((i+1)/2):
    l[i]=1
    
l2=[0]*(MAX+1)
for i in range(0, MAX):
  l2[i+1]=l2[i]+l[i]
#print(l2)

for i in range(q):
  l,r=map(int, input().split())
  r+=1
  print(l2[r]-l2[l])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < C(al)[i-1] + C(al)[i] + C(al)[i+1]:
    cnt = C(al)[i-1] + C(al)[i] + C(al)[i+1]

print(cnt)

Fixed submission:
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)
#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

print(cnt)

Buggy python submission (verdict: Runtime Error):
n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
  if cnt >= len(al) / 2
  break
print(cnt)

Fixed submission:
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)
#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
print(cnt)

Fixed submission:
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)
#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
print(cnt)

Fixed submission:
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)
#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

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

rate=[0]*9
over=0

for i in a:
  for j in range(1,9):
    if 400*(j-1) <= i < 400*j:
      rate[j]=1
      break
    elif i >= 3200:
      over+=1
      break

ansmin = rate.counta(1)
ansmax = rate.count(1)
if ansmin == 0:
  ansmin=1

if over > 0:
  ansmax = ansmax + over
    
#print(rate,over)
print(ansmin, ansmax)

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

rate=[0]*9
over=0

for i in a:
  for j in range(1,9):
    if 400*(j-1) <= i < 400*j:
      rate[j]=1
      break
    elif i >= 3200:
      over+=1
      break

ansmin = rate.count(1)
ansmax = rate.count(1)
if ansmin == 0:
  ansmin=1

if over > 0:
  ansmax += over
    
#print(rate,over)
print(ansmin, ansmax)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = [k for k,v in h_count.items() if v == max_h]
max_w_list = [k for k,v in w_count.items() if v == max_w]

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)

Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = set([k for k,v in h_count.items() if v == max_h])
max_w_list = set([k for k,v in w_count.items() if v == max_w])

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)

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

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = [k for k,v in h_count.items() if v == max_h]
max_w_list = [k for k,v in w_count.items() if v == max_w]

for h in max_h_list:
    for w in max_w_list:
        if [h, w] not in hw:
            print(ans)
            sys.exit()
print(ans - 1)

Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = set([k for k,v in h_count.items() if v == max_h])
max_w_list = set([k for k,v in w_count.items() if v == max_w])

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
def count_books(books, limit):
    num_books = len(books)
    total_time = 0
    for i, time in enumerate(books):
        if total_time + time > limit:
            num_books = i
            break
        total_time += time
    return [num_books, total_time]

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

    max_num_A, total_time_A = count_books(A, K)
    read_book_nums = [0] * (max_num_A + 1)

    remain = K - total_time_A
    num_B, total_time_B = count_books(B, remain)
    read_book_nums[-1] = max_num_A + num_B

    num_A = max_num_A
    for n in range(max_num_A-1, -1, -1):
        num_A -= 1
        remain += A[n-1]
        num_B, total_time_B = count_books(B, remain)
        read_book_nums[n] = num_A + num_B

    print(max(read_book_nums))
    
main()

Fixed submission:
def count_books(books, limit):
    num_books = len(books)
    total_time = 0
    for i, time in enumerate(books):
        if total_time + time > limit:
            num_books = i
            break
        total_time += time
    return [num_books, total_time]

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

    max_num_A, total_time_A = count_books(A, K)

    read_book_nums = [0] * (max_num_A + 1)

    remain = K - total_time_A
    num_B, total_time_B = count_books(B, remain)
    read_book_nums[-1] = max_num_A + num_B

    num_A = max_num_A
    m = 0
    total_time_B = 0
    for n in range(max_num_A-1, -1, -1):
        num_A -= 1
        remain += A[n]

        while m < M and total_time_B + B[m] <= remain:
            total_time_B += B[m]
            m += 1
        num_B = m

        read_book_nums[n] = num_A + num_B

    print(max(read_book_nums))
    
main()
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
P = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break

Fixed submission:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    if a == 0:
        print(0)
        sys.exit()
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
import sys

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

if 0 in A:
    print(0)
    sys.exit();

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
import sys

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

if 0 in A:
    print(0)
    sys.exit();

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys

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

if 0 in A:
    print(0)
    sys.exit();

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
ans = 1
for a in A:
    ans *= a
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys

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

if 0 in A:
    print(0)
    sys.exit();

ans = 1
for a in sorted(A, reverse=True):
    ans *= a
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)