Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02835 (python)

Fixed submission:
x,y,z= map(int,input().split())
if x+y+z>21:
    print("bust")
else:
    print("win")

Buggy submission (verdict: Runtime Error):
x,y,z= map(int,input().split())
if sum(x,y,z)>21:
    print("bust")
else:
    print("win")
Problem p02862 (python)

Fixed submission:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
M = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, M + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

a, b = map(int, input().split())
N = (a+b)//3
A = (N -abs(a-b))//2
B = (N +abs(a-b))//2
if (a+b)%3!=0 or A<0 :
    print(0)
else :
    print(cmb(N, A, p))

Buggy submission (verdict: Runtime Error):
from decimal import * 
import math
a,b,x = map(int,input().split())
X = x/a
P = X /(a*b)
if P >= 0.5 :
    print(math.degrees(math.atan((2*b*(1-P)/a))))
else:
    print(math.degrees(math.atan((a*b**2/(2*x)))))
Problem p03208 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n,m= map(int,input().split())
A = [ int(input()) for _ in range(n)]
a=sorted(A)
ans = 10 **10
for i in range(n-m+1):
    ans = min(abs(a[i+m-1] - a[i]),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m= map(int,input().split())

B = []
C = [0]*n
ans = 0
pna = 0
for i in range(m):
    A = list(map(str,input().split()))
    if A[0] not in B:
        if A[1]=="AC" :
            B.append(A[0])
            ans += 1
            pna += C[int(A[0])-1]
    	else:
      	  C[int(A[0])-1] += 1 
print(ans,pna)
Problem p03745 (python)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N):
    if P[i-1]>P[i] and flag == 0:
        flag = 1
    elif P[i-1]<P[i] and flag == 0:
        flag = 2
    elif flag == 1 and (P[i-1] < P[i]) :
        cnt += 1
        flag = 0
    elif flag == 2 and (P[i-1] > P[i]) :
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 #flag 0=,1=+,2=-
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 #flag 0=,1=+,2=-
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)
Problem p03785 (python)

Fixed submission:
#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np
import sys
import math
input = sys.stdin.readline
n,c,k = map(int,input().split())
A = [int(input()) for i in range(n)]
a = sorted(A)
ans = 0
time = 0.1 
num = 0
for i in range(n):
    if ans == 0:
        ans +=1
        time = a[0] 
        num +=1
    elif ans != 0 and a[i] <= time +k and num < c :
        num +=1
    elif  ans != 0 and (c <=num  or  time +k <=a[i]):
      
        time = a[i] 
        num = 1
        ans +=1
print(ans)

Buggy submission (verdict: Runtime Error):
input = sys.stdin.readline
n,c,k = map(int,input().split())
A = [int(input()) for i in range(n)]
a = sorted(A)
ans = 0
time = 0.1 
num = 0
for i in range(n):
    if ans == 0:
        ans +=1
        time = a[0] -0.1
        num +=1
    elif ans != 0 and a[i] < time +k and num < c :
        num +=1
    elif  ans != 0 and (c <=num  or  time +k <=a[i]):
      
        time = a[i] -0.1
        num = 1
        ans +=1
print(ans)
Problem p02729 (python)

Fixed submission:
def comb(val):
    if(val > 0):
        return int(val*(val-1) / 2)
    else:
        return 0

def main():
    args = input().rstrip().split(' ')
    N, M = int(args[0]), int(args[1])
    print(comb(N) + comb(M))
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def comb(val):
    if(val > 0):
        return int(val*(val-1) / 2)
    else:
        return 0
    
def make_map(balls):
    balls_map = {}
    for ball in balls:
        if(ball in balls_map):
            balls_map[ball] += 1
        else:
            balls_map[ball] = 1
    return balls_map

def main():
    args = input().rstrip().split(' ')
    N = int(args[0])
    balls = [val for val in input().rstrip().split(' ')]
    balls_map = make_map(balls)
    
    sum_ = 0
    for ball in balls:
        balls_map[ball] -= 1
        sum_ = 0
        for val in balls_map.values():
            sum_ += comb(val)
        print(sum_)
        balls_map[ball] += 1
    
if __name__ == "__main__":
    main()
Problem p02729 (python)

Fixed submission:
N,M = map(int,input().split())
 
if N>=2:
  gyu = N*(N-1)//2
else:
  gyu = 0
  
if M>=2:
  ki = M*(M-1)//2
else:
  ki = 0
 
print(gyu+ki)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input())

if N>=2:
  gyu = N*(N-1)//2
