Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Q =map(int,input().split())
bond = [[]for _ in range(N)]
for i in range(N-1):
    a,b = [int(i)-1 for i in input().split()]
    bond[a].append(b)
    bond[b].append(a)

#qu = [[int(i)for i in input().split()]for _ in range(Q)]
qlis = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    qlis[p-1] += x

que =[]
for i in bond[0]:
    que.append([0,i])
    bond[i].remove(0)

for _ in range(N-1):
    ue,sita = que.pop(0)
    for i in bond[sita]:
        que.append([sita,i])
        bond[i].remove(sita)
    qlis[sita] += qlis[ue]
anstr = " ".join([str(i)for i in qlis])
print(anstr)


Fixed submission:
import sys
input = sys.stdin.readline
N,Q =map(int,input().split())
bond = [[]for _ in range(N)]
for i in range(N-1):
    a,b = [int(i)-1 for i in input().split()]
    bond[a].append(b)
    bond[b].append(a)

qlis = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    qlis[p-1] += x

stat = [True]*N
stat[0] =False
que =[]
for i in bond[0]:
    que.append([0,i])

for _ in range(N-1):
    ue,sita = que.pop()
    if stat[sita]:
        for i in bond[sita]:
            if stat[i]:
                que.append([sita,i])
        qlis[sita] += qlis[ue]
    stat[sita] = False
anstr = " ".join([str(i)for i in qlis])
print(anstr)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Q =map(int,input().split())
bond = [[]for _ in range(N)]
for i in range(N-1):
    a,b = [int(i)-1 for i in input().split()]
    bond[a].append(b)
    bond[b].append(a)

#qu = [[int(i)for i in input().split()]for _ in range(Q)]
qlis = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    qlis[p-1] += x

ans = [0]*N
ans[0] += qlis[0]
que =[]
for i in bond[0]:
    que.append([0,i])
    bond[i].remove(0)

for _ in range(N-1):
    ue,sita = que.pop(0)
    for i in bond[sita]:
        que.append([sita,i])
        bond[i].remove(sita)
    ans[sita] = ans[ue]+qlis[sita]
anstr = " ".join([str(i)for i in ans])
print(anstr)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q =map(int,input().split())
bond = [[]for _ in range(N)]
for i in range(N-1):
    a,b = [int(i)-1 for i in input().split()]
    bond[a].append(b)
    bond[b].append(a)

qlis = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    qlis[p-1] += x

stat = [True]*N
stat[0] =False
que =[]
for i in bond[0]:
    que.append([0,i])

for _ in range(N-1):
    ue,sita = que.pop()
    if stat[sita]:
        for i in bond[sita]:
            if stat[i]:
                que.append([sita,i])
        qlis[sita] += qlis[ue]
    stat[sita] = False
anstr = " ".join([str(i)for i in qlis])
print(anstr)
Buggy python submission (verdict: Runtime Error):
N = int(input())
dic = {}
plis = [2]
for i in range(3,100):
    s =True
    for p in plis:
        if i%p==0:
            s = False
    if s:
        plis.append(i)
for i in range(N):
    foo = 1
    for j in input():
        j = ord(j) - ord("a")
        foo *= plis[j]
    try:
        dic[foo] += 1
    except:
        dic[foo] = 1
ans = 0
for n in dic.values():
    ans += n*(n-1)//2
print(ans)

Fixed submission:
N = int(input())
dic = {}
plis = [2]
for i in range(3,150):
    s =True
    for p in plis:
        if i%p==0:
            s = False
    if s:
        plis.append(i)
for i in range(N):
    foo = 1
    for j in input():
        j = ord(j) - ord("a")
        foo *= plis[j]
    try:
        dic[foo] += 1
    except:
        dic[foo] = 1
