Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)
    u = tuple(t)

    count = 0
    i = 0
    while i < n:
        x = u[i] + k
        y = min(i + c - 1, n - 1)
        while True:
            if u[y] <= x:
                break
            y -= 1

        count += 1
        i = y + 1

    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)
    u = tuple(t)

    cnt = 1
    p, l = 0, u[0] + k
    for v in t:
        if v <= l and p < c:
            p += 1
        else:
            cnt += 1
            l = v + k
            p = 1
    print(cnt)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)

    count = 0
    i = 0
    while i < n:
        x = t[i] + k
        y = min(i + c - 1, n - 1)
        while True:
            if t[y] <= x:
                break
            y -= 1

        count += 1
        i = y + 1

    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t = sorted(t)
    u = tuple(t)

    cnt = 1
    p, l = 0, u[0] + k
    for v in t:
        if v <= l and p < c:
            p += 1
        else:
            cnt += 1
            l = v + k
            p = 1
    print(cnt)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
ans=1
for i in range(int(iput())):
  ans*=i%(10**9+7)
print(ans)

Fixed submission:
ans=1
for i in range(1,int(input())+1):
  ans=ans*i%(10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    _, __ = map(int, input().split())
    ___ = [[] for _ in range(_)]
    for _ in range(__):
        ____, _____ = map(lambda ______: int(_____) - 1, input().split())
        ___[____].append(_____)
        ___[_____].append(____)

    _______ = [False] * _
    ________ = ___________(0, ___, _______, 0)

    print(________)


def ___________(_____, ___, _______, _________):
    _______[_____] = True
    if all(_______):
        return _________ + 1

    for __________ in ___[_____]:
        if _______[__________]:
            continue
        _________ = ___________(__________, ___, _______, _________)
        _______[__________] = False

    return _________


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(lambda x: int(x) - 1, input().split())
        g[u].append(v)
        g[v].append(u)

    vis = [False] * n
    ans = dfs(0, g, vis, 0)

    print(ans)


def dfs(v, g, vis, count):
    vis[v] = True

    if all(vis):
        return count + 1

    for i in g[v]:
        if vis[i]:
            continue
        count = dfs(i, g, vis, count)
        vis[i] = False

    return count


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s=str(input())
a,b=s.find("A"),s,rfind("Z")
print(b-a+1)

Fixed submission:
s=str(input())
a,b=s.find("A"),s.rfind("Z")
print(b-a+1)
Buggy python submission (verdict: Runtime Error):
n,s=map(int,input().split())
l=[0]
for i in s:
  x= -1 if i=="D" else 1
  l+=[l[-1]+x]
print(max(l))

Fixed submission:
n,s=int(input()),str(input())
l=[0]
for i in s:
  x= -1 if i=="D" else 1
  l+=[l[-1]+x]
print(max(l))
Buggy python submission (verdict: Runtime Error):
import heapq


def dijkstra(n, s, g):
    h = [(0, s)]
    heapq.heapify(h)
    cost = [float("Inf")] * (n + 1)  # cost: i -> j
    cost[s] = 0

    while h:
        c, v = heapq.heappop(h)
        if c > cost[v]:
            continue
        for d, u in g[v]:
            d_s_u = d + cost[v]
            if d_s_u < cost[u]:
                cost[u] = d_s_u
                heapq.heappush(h, (d_s_u, u))

    return cost


def main():
    n, m, *abc = map(int, open(0).read().split())
    g = [[] for _ in range(n + 1)]

    for a, b, c in zip(*[iter(abc)] * 3):
        g[a].append([c, b])
        g[b].append([c, a])

    ans = 0
    checkd = [[False] * (n + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        cost = dijkstra(n, i, g)
        for j, k in g[i]:
            if checkd[i][j]:
                continue
            if j > cost[k]:
                ans += 1
            checkd[i][j] = True
            checkd[j][i] = True
    
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, m, *abc = map(int, open(0).read().split())
    d = [[float("Inf")] * (n + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        d[i][i] = 0

    for a, b, c in zip(*[iter(abc)] * 3):
        d[a][b] = c
        d[b][a] = c

    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    ans = 0
    for a, b, c in zip(*[iter(abc)] * 3):
        if d[a][b] < c:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    c = Counter(a)
    f = True
    if n % 2 == 0:
        f = all(x == 2 for x in c.values())
    else:
        g = c.pop("0") == 1
        f = all(x == 2 for x in c.values()) and g
    ans = 2 ** (n // 2) % 1000000007 if f is True else 0
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import collections
n=int(input())
l=list(input().split())
c=collections.Counter(l)
if n%2==0:
  f=all(x==2 for x in c.values())
else:
  g=c.pop("0")==1
  f=all(x==2 for x in c.values()) and g
print(2**(n//2)%1000000007 if f==True else 0)

Buggy python submission (verdict: Runtime Error):
def main():
    import collections
    n, *a = map(int, open(0).read().split())
    c = collections.Counter(a)
    if n % 2 == 0:
        f = all(x == 2 for x in c.values())
    else:
        g = c.pop("0") == 1
        f = all(x == 2 for x in c.values()) and g
    ans = 2 ** (n // 2) % 1000000007 if f is True else 0
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import collections
n=int(input())
l=list(input().split())
c=collections.Counter(l)
if n%2==0:
  f=all(x==2 for x in c.values())
else:
  g=c.pop("0")==1
  f=all(x==2 for x in c.values()) and g
print(2**(n//2)%1000000007 if f==True else 0)

Buggy python submission (verdict: Time Limit Exceeded):
n,l=int(input()),list(map(int,input().split()))
if n%2==0:
  f=all(l.count(l[i])==2 for i in range(n))
else:
  f=all(l.count(l[i])==2 for i in range(n) if l[i]!=0) and l.count(0)==1
print(2**(n//2)%1000000007 if f==True else 0)

Fixed submission:
import collections
n=int(input())
l=list(input().split())
c=collections.Counter(l)
if n%2==0:
  f=all(x==2 for x in c.values())
else:
  g=c.pop("0")==1
  f=all(x==2 for x in c.values()) and g
print(2**(n//2)%1000000007 if f==True else 0)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, t, *a = map(int, open(0).read().split())
    a += [-float("Inf")]
    b = [max(a[i + 1:]) for i in range(n)]
    c = []
    for i in range(n):
        x = a[i]
        y = b[i]
        c.append(y - x)

    d = c.count(max(c))
    print(d)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, t, *a = map(int, open(0).read().split())
    b = 0
    c = float("Inf")
    d = 0
    for i in range(n):
        x = a[i]
        if x - c > b:
            b = x - c
            d = 1
        elif x - c == b:
            d += 1
        c = min(c, x)

    print(d)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from math import ceil
    n = int(input())
    a, b = 1, 1
    for _ in range(n):
        i, j = map(int, input().split())
        x = max((a + s - 1) // s, (b + t - 1) // t)
        a, b = x * i, x * j
    print(a + b)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from math import ceil
    n = int(input())
    a, b = 1, 1
    for _ in range(n):
        i, j = map(int, input().split())
        x = max((a + i - 1) // i, (b + j - 1) // j)
        a, b = x * i, x * j
    print(a + b)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[a[i]]==i:
    ans+=1
print(ans)

Fixed submission:
n=int(input())
a=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  if a[a[i]]==i:
    ans+=1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    n = len(s)
    ans = 0
    for i in range(n + 1):
        for j in range(i + 1, n + 1):
            x = int(s[i:j])
            p = 2 ** max(0, i - 1)
            q = 2 ** max(0, n - j - 1)
            ans += x * p * q

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    n = len(s)
    ans = 0
    for i in range(n + 1):
        for j in range(i + 1, n + 1):
            x = int(s[i:j])
            p = 2 ** max(0, i - 1) * 2 ** max(0, n - j - 1)
            ans += x * p

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    n = len(s)
    ans = 0
    for i in range(n + 1):
        for j in range(i + 1, n + 1):
            x = int(s[i:j])
            p = 2 ** max(0, i - 1)
            q = 2 ** max(0, n - j - 1)
            ans += x * p * q

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    n = len(s)
    ans = 0
    for i in range(n + 1):
        for j in range(i + 1, n + 1):
            x = int(s[i:j])
            p = 2 ** max(0, i - 1) * 2 ** max(0, n - j - 1)
            ans += x * p

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
while(s.count("B")!=0):
  i=s.find("B")
  if i!=0:
    s=s[:i-1]+s[i+1:]
print(s)

Fixed submission:
s=str(input())
while(s.count("B")!=0):
  i=s.find("B")
  if i!=0:
    s=s[:i-1]+s[i+1:]
  else:
    s=s[1:]
print(s)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input()))
b = a.count('5')
c = a.count('7')
if b == 2 and c ==1:
            print('YES')
else:
            print('NO')

Fixed submission:
a = list(map(int,input().split()))
b = a.count(5)
c = a.count(7)
if b == 2 and c ==1:
            print('YES')
else:
            print('NO')

Buggy python submission (verdict: Runtime Error):
a = list(map(int,input()))
b = a.count(’5')
c = a.count(’7')
if b == 2 and c ==1:
            print('YES')
else:
            print('NO')

Fixed submission:
a = list(map(int,input().split()))
b = a.count(5)
c = a.count(7)
if b == 2 and c ==1:
            print('YES')
else:
            print('NO')

Buggy python submission (verdict: Runtime Error):
a = list(map(int,input()))
b = a.count(’5')
c = a.count(’7')
if b == 2 and c ==1:
            pritn('YES')
else:
            print('NO')
 

Fixed submission:
a = list(map(int,input().split()))
b = a.count(5)
c = a.count(7)
if b == 2 and c ==1:
            print('YES')
else:
            print('NO')
Buggy python submission (verdict: Runtime Error):
n,l = map(int,input().split())
l = sorted([str(input()) for _ in range(l)])
print(l)

Fixed submission:
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")
Buggy python submission (verdict: Runtime Error):
from math import gcd

N = int(input())
A = list(map(int, input().split()))
sieve = [1] * (10**5*5+1)
for i in range(2, 10**3):
	if sieve[i] == 1:
		sieve[i] = i
		j = 2
		while(j * i <= 10**5*5):
			sieve[j * i] = i
			j += 1
sieve[1] = 0

g = A[0]
a = 0
for i in range(1, N):
	g = gcd(g, A[i])
	if A[i] == 1:
		a = 1
	
if g != 1:
	print("not coprime")
else:
	if a == 1:
		print("setwise coprime")
		exit()
	s = set()
	for i in range(N):
		st = set()
		while(A[i] > 1):
			d = sieve[A[i]]
			if not(d in st) and d in s:
				print("setwise coprime")
				exit()
			s.add(d)
			st.add(d)
			A[i] //= d
	print("pairwise coprime")

Fixed submission:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
sieve = [1] * (10**6+1)
for i in range(2, 10**6 + 1):
	if sieve[i] == 1:
		sieve[i] = i
		j = 2
		while(j * i <= 10**6):
			sieve[j * i] = i
			j += 1

g = A[0]
for i in range(1, N):
	g = gcd(g, A[i])
	
if g != 1:
	print("not coprime")
else:
	s = set()
	for i in range(N):
		st = set()
		while(A[i] > 1):
			d = sieve[A[i]]
			st.add(d)
			A[i] //= d
		for p in st:
			if p in s:
				print("setwise coprime")
				exit()
			s.add(p)
	print("pairwise coprime")
Buggy python submission (verdict: Runtime Error):
from math import ceil

N, X, T = map(int,input().split())

print(ceil(N / X)* T)from math import ceil

N, X, T = map(int,input().split())

print(ceil(N / X)* T)

Fixed submission:
from math import ceil

N, X, T = map(int,input().split())

print(ceil(N / X)* T)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

H, W, M = map(int,input().split())
targets = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

cnth = [0] * H
cntw = [0] * W
wlist = [[] for i in range(H)]

for i in range(M):
	hi, wi = targets[i]
	cnth[hi] += 1
	cntw[wi] += 1
	wlist[hi].append(wi)

maxhi = []
maxwi = []
maxh = max(cnth)
maxw = max(cntw)

for i in range(H):
	wlist[i].sort()
	if cnth[i] == maxh:
		maxhi.append(i)
for i in range(W):
	if cntw[i] == maxw:
		maxwi.append(i)

for i in range(len(maxhi)):
	for j in range(len(maxwi)):
		if bisect_right(wlist[maxhi[i]], maxwi[j]) - bisect_left(wlist[maxhi[i]], maxwi[j]) == :
			print(maxh + maxw)
			exit()
print(maxh + maxw - 1)

Fixed submission:
from bisect import bisect_left, bisect_right

def exists(ite, x):
	return bool(bisect_right(ite, x) - bisect_left(ite, x))

H, W, M = map(int,input().split())
targets = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

cnth = [0] * H
cntw = [0] * W
wlist = [[] for i in range(H)]

for i in range(M):
	hi, wi = targets[i]
	cnth[hi] += 1
	cntw[wi] += 1
	wlist[hi].append(wi)

maxhi = []
maxwi = []
maxh = max(cnth)
maxw = max(cntw)

for i in range(H):
	wlist[i].sort()
	if cnth[i] == maxh:
		maxhi.append(i)
for i in range(W):
	if cntw[i] == maxw:
		maxwi.append(i)

for i in range(len(maxhi)):
	for j in range(len(maxwi)):
		if not exists(wlist[maxhi[i]], maxwi[j]):
			print(maxh + maxw)
			exit()
print(maxh + maxw - 1)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(max(temp),max([temp[-1]+temp[i+1] for i in range(K%(len(temp)-1))]))
    ans=max(ans, t)
		
print(int(ans))


Fixed submission:
S=input().strip("¥n")

if S=="RRR":
	print(3)
elif "RR" in S:
	print(2)
elif "R" in S:
	print(1)
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(temp+[temp[-1]+temp[i+1] for i in range(K%(len(temp)-1))])
    ans=max(ans, t)
		
print(int(ans))


Fixed submission:
S=input().strip("¥n")

if S=="RRR":
	print(3)
elif "RR" in S:
	print(2)
elif "R" in S:
	print(1)
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(temp+[temp[-1]+temp[i+1] for i in range(K%(len(temp)-1)+1)])
    ans=max(ans, t)
		
print(int(ans))


Fixed submission:
S=input().strip("¥n")

if S=="RRR":
	print(3)
elif "RR" in S:
	print(2)
elif "R" in S:
	print(1)
else:
	print(0)
Buggy python submission (verdict: Runtime Error):
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    sumA=sum(A)
    K_i=[int(A[i]/sumA*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
input=sys.stdin.readline

def main():
    X=int(input())
    if X>=30:
        print("Yes")
    else:
        print("No")
    
    
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#

import sys
from math import gcd
input=sys.stdin.readline

def main():
    K=int(input())
    if K%2==0:
        print(-1)
        exit()
    if K==5:
        print(-1)
    s=set()
    r=7%K
    rsum=r
    s.add(r)
    for i in range(10**6):
        if rsum==0:
            print(i+1)
            exit()
        r=(r*10)%K
        if r in s:Q
            break
        s.add(r)
        rsum=(rsum+r)%K
    print((i+1)*K/gcd(rsum,K))
    
    
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
input=sys.stdin.readline

def main():
    K=int(input())
    rsum=0
    r=7
    for i in range(10**6+1):
        rsum=(rsum+r)%K
        r=(r*10)%K
        if rsum==0:
            print(i+1)
            exit()
    print(-1)
    
    
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    K_i=[int(A[i]/sum(A)*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    d=K/N
    K_i=[int(A[i]/aveA*d) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    K_i=[int(A[i]/aveA*K/N) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    for i in range(res):
        maxi=dA.index(max(dA))
        K_i[maxi]+=1
        dA[maxi]=A[maxi]/(K_i[maxi]+1)
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    d=K/N
    K_i=[int(A[i]/aveA*d) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#

import sys
from copy import deepcopy
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    satsum=0
    for day in range(1,D+1):
        lastt=deepcopy(last)
        maxt=0
        maxsat=0
        for t in range(1,27):
            sat=0
            for j in range(day,D+1):
                    last[j][t]=day
            sat+=S[day-1][t-1]
            for j in range(1,27):
                sat-=C[j-1]*(day-last[day][j])
            if t==1:
                maxt=t
                maxsat=sat
            elif maxsat<sat:
                maxt=t
                maxsat=sat
            last=deepcopy(lastt)
            
        satsum+=maxsat
        for j in range(day,D+1):
            last[j][maxt]=day
        satsum+=maxsat
        print(maxt)
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    for day in range(1,D+1):
        maxt=0
        maxx=0
        sat=0
        for t in range(1,27):
            for j in range(day,D+1):
                    last[j][t]=day
            sat+=S[day-1][t-1]
            for j in range(1,27):
                sat-=C[j-1]*(day-last[day][j])
            if maxx<sat:
                maxt=t
                maxx=sat
        print(maxt)
    
if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#

import sys
input=sys.stdin.readline
MOD=10**9+7

fac=[1]*(5*10**5+1)
for i in range(1,5*10**5+1):
    fac[i]=(fac[i-1]*i)%MOD
    
def inv(x):
    return pow(x,MOD-2,MOD)

def nPr(n,r):
    return (fac[n]*inv(fac[n-r]))%MOD
def nCr(n,r):
    return (fac[n]*inv(fac[n-r])*inv(fac[r]))%MOD

def main():
    N,M=map(int,input().split())
    hojo=0
    for i in range(1,N+1):
        hojo+=(-1)**(i)*nCr(N,i)*nPr(M,i)*nPr(M-i,N-i)**2
        hojo%=MOD
    print((nPr(M,N)**2+hojo)%MOD)
    
    
    
if __name__=="__main__":
    main()


Fixed submission:
#

import sys
input=sys.stdin.readline
MOD=10**9+7

fac=[1]*(5*10**5+1)
for i in range(1,5*10**5+1):
    fac[i]=(fac[i-1]*i)%MOD
    
def inv(x):
    return pow(x,MOD-2,MOD)

def nPr(n,r):
    return (fac[n]*inv(fac[n-r]))%MOD
def nCr(n,r):
    return (fac[n]*inv(fac[n-r])*inv(fac[r]))%MOD

def main():
    N,M=map(int,input().split())
    hojo=0
    for i in range(1,N+1):
        hojo+=(-1)**(i)*nCr(N,i)*nPr(M,i)*nPr(M-i,N-i)**2
        hojo%=MOD
    print((nPr(M,N)**2+hojo)%MOD)
    
    
    
if __name__=="__main__":
    main()