else:
  gyu = 0
  
if M>=2:
  ki = M*(M-1)//2
else:
  ki = 0

print(gyu+ki)
Problem p02759 (python)

Fixed submission:
N=int(input())
 
print(N//2+(N%2!=0))

Buggy submission (verdict: Runtime Error):
N=int(input())

print(N//2+(if N%2!=0))
Problem p02987 (python)

Fixed submission:
from collections import Counter as C
 
S = input()
 
c = C(S)
if len(c.keys())==2:
  if list(c.values())[0]==2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from collections import Counter as C

S = input()

c = C(S)
if len(c.keys())==2:
  if c.values[0]==2:
    print("Yes")
  else:
    print("No")
else:
  print("No")
Problem p03041 (python)

Fixed submission:
N,K = map(int,input().split())
S = list(input())
 
S[K-1]=S[K-1].lower()
print("".join(S))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()

S[K-1]=S[k-1].lower()
print(S)
Problem p03075 (python)

Fixed submission:
antena = [0]*5
for i in range(5):
  antena[i] = int(input())
  
k = int(input())
 
for i in range(len(antena)):
  if antena[-1]-antena[i]>k:
    print(":(")
    break
else:
  print("Yay!")

Buggy submission (verdict: Runtime Error):
antena = []
for i in range(5):
  antena[i] = int(input())
  
k = int(input())

for i in range(len(antena)):
  if antena[-1]-antena[i]>k:
    print(":(")
else:
  print("Yay!")
Problem p03135 (python)

Fixed submission:
T,X = map(int,input().split())

print(T/X)

Buggy submission (verdict: Runtime Error):
T,X = map(int,input())

print(T/X)
Problem p02622 (python)

Fixed submission:
def calculate(s,t):
    count = 0
    j = 0
    for i in s:
        if i != t[j]:
            count += 1
        j += 1
    return count
    
s = input()
t = input()
print(calculate(s,t))

Buggy submission (verdict: Runtime Error):
def calculate(s,t):
  count = 0
  for i in t:
    if i != s[j]:
      count += 1
    j += 1
  return count  


s = raw_input()
t = raw_input()
print(calculate(s,t))
Problem p02793 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

def main():
    n=int(input())
    a=list(map(int,input().split()))
    mod=pow(10,9)+7
    lcma={}
    for ai in a:
      f=factorization(ai)
      for fi in f:
        if fi[0] in lcma:
          lcma[fi[0]]=max(lcma[fi[0]],fi[1])
        else:
          lcma[fi[0]]=fi[1]
    l=1
    for k,v in lcma.items():
      l*=pow(k,v,mod)
      l%=mod
    ans=0
    for ai in a:
      ans+=l*pow(ai,mod-2,mod)
      ans%=mod
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import functools
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
    return functools.reduce(multiple, nums)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    # 方針1.dp[k] := A1~Akまでについて条件を満たすようなB1~Bkの総和..?
    # 方針2.A全体のlcmをxとすると、ans=Σ(i=[0,N])x/Ai
    ans = 0
    x = lcm(A)
    for a in A:
        ans += int(x/a)%MOD
        ans %= MOD
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import functools
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
    return functools.reduce(multiple, nums)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    # 方針1.dp[k] := A1~Akまでについて条件を満たすようなB1~Bkの総和..?
    # 方針2.A全体のgcdをxとすると、ans=Σ(i=[0,N])x/Ai
    ans = 0
    x = lcm(A)
    for a in A:
        ans += int(x/a)%MOD
        ans %= MOD
    print(ans)

main()
Problem p02688 (python)

Fixed submission:
N,K=map(int,input().split())
a=set([])
for i in range(K):
    d=int(input())
    L=list(map(int,input().split()))
    for x in L:
        a.add(x)
print(N-len(a))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a=set([])
for i in range(K):
    d=int(input())
    for i in range(d):
        L=list(map(int,input().split()))
        for x in L:
            a.add(x)
print(N-len(a))
Problem p02695 (python)

Fixed submission:
import itertools
N,M,Q=map(int,input().split())
v=[[] for _ in range(Q)]
o=0
for i in range(Q):
    v[i]=list(map(int,input().split()))
l=list(itertools.combinations(range(M-1+N), N))
for x in l:
    s=0
    a=[]
    for i in range(N):
        a.append(x[i]-i+1)
    for i in range(Q):
        if a[v[i][1]-1]-a[v[i][0]-1]-v[i][2]==0:
            s+=v[i][3]
    if s>o:
        o=s
print(o)

Buggy submission (verdict: Runtime Error):
N,M,Q=map(int,input().split())
v=[[] for _ in range(Q)]
o=0
for i in range(Q):
    v[i]=list(map(int,input().split()))
l=list(itertools.combinations(range(M+N), N))
for x in l:
    s=0
    a=[]
    for i in range(N):
        a.append(x[i]-i)
    for i in range(Q):
        if a[l[i][2]]-a[l[i][1]]-l[i][3]==0:
            s+=l[i][4]
    if s>o:
        o=s
print(o)

Buggy submission (verdict: Runtime Error):
import itertools
N,M,Q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
s=0
o=0
for i in range(Q):
    u,v,x,y=map(int,input().split())
    a.append(u)
    b.append(v)
    c.append(x)
    d.append(y)
for k in range(M):
    l=list(itertools.combinations(range(k+N), N))
    for x in l:
        s=0
        h=[]
        for i in range(N):
            h.append(x[i]-i)
        for i in range(Q):
            if h[a[i]]-h[b[i]]==c[i]:
                s+=d[i]
    if o<s:
        o=s
print(o)
Problem p02711 (python)

Fixed submission:
s=str(input())
if '7' in s:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=0
l=[0 for _ in range(K)]
for i in range(K):
    j=K-i
    v=(K//j)**N-l[j-1]
    for w in range(j//2):
        if j%(w+1)==0:
            l[w]+=v
    S+=j*v
print(S%(10**9+7))
Problem p03137 (python)

Fixed submission:
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort()

if N >= M:
    print(0)
    exit()

r = [X[i] - X[i-1] for i in range(1, M)]
r.sort(reverse=True)

print((X[-1] - X[0]) - sum(r[:N-1]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort()

if N >= M:
    print(0)
    exit()

li = [[0, 0]] * M
for i in range(1, M):
    li[i] = [i, X[i] - X[i-1]]
li.sort(key=lambda x: x[1], reverse=True)
cnt = 0
tmp = []
while cnt < N-1:
    tmp.append(li[cnt][0])
    cnt += 1
prev = 0
ans = 0
for t in tmp:
    ans += abs(X[t-1] - X[prev])
    prev = t
ans += abs(X[-1] - X[tmp[-1]])
print(ans)
Problem p03221 (python)

Fixed submission:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p].append(y)

for i in range(N+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p].append(y)

for i in range(M+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(M+1)]

for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p].append(y)

for i in range(M+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(M)]

for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Buggy submission (verdict: Runtime Error):
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n - 1
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Buggy submission (verdict: Runtime Error):
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

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

P = []
Y = []
PY = [[] for _ in range(M)]

for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = PY[P[i]-1].index(Y[i])
    print("%06d%06d" % (P[i], x + 1))
Problem p03252 (python)

Fixed submission:
S = input()
T = input()

dic = {}
dic_rev = {}


def solve():
    for s, t in zip(S, T):
        if t in dic.keys():
            if s != dic[t]:
                print('No')
                return
        else:
            dic[t] = s
    for s, t in zip(S, T):
        if s in dic_rev.keys():
            if t != dic_rev[s]:
                print('No')
                return
        else:
            dic_rev[s] = t
    print('Yes')
    return


solve()

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

dic = {}
dic_rev = {}


def solve():
    for s, t in zip(S, T):
        if t in dic.keys():
            if s != dic[t]:
                print('No')
                return
        else:
            dic[t] = s
    for s, t in zip(S, T):
        if t in dic_rev.keys():
            if t != dic_rev[s]:
                print('No')
                return
        else:
            dic_rev[s] = t
    print('Yes')
    return


solve()
Problem p03295 (python)

Fixed submission:
N, M = map(int, input().split())
a_b = []
for _ in range(M):
    a, b = map(int, input().split())
    a_b.append((a, b))
a_b.sort(key=lambda x: x[0])

r = a_b[0][1]
ans = 1
for a, b in a_b[1:]:
    if a >= r:
        r = b
        ans += 1
        continue
    if b < r:
        r = b
print(ans)

Buggy submission (verdict: Runtime Error):
a_b = []
for _ in range(M):
    a, b = map(int, input().split())
    a_b.append((a, b))
a_b.sort(key=lambda x: x[0])

r = a_b[0][1]
ans = 1
for a, b in a_b[1:]:
    if a >= r:
        r = b
        ans += 1
        continue
    if b < r:
        r = b
print(ans)
Problem p03805 (python)

Fixed submission:
def dfs(i):
    if all(visited):
        global ans
        ans += 1
        return
    for j in range(N):
        if g[i][j] and not visited[j]:
            visited[j] = True
            dfs(j)
            visited[j] = False

N, M = map(int, input().split())
g = [[False] * N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a-1][b-1] = True
    g[b-1][a-1] = True

ans = 0
visited = [False] * N
visited[0] = True
dfs(0)
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(i):
    if all(visited):
        global ans
        ans += 1
        return
    for j in range(N):
        if g[i][j] and not visited[j]:
            visited[j] = True
            dfs(j)
            visited[j] = False

N, M = map(int, input().split())
g = [[False] * M for _ in range(M)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a-1][b-1] = True
    g[b-1][a-1] = True

ans = 0
visited = [False] * N
visited[0] = True
dfs(0)
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(i):
    if all(visited):
        global ans
        ans += 1
        return
    for j in range(N):
        if g[i][j] and not visited[j]:
            visited[j] = True
            dfs(j)
            visited[j] = False
    return

N, M = map(int, input().split())
g = [[False] * M for _ in range(M)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a-1][b-1] = True
    g[b-1][a-1] = True

ans = 0
visited = [False] * N
visited[0] = True
dfs(0)
Problem p02624 (python)

Fixed submission:
N=int(input())
out=0
for X in range(1,N+1):
    Y=N//X
    out+=Y*(Y+1)*X/2
print(int(out))

Buggy submission (verdict: Runtime Error):
import sympy
N=int(input())
out=0
for i in range(1,N+1):
    out+=len(sympy.divisors(i))*i
print(out)

Buggy submission (verdict: Runtime Error):
import collections as col
import sympy
N=int(input())
out=0
for i in range(1,N+1):
    out+=len(sympy.divisors(i))*i
print(out)
Problem p03745 (python)

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

state_plus = False
state_minus = False
state_flat = True
count = 0

for i in range(N-1):
    # print(str(A[i]) + ',' + str(A[i + 1]))
    if state_flat:
        if A[i + 1] > A[i]:
            state_flat = False
            state_plus = True
        elif A[i + 1] < A[i]:
            state_flat = False
            state_minus = True
    elif state_plus:
        if A[i] > A[i + 1]:
            state_plus = False
            state_flat = True
            count += 1
    elif state_minus:
        if A[i] < A[i + 1]:
            state_minus = False
            state_flat = True
            count += 1
    # print(count)

print(count + 1)

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

que = A[0]
list_plus = False
list_minus = False
que_list = []

for i in A:
    if que < i:
        list_plus = True
        break
    elif que > i:
        list_minus = True
        break

if list_plus:
    for i in A:
        if A[i] < A[i-1]:
            len = i
            break
else:
    for i in A:
        if A[i] > A[i-1]:
            len = i
            break

# print(len)
s = N // len
a = N % len

print(s + a)

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

que = 0
list_plus = False
list_minus = False
que_list = []

for i in A:
    if que == 0:
        que = i
        que_list.append(i)
    elif que < i:
        list_plus = True
        que = i
        que_list.append(i)
    elif que > i:
        list_minus = True
        que = i
        que_list.append(i)

    if list_plus:
        if list_minus:
            len = len(que_list) - 1
            break
    else:
        if list_plus:
            len = len(que_list) - 1
            break

s = N // len
a = N % len

print(s + a)
Problem p02623 (python)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


def dfs(A_index, B_index, K, books):
    
    return_books = books
    return_booksA = books

    if N > A_index and K>=A[A_index]:
        return_books = dfs(A_index+1, B_index, K-A[A_index], books+1)
    if M > B_index and K>=B[B_index]:
        return_booksA = dfs(A_index, B_index+1, K-B[B_index], books+1)

    return max(return_books, return_booksA)

print(dfs(0, 0, K, 0))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


A_index=0
B_index=0
books = 0

while True:
    temp = books
    if N <= A_index and M <= B_index:
        break
    
    elif N <= A_index  and K>=B[B_index]:
        books += 1
        K -= B[B_index]
        B_index += 1
        
    elif M <= B_index  and K>=A[A_index]:
        books += 1
        K -= A[A_index]
        A_index += 1
        
    elif A[A_index] > B[B_index] and K>=B[B_index]:
        books += 1
        K -= B[B_index]
        B_index += 1
        
    elif A[A_index] < B[B_index] and K>=A[A_index]:
        books += 1
        K -= A[A_index]
        A_index += 1
    if temp==books:
        break
print(books)