ans = 0
for n in dic.values():
    ans += n*(n-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
S = sum(A)

def searchPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

plis = searchPrimeNum(40000)

lis = []
for p in plis:
    if S%p == 0:
        lis.append([p,1])
        S = S//p
        while S%p == 0:
            lis[-1][1] += 1
            S = S//p
    if S == 1:
        break
if S != 1:
    lis.append([[S,1]])

yakulis =[1]
for l in lis:
    for j in range(len(yakulis)):
        for k in range(l[1]):
            n = yakulis[j]
            yakulis.append(l[0]**(k+1)*n)
yakulis.sort(reverse=True)

s = True
for r in yakulis:
    B = [i%r for i in A]
    B.sort()
    le = -1
    ri = N
    while ri-le > 1:
        mid = (le+ri)//2
        pl = sum(B[:mid+1])
        mi = r*(N-1-mid) - sum(B[mid+1:])
        if pl > mi:
            ri = mid
        else:
            le = mid
    k = sum(B[:le+1])
    if k <= K:
        s = False
        print(r)
        break
if s:
    print(1)

Fixed submission:
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
S = sum(A)

def searchPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

plis = searchPrimeNum(40000)

lis = []
for p in plis:
    if S%p == 0:
        lis.append([p,1])
        S = S//p
        while S%p == 0:
            lis[-1][1] += 1
            S = S//p
    if S == 1:
        break
if S != 1:
    lis.append([S,1])

yakulis =[1]
for l in lis:
    for j in range(len(yakulis)):
        for k in range(l[1]):
            n = yakulis[j]
            yakulis.append(l[0]**(k+1)*n)
yakulis.sort(reverse=True)

s = True
for r in yakulis:
    B = [i%r for i in A]
    B.sort()
    le = -1
    ri = N
    while ri-le > 1:
        mid = (le+ri)//2
        pl = sum(B[:mid+1])
        mi = r*(N-1-mid) - sum(B[mid+1:])
        if pl > mi:
            ri = mid
        else:
            le = mid
    k = sum(B[:le+1])
    if k <= K:
        s = False
        print(r)
        break
if s:
    print(1)
Buggy python submission (verdict: Runtime Error):
r = int(input())
print(3*(a**2))

Fixed submission:
r = int(input())
print(3*(r**2))
Buggy python submission (verdict: Runtime Error):

import math
C,D,A,B =map(int,input().split())
la =[D//A,(C-1)//A]
lb =[D//B,(C-1)//B]
lcm = A*B //math.gcd(A,B)
lab =[D//lcm,(C-1)//lcm]

ans = la[0] +lb[0] -la[1] -lb[1] -(lab[0]-lab[1])
print(D-C+1-ans)

Fixed submission:

def gcd(x,y): #x<y
    if x==0:
        return y
    else:
        return gcd(y%x,x)



C,D,A,B =map(int,input().split())
la =[D//A,(C-1)//A]
lb =[D//B,(C-1)//B]
lcm = A*B //gcd(A,B)
lab =[D//lcm,(C-1)//lcm]

ans = la[0] +lb[0] -la[1] -lb[1] -(lab[0]-lab[1])
print(D-C+1-ans)
Buggy python submission (verdict: Runtime Error):
l =map(int,input().split())
l.sort()
print(l[0]+l[1])


Fixed submission:
l =[int(i) for i in input().split()]
l.sort()
print(l[0]+l[1])
Buggy python submission (verdict: Runtime Error):

import sys
imput =sys.stdin.readline

p = 10**9 + 7

N,M =map(int,input().split())
lis = [0]*N

for _ in range(M):
    i = int(input())-1
    lis[i] = -1


if lis[0]!=-1:
    lis[0] =1
if lis[1]!=-1:
    lis[1] =1 + max(0,lis[0])

for i in range(N-2):
    i += 2
    if lis[i]!=-1:
        lis[i]= (max(0,lis[i-1])+max(0,lis[i-2]))%p

print(lis[-1])

Fixed submission:

import sys
imput =sys.stdin.readline

p = 10**9 + 7

N,M =map(int,input().split())
lis = [0]*N

for _ in range(M):
    i = int(input())-1
    lis[i] = -1


if lis[0]!=-1:
    lis[0] =1
if N != 1:
    if lis[1]!=-1:
        lis[1] =1 + max(0,lis[0])

for i in range(N-2):
    i += 2
    if lis[i]!=-1:
        lis[i]= (max(0,lis[i-1])+max(0,lis[i-2]))%p

print(max(0,lis[-1]))
Buggy python submission (verdict: Time Limit Exceeded):

N,K =map(int,input().split())
n = 0
ans = 0
L = K-1
R = N
while True:
    if L < N:
        break
    else:
        n += 1
        R = L
        L = R//2

if R > N:
    R=N

while True:
    foo = R-L
    foo /= 2**n
    ans += foo
    if L==1:
        ans += 1/(2**(n+1))
        break
    R = L
    L =R//2
    n += 1
print(ans/N)

Fixed submission:

N,K =map(int,input().split())
n = 0
ans = 0
L = K-1
R = N
while True:
    if L < N:
        break
    else:
        n += 1
        R = L
        L = R//2

if R > N:
    R=N

while True:
    foo = R-L
    foo /= 2**n
    ans += foo
    if L==1:
        ans += 1/(2**(n+1))
        break
    if L ==0:
        break
    R = L
    L =R//2
    n += 1
print(ans/N)
Buggy python submission (verdict: Runtime Error):
N,K =map(int,input().split())
S =input()
lis = [[],[]]
if S[0]=="0":
    lis[1].append(0)
j = S[0]
su = 0
for i in S:
    if i ==j:
        su += 1
    else:
        lis[int(j)].append(su)
        j = i
        su = 1
lis[int(j)].append(su)
if j=="0":
    lis[1].append(0)
if len(lis[0])<=K:
    print(N)
else:
    ans = 0

    foo = sum(lis[0][0:K]) + sum(lis[1][0:K+1])
    for i in range(len(lis[0])+1-K):
        foo += lis[0][K+i] -lis[0][i] +lis[1][K+1+i] -lis[1][i]
        if ans < foo:
            ans = foo
    print(ans)

Fixed submission:
N,K =map(int,input().split())
S =input()
lis = [[],[]]
if S[0]=="0":
    lis[1].append(0)
j = S[0]
su = 0
for i in S:
    if i ==j:
        su += 1
    else:
        lis[int(j)].append(su)
        j = i
        su = 1
lis[int(j)].append(su)
if j=="0":
    lis[1].append(0)
if len(lis[0])<=K:
    print(N)
else:
    ans = 0

    ans = sum(lis[0][0:K]) + sum(lis[1][0:K+1])
    foo = ans
    for i in range(len(lis[0])-K):
        foo += lis[0][K+i] -lis[0][i] +lis[1][K+1+i] -lis[1][i]
        if ans < foo:
            ans = foo
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K =map(int,input().split())
S =input()
lis = [[],[]]
if S[0]=="0":
    lis[1].append(0)
st = []
j = S[0]
su = 0
for i in S:
    if i ==j:
        su += 1
    else:
        lis[int(j)].append(su)
        st.append(j)
        j = i
        su = 1
lis[int(j)].append(su)
st.append(j)
if j=="0":
    lis[1].append(0)
if len(lis[0])<=K:
    print(N)
else:
    ans = 0
    for i in range(len(lis[0])+1-K):    
        foo = sum(lis[0][i:i+K]) + sum(lis[1][i:i+K+1])
        if ans < foo:
            ans = foo
    print(ans)


Fixed submission:
N,K =map(int,input().split())
S =input()
lis = [[],[]]
if S[0]=="0":
    lis[1].append(0)
j = S[0]
su = 0
for i in S:
    if i ==j:
        su += 1
    else:
        lis[int(j)].append(su)
        j = i
        su = 1
lis[int(j)].append(su)
if j=="0":
    lis[1].append(0)
if len(lis[0])<=K:
    print(N)
else:
    ans = 0

    ans = sum(lis[0][0:K]) + sum(lis[1][0:K+1])
    foo = ans
    for i in range(len(lis[0])-K):
        foo += lis[0][K+i] -lis[0][i] +lis[1][K+1+i] -lis[1][i]
        if ans < foo:
            ans = foo
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =input()
for _ in range(Q):
  l,r = map(int,input().split())
  print(S[l-1:r].count("AC"))
  

Fixed submission:
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =[i for i in input()]
q = [[int(i) for i in input().split()] for _ in range(Q)]
num = 0
for i in range(N-1):
    if S[i]+S[i+1]=="AC":
        num += 1
    S[i] = num
S[-1] = num
S.append(0)
for lr in q:
  print(S[lr[1]-2] -S[lr[0]-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q =map(int,input().split())
S =input()
for _ in range(Q):
  l,r = map(int,input().split())
  print(S[l-1:r].count("AC"))
  

Fixed submission:
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =[i for i in input()]
q = [[int(i) for i in input().split()] for _ in range(Q)]
num = 0
for i in range(N-1):
    if S[i]+S[i+1]=="AC":
        num += 1
    S[i] = num
S[-1] = num
S.append(0)
for lr in q:
  print(S[lr[1]-2] -S[lr[0]-2])
Buggy python submission (verdict: Runtime Error):
a,b,k =map(int,input().split())

def euclid(p,q):
  if q == 0:
    return p
  else:
    return euclid(q,p//q)
  
n = euclid(a,b)
count = 0
for i in range(n):
  if n % (n-i)==0:
    count += 1
  if count == k:
    print(n-i)
    break


Fixed submission:
a,b,k =map(int,input().split())

def euclid(p,q):
  if q == 0:
    return p
  else:
    return euclid(q,p%q)
  
n = euclid(a,b)
count = 0
for i in range(n):
  if n % (n-i)==0:
    count += 1
  if count == k:
    print(n-i)
    break
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A,B,C =map(int,input().split())
s =[-10**11] + [int(input())for _ in range(A)] +[10**11]
t =[-10**11] + [int(input())for _ in range(B)] +[10**11]

for _ in range(C):
    x =int(input())
    ns = bisect.bisect_left(s,x)
    nt = bisect.bisect_left(t,x)
    sx =[s[ns-1],s[ns]]
    tx =[t[nt-1],t[nt]]
    lis =[sx,tx]
    ans = 10**11
    for i in range(8):
        p =i%2
        q =(i//2)%2
        r =i//4
        foo =abs(x-lis[p][q])+abs(lis[p][q]-lis[p-1][r])
        if foo < ans:
            ans = foo
    print(ans)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A,B,C =map(int,input().split())
s =[-10**11] + [int(input())for _ in range(A)] +[10**11]
t =[-10**11] + [int(input())for _ in range(B)] +[10**11]

for _ in range(C):
    x =int(input())
    ns = bisect.bisect_left(s,x)
    nt = bisect.bisect_left(t,x)
    sx =[s[ns-1],s[ns]]
    tx =[t[nt-1],t[nt]]
    lis =[sx,tx]
    ans = 10**11
    for i in range(8):
        p =i%2
        q =(i//2)%2
        r =i//4
        foo =abs(x-lis[p][q])+abs(lis[p][q]-lis[p-1][r])
        if foo < ans:
            ans = foo
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def nibuntansaku(l,x):
    n = len(l)
    def hantei(med):
        if med == -1:
            return False
        elif med == n:
            return True
        elif l[med] > x:
            return True
        else:
            return False
    left = -1
    right =n
    while right-left >1:
        med = (left+right)//2
        if right == med or left == med:
            break
        if hantei(med):
            right = med
        else:
            left = med
    ret =[0,0]
    if left == -1:
        ret[0] = 10**11
        ret[1] = l[right] -x
    elif right == n:
        ret[0] = x -l[left]
        ret[1] = 10**11
    else:
        ret[0] = x - l[left]
        ret[1] = l[right] -x
    return ret


A,B,Q =[int(i)for i in input().split()]
S =[int(input())for _ in range(A)]
T =[int(input())for _ in range(B)]

for _ in range(Q):
    x = int(input())
    slef,sri = nibuntansaku(S,x)
    tlef,tri = nibuntansaku(T,x)
    lmax,lmin = max(slef,tlef),min(slef,tlef)
    rmax,rmin = max(sri,tri),min(sri,tri)
    ans = min(lmax,rmax,2*lmin+rmin,2*rmin+lmin)
    print(ans)


Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A,B,C =map(int,input().split())
s =[-10**11] + [int(input())for _ in range(A)] +[10**11]
t =[-10**11] + [int(input())for _ in range(B)] +[10**11]

for _ in range(C):
    x =int(input())
    ns = bisect.bisect_left(s,x)
    nt = bisect.bisect_left(t,x)
    sx =[s[ns-1],s[ns]]
    tx =[t[nt-1],t[nt]]
    lis =[sx,tx]
    ans = 10**11
    for i in range(8):
        p =i%2
        q =(i//2)%2
        r =i//4
        foo =abs(x-lis[p][q])+abs(lis[p][q]-lis[p-1][r])
        if foo < ans:
            ans = foo
    print(ans)
Buggy python submission (verdict: Runtime Error):
N =int(input())
l =[int(i)for i in input().split()]
l =sorted(l)
min =l[0]
for i,st in enumerate(l):
    st = st % min
    if st==0:
        l.pop(i)
    elif st < min:
        min = min(st,min%st)
print(min)

Fixed submission:
def kumitate(a,b):
    a,b =max(a,b),min(a,b)
    while b != 0:
        a,b = b,a%b
    return a

N =int(input())
l =[int(i)for i in input().split()]
l =sorted(l)
mini =l[0]
for i in l:
    mini = kumitate(mini,i)
print(mini)
Buggy python submission (verdict: Runtime Error):
N,K =[int(i)for input().split()]
if 2*K-1 <= N:
  print("YES")
else:
  print("NO")

Fixed submission:
N,K =[int(i)for i in input().split()]
if 2*K-1 <= N:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N,M =[int(i)for i in input().split()]
l=[]
for i in range(2,int(M**0.5+1)):
    if M%i==0:
        if M/i >= N:
            l.append(i)
        if i >= N:
            l.append(M/i)
print(max(l))

Fixed submission:
N,M =[int(i)for i in input().split()]
l=[]
for i in range(1,int(M**0.5+2)):
    if M%i==0:
        if M/i >= N:
            l.append(i)
        if i >= N:
            l.append(M/i)
print(int(max(l)))

Buggy python submission (verdict: Time Limit Exceeded):
N,M =map(int,input().split())
sta = M//N
for i in range(0,sta):
    i = sta-i
    if M%i==0:
        print(i)
        break


Fixed submission:
N,M =[int(i)for i in input().split()]
l=[]
for i in range(1,int(M**0.5+2)):
    if M%i==0:
        if M/i >= N:
            l.append(i)
        if i >= N:
            l.append(M/i)
print(int(max(l)))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ki = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
tf = [False for _ in range(N)]

# DFS
def dfs(v):
    global eda
    tf[v] = True
    eda += 1
    for nv in set(ki[v]):
        if not tf[nv]:
            dfs(nv)

ans = 0
for i in range(N):
    if not tf[i]:
        eda = 0
        dfs(i)
        ans = max(ans, eda)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
N, M = map(int, input().split())
ki = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
tf = [False for _ in range(N)]

# DFS
def dfs(v):
    global eda
    tf[v] = True
    eda += 1
    for nv in set(ki[v]):
        if not tf[nv]:
            dfs(nv)

ans = 0
for i in range(N):
    if not tf[i]:
        eda = 0
        dfs(i)
        ans = max(ans, eda)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
score = [1]
for i in range(K):
    score[-1] *= A[i]
for i in range(K, N):
    temp = score[-1]//A[i-K]*A[i]
    if temp > score[-1]:
        print("Yes")
    else:
        print("No")
    score.append(temp)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K, N):
    if A[i-K] < A[i]:
         print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    # 累積和
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()
   
for b in B:
    print(b, end=" ")

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
    B = [0 for k in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    # 累積和
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()
   
for b in B:
    print(b, end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    B = [0 for _ in range(N)]
    if all(b == N for b in B):
        break
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    # 累積和
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()
   
for b in B:
    print(b, end=" ")

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
    B = [0 for k in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    # 累積和
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()
   
for b in B:
    print(b, end=" ")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [False for _ in range(N)]

i = 1
c = 0
jun = []

if K <= N:
    while True:
        K -= 1
        i = A[i-1]
        if K == 0:
            print(i)
            exit()


while True:
    if i == A[i-1]:
        print(i)
        exit()
    if visited[i-1]:
        lp = i
        break
    else:
        visited[i - 1] = True
        jun.append(i)
        i = A[i-1]
        c += 1
ji = jun.index(lp)
K -= len(jun[:ji])
jun = jun[lp:]

kai = K % c

if kai == len(jun) + 1:
    print(jun[0])
else:
    print(jun[kai-1])

Fixed submission:
from itertools import combinations

N, M, X = map(int, input().split())
box = [list(map(int, input().split())) for _ in range(N)]

ans = -1

for j in range(1, N+1):
    for i in combinations(box, j):
        kakaku = 0
        rika = [0 for _ in range(M)]
        for el in i:
            kakaku += el[0]
            for n, k in enumerate(el[1:]):
                rika[n] += k

        if all(p >= X for p in rika):
            if ans == -1:
                ans = kakaku
            else:
                ans = min(kakaku, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
X = int(input())

for i in range(100000):
    A5 = X - i**5
    if (A5**(1/5)).is_integer():
        print(i, -int(A5**(1/5)))
        break

Fixed submission:
X = int(input())

for i in range(1000):
    for j in range(-1000, i):
        if i**5 - j**5 == X:
            print(i, j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

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

mv = 0
while N > 0:
    mv = max(mv, floor(A*N/B) - A*floor(N/B))
    N -= 1

print(mv)

Fixed submission:
from math import floor

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

if B > N:
    print(floor(A*N/B) - A*floor(N/B))
else:
    N = B - 1
    print(floor(A*N/B) - A*floor(N/B))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
MOD = 2019

for i in range(len(S)):
    for j in range(i+1, len(S)+1):
        if int(S[i:j]) % MOD == 0:
            ans += 1
            break

print(ans)

Fixed submission:
from collections import defaultdict
S = input()
n = len(S)
N = defaultdict(int)
x = 0
for i in reversed(range(n)):
    x += int(S[i])*pow(10,(n-i-1),2019)
    x %= 2019
    N[x] += 1
ans = N[0]
for j in N.values():
    ans += j*(j-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
jyogai = 0

for i in range(N-1):
    nS = S[i+1:]
    kouho = []
    for w in ["R", "G", "B"]:
        if S[i] != w:
            kouho.append(nS.count(w))
    temp = i
    while True:
        temp += 1
        temp2 = temp - i
        if i + 2*temp2 > N-1:
            break
        b = [S[i], S[i + temp2], S[i + 2*temp2]]
        if len(set(b)) == 3:
            jyogai += 1

    ans += kouho[0] * kouho[1]

print(ans - jyogai)

Fixed submission:
N = int(input())
S = input()

ans = 0
jyogai = 0

for i in range(N-1):
    nS = S[i+1:]
    kouho = []
    for w in ["R", "G", "B"]:
        if S[i] != w:
            kouho.append(nS.count(w))
    temp = i
    while True:
        temp += 1
        temp2 = temp - i
        if i + 2*temp2 > N-1:
            break
        b = [S[i], S[i + temp2], S[i + 2*temp2]]
        if len(set(b)) == 3:
            jyogai += 1

    ans += kouho[0] * kouho[1]

print(ans - jyogai)