Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=[]
for i in range(N):
    score=[]
    B=[]
    count=1
    nex=P[i]-1
    point=C[nex]
    B.append(C[nex])
    score.append(point)
    while count<=K:
        if nex==i:
            break
        nex=P[nex]-1
        point+=C[nex]
        score.append(point)
        B.append(C[nex])
        count+=1
    if count==K:
        ans.append(max(score))
    else:
        if point<=0:
            ans.append(max(score))
        else:
            a=K//count
            b=K%count
            maxpoint=point*(a-1)
            for j in range(b):
                maxpoint+=B[j]
            c=maxpoint
            for j in range(count):
                if b+j<count:
                    c+=B[b+j]
                else:
                    c+=B[b+j-count]
                maxpoint=max(maxpoint,c)
            ans.append(maxpoint)
print(max(ans))

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=[]
for i in range(N):
    score=[]
    B=[]
    count=1
    nex=P[i]-1
    point=C[nex]
    B.append(C[nex])
    score.append(point)
    while count<=K:
        if nex==i:
            break
        nex=P[nex]-1
        point+=C[nex]
        score.append(point)
        B.append(C[nex])
        count+=1
    if count==K:
        ans.append(max(score))
    else:
        if point<=0:
            ans.append(max(score))
        else:
            a=K//count
            b=K%count
            maxpoint=point*(a-1)
            for j in range(b):
                maxpoint+=B[j]
            c=maxpoint
            for j in range(count):
                if b+j<count:
                    c+=B[b+j]
                else:
                    c+=B[b+j-count]
                maxpoint=max(maxpoint,c)
            ans.append(maxpoint)
print(max(ans))
Buggy python submission (verdict: Runtime Error):
import string
a=string.ascii_lowercase
N=int(input())
ans=[]
count=1
n=26
while N>n:
    count+=1
    s=n
    n+=26**count
if N>26**count:
    for i in range(count):
        n=N//26**(count-i-1)
        if i!=count-1:
            m=N%26**(count-i-1)
        if n>=276:
            ans.append(a[25])
            N-=26**(count-i)
        else:
            ans.append(a[m-1])
else:
    while N>0:
        n=N//26
        m=N%26
        ans.append(a[m-1])
        N=n
Ans=[]
for i in range(len(ans)):
    Ans.append(ans[len(ans)-i-1])
print("".join(Ans))

Fixed submission:
import string
a=string.ascii_lowercase
N=int(input())
ans=[]
count=1
n=26
s=0
while N>n:
    count+=1
    s=n
    n+=26**count
N-=s+1
for i in range(count):
    n=N//26
    m=N%26
    ans.append(a[m])
    N=n
Ans=[]
for i in range(len(ans)):
    Ans.append(ans[len(ans)-i-1])
print("".join(Ans))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=1
mod=10**18
for i in A:
    ans*=i
if ans>mod:
    ans=-1
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=1
mod=10**18
for i in A:
    if i==0:
        ans=0
        break
    elif i==1:
        continue
    elif ans!=-1:
        ans=ans*i
        if ans>mod:
            ans=-1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
ischecked=[0]*N
move=[]
move1=[]
now=0
count=0
count1=0
while 1:
    move.append(now+1)
    nex=A[now]-1
    ischecked[now]=1
    if ischecked[nex]==1:
        roop=nex+1
        break
    now=nex
for i in range(len(move))[::-1]:
    move1.append(move[i])
    if move[i]==roop:
        b=len(move)-i
        break
if K>len(move):
    n=K-len(move)
    n=n%len(move1)
    print(move1[len(move1)-1-n])
else:
    print(move[K])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
ischecked=[0]*N
move=[]
move1=[]
now=0
count=0
count1=0
while 1:
    move.append(now+1)
    nex=A[now]-1
    ischecked[now]=1
    if ischecked[nex]==1:
        roop=nex+1
        break
    now=nex
for i in range(len(move))[::-1]:
    move1.append(move[i])
    if move[i]==roop:
        b=len(move)-i
        break
if K>=len(move):
    n=K-len(move)
    n=n%len(move1)
    print(move1[len(move1)-1-n])
else:
    print(move[K])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
L.sort()
R.sort()
l=0
for i in range(N):
    if i>=1:
        if L[i]==L[i-1]:
            ans=ans+count
            continue
    count=0
    for j in range(l,N):
        if L[i]==R[j]:
            count=count+1
        if L[i]<R[j]:
            l=j
            break
    ans=ans+count
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
L.sort()
R.sort()
for i in L:
    l=bisect.bisect_left(R,i)
    r=bisect.bisect_right(R,i)
    ans=ans+r-l
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
for i in L:
    a=R.count(i)
    ans=ans+a
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
L.sort()
R.sort()
for i in L:
    l=bisect.bisect_left(R,i)
    r=bisect.bisect_right(R,i)
    ans=ans+r-l
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
a=[]
B=[]
ans=0
for i in range(1,N):
    b=A[i]+A[0]
    a.append(b-i)
    B.append(A[i]-A[0])
ans=a.counter(0)
for i in range(N):
    b=B[i]
    a1=a[i:].copy()
    a1=a1-[b-i-1]
    ans+=a1.counter(0)
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
ans=0
for i in range(N):
    L.append(i+1+A[i])
    R.append(i+1-A[i])
L.sort()
R.sort()
for i in L:
    l=bisect.bisect_left(R,i)
    r=bisect.bisect_right(R,i)
    ans=ans+r-l
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
l=1
r=N
dis=[]
if N%2==1:
    for i in range(M):
        print(l,r)
        l=l+1
        r=r-1
else:
    for _ in range(M):
        print(l,r)
        a,b=r-l,N+l-r
        dis.append(a)
        dis.append(b)
        l=l+1
        r=r-1
        if r-l in dis or N+l-r in dis or r-l==N+l-r:
            r=r-1

Fixed submission:
N,M=map(int,input().split())
l=1
r=N
dis=set()
if N%2==1:
    for i in range(M):
        print(l,r)
        l=l+1
        r=r-1
else:
    for _ in range(M):
        print(l,r)
        a,b=r-l,N+l-r
        dis.add(a)
        dis.add(b)
        l=l+1
        r=r-1
        if r-l in dis or N+l-r in dis or r-l==N+l-r:
            r=r-1

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
l=1
r=N
dis=[]
if N%2==1:
    for i in range(M):
        print(l,r)
        l=l+1
        r=r-1
else:
    for _ in range(M):
        print(l,r)
        a,b=r-l,N+l-r
        dis.append(a)
        dis.append(b)
        l=l+1
        r=r-1
        if r-l in dis or N+l-r in dis or r-l=N+l-r:
            r=r-1

Fixed submission:
N,M=map(int,input().split())
l=1
r=N
dis=set()
if N%2==1:
    for i in range(M):
        print(l,r)
        l=l+1
        r=r-1
else:
    for _ in range(M):
        print(l,r)
        a,b=r-l,N+l-r
        dis.add(a)
        dis.add(b)
        l=l+1
        r=r-1
        if r-l in dis or N+l-r in dis or r-l==N+l-r:
            r=r-1
Buggy python submission (verdict: Time Limit Exceeded):
S=list(map(int,input()))
num=0
ans=0
for i in range(len(S)-3):
    num=S[i]*1000+S[i+1]*100+S[i+2]*10+S[i+3]
    if num%2019==0:
        ans=ans+1
    for j in range(i+4,len(S)):
        num=num*10+S[j]
        if num%2019==0:
            ans=ans+1
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
S=list(map(int,input()))
N=len(S)
P=2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + S[i] * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=list(map(int,input()))
num=0
ans=0
for i in range(len(S)-3):
    num=S[i]*1000+S[i+1]*100+S[i+2]*10+S[i+3]
    if num%2019==0:
        ans=ans+1
    for j in range(i+4,len(S)):
        num=num*10+S[j]
        if num%2019==0:
            ans=ans+1
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
S=list(map(int,input()))
N=len(S)
P=2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + S[i] * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
del p[:-X]
del q[:-Y]
ans=sum(p)+sum(q)
for i in range(len(r)):
    a=r[-(i+1)]
    minp=min(p)
    minq=min(q)
    if minp<=minq and minp<a:
        ans=ans-minp+a
        del p[p.index(minp)]
        p.append(a)
    elif minp>=minq and minq<a:
        ans=ans-minq+a
        del q[q.index(minq)]
        q.append(a)
    else:
        break
print(ans)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
ans=[]
for i in range(X):
    a=i+1
    ans.append(p[-a])
for i in range(Y):
    a=i+1
    ans.append(q[-a])
for i in r:
    ans.append(i)
ans.sort()
Ans=0
for i in range(X+Y):
    a=i+1
    Ans+=ans[-a]
print(Ans)

Buggy python submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
del p[:-X]
del q[:-Y]
if len(r)>X+Y:
    del r[:-max(X+Y)]
ans=sum(p)+sum(q)
for i in range(len(r)):
    a=r[-(i+1)]
    minp=min(p)
    minq=min(q)
    if minp<=minq and minp<a:
        ans=ans-minp+a
        del p[p.index(minp)]
        p.append(a)
    elif minp>=minq and minq<a:
        ans=ans-minq+a
        del q[q.index(minq)]
        q.append(a)
    else:
        break
print(ans)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
ans=[]
for i in range(X):
    a=i+1
    ans.append(p[-a])
for i in range(Y):
    a=i+1
    ans.append(q[-a])
for i in r:
    ans.append(i)
ans.sort()
Ans=0
for i in range(X+Y):
    a=i+1
    Ans+=ans[-a]
print(Ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
s=[]
dp=[[10**9]*(W)for _ in range(H)]
dp[0][0]=0
for i in range(H):
    S=input()
    s.append(S)
q=[(0,0)]
while q:
    a,b=q.pop(0)
    if a+1<H:
        if s[a][b]=="." and s[a+1][b]=="#":
            dp[a+1][b]=min(dp[a][b]+1,dp[a+1][b])
        else:
            dp[a+1][b]=min(dp[a][b],dp[a+1][b])
        q.append((a+1,b))
    if b+1<W:
        if s[a][b]=="." and s[a][b+1]=="#":
            dp[a][b+1]=min(dp[a][b]+1,dp[a][b+1])
        else:
            dp[a][b+1]=min(dp[a][b],dp[a][b+1])
        q.append((a,b+1))
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)

Fixed submission:
H,W=map(int,input().split())
s=[]
dp=[[10**9]*W for _ in range(H)]
dp[0][0]=0
for _ in range(H):
    s.append(list(input()))
for i in range(H):
    for j in range(W):
        if j!=W-1:
            if s[i][j]=="." and s[i][j+1]=="#":
                dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1])
            else:
                dp[i][j+1]=min(dp[i][j],dp[i][j+1])
        if i!=H-1:
            if s[i][j]=="." and s[i+1][j]=="#":
                dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j])
            else:
                dp[i+1][j]=min(dp[i][j],dp[i+1][j])
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
s=[]
dp=[[10**9]*(W)for _ in range(H)]
dp[0][0]=0
for i in range(H):
    S=input()
    s.append(S)
q=[(0,0)]
while q:
    a,b=q.pop(0)
    if a+1<H:
        if s[a][b]=="." and s[a+1][b]=="#":
            dp[a+1][b]=min(dp[a][b]+1,dp[a+1][b])
        else:
            dp[a+1][b]=min(dp[a][b],dp[a+1][b])
        q.append((a+1,b))
    if b+1<W:
        if s[a][b]=="." and s[a][b+1]=="#":
            dp[a][b+1]=min(dp[a][b]+1,dp[a][b+1])
        else:
            dp[a][b+1]=min(dp[a][b],dp[a][b+1])
        q.append((a,b+1))
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)

Fixed submission:
H,W=map(int,input().split())
s=[]
dp=[[10**9]*W for _ in range(H)]
dp[0][0]=0
for _ in range(H):
    s.append(list(input()))
for i in range(H):
    for j in range(W):
        if j!=W-1:
            if s[i][j]=="." and s[i][j+1]=="#":
                dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1])
            else:
                dp[i][j+1]=min(dp[i][j],dp[i][j+1])
        if i!=H-1:
            if s[i][j]=="." and s[i+1][j]=="#":
                dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j])
            else:
                dp[i+1][j]=min(dp[i][j],dp[i+1][j])
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c=map(int,input().split())
if a+b<c and 4*a*b<(c-a-b)**2
    print("Yes")
else:
    print("No")

Fixed submission:
a,b,c=map(int,input().split())
if a+b<c and 4*a*b<(c-a-b)**2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,A,B=map(int,input().split())
M=0
ans=0
for i in range(10**18):
    if M+A+B<=N:
        M=M+A+B
        ans+=A
    elif M+A<=N:
        ans+=A
        break
    else:
        A=N-M
        ans+=A
        break
print(ans)

Fixed submission:
N,A,B=map(int,input().split())
M=0
ans=0
C=A+B
c=N//C
ans=A*c
if N-C*c<A:
    ans+=N-C*c
else:
    ans+=A
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
p=list(map(int,input().split()))
Max=0
for i in range(N+1-K):
    a=0
    for j in range(K):
        a+=(1+p[i+j])/2
    if Max<a:
        Max=a
print(Max)

Fixed submission:
N,K=map(int,input().split())
p=list(map(int,input().split()))
a=0
for j in range(K):
    a+=(1+p[j])/2
Max=a
for i in range(K,N):
    a=a+(p[i]-p[i-K])/2
    if Max<a:
        Max=a
print(Max)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
H,N=map(int,input().split())
List=[]
A=0
B=0
C=10*10*10*10
D=0
for i in range(N):
    a,b=list(map(int,input().split()))
    c=a/b
    List.append((a,b,c))
List1=sorted(List,key=itemgetter(2))
List2=sorted(List,key=itemgetter(0))
for i in range(H):
    if A<H:
        h=H-A
        if h>=List1[N-1][0]:
            A=A+List1[N-1][0]
            B=B+List1[N-1][1]
        else:
            for j in range(N):
                if List2[j][0]>=h:
                    temp1=List2[j][0]
                    temp=List2[j][1]
                    if temp<=C:
                        C=temp
                        D=temp1
            B=B+C
            A=A+D
    elif A>=H:
        break
print(B)

Fixed submission:
H,A=map(int,input().split())
B=H//A
if H%A==0:
    print(B)
else:
    print(B+1)
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+1)
for i in range (1,H+1):
    dp[i]=min(dp[max(i-a,0)]+b for a,b in ab)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+10)
for i in range (1,H+1):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*(H+1)
for i in range (1,H+1):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*(H)
for i in range (1,H+1):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append((a,b))
dp=[0]*(H+1)
for i in range(1,H+1):
    for a,b in AB:
        if dp[i]==0:
            dp[i]=dp[max(i-a,0)]+b
        else:
            dp[i]=min(dp[i],dp[i-a]+b)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append((a,b))
AB.sort()
amax=AB[-1][0]
dp=[0]*(H+1)
for i in range(1,H+1):
    for a,b in AB:
        if dp[i]==0:
            dp[i]=dp[max(i-a,0)]+b
        else:
            dp[i]=min(dp[i],dp[i-a]+b)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
x=0
for i in range(N):
    B=0
    a=P[i]
    for j in range(i+1):
        b=P[j]
        if a>b:
            break
        else:
            B+=1
    if i+1==B:
        x+=1
print(x)

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
x=1
Min=P[0]
for i in range(1,N):
    if Min>P[i]:
        Min=P[i]
        x+=1
print(x)
Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=k:
        j=j//10
    c[i][j]=c[i][j]+1

for i in range(10):
    for j in range(10):
        ans=ans+c[i][j]*c[j][i]
print(ans)

Fixed submission:
N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=j:
        j=j//10
    c[i][j]=c[i][j]+1

for i in range(10):
    for j in range(10):
        ans=ans+c[i][j]*c[j][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=1
gcd=A[0]
for i in range(1,N):
    a=A[i]
    b=math.gcd(a,gcd)
    temp=gcd
    gcd=temp*a//b
    ans=ans*(a//b)+temp//b
    ans%=MOD
print(ans)

Fixed submission:
import fractions
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=1
gcd=A[0]
for i in range(1,N):
    a=A[i]
    b=fractions.gcd(a,gcd)
    temp=gcd
    gcd=temp*a//b
    ans=ans*(a//b)+temp//b
    ans%=MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
comb=[0]*(N)
comb[K-1]=1
ans=0
for i in range(K,N):
    comb[i]=comb[i-1]*i//(i-(K-1))
for i in range(N-K+1):
    ans=ans+comb[N-1-i]*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
fan=[1]*(N+1)
for i in range(2,N+1):
    fan[i]=fan[i-1]*(i)%MOD
ans=0
def comb(a,b):
    return fan[a]*pow(fan[b],MOD-2,MOD)*pow(fan[a-b],MOD-2,MOD)%MOD
for i in range(N-K+1):
    ans=ans+comb(N-i-1,K-1)*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
comb=[0]*(N)
comb[K-1]=1
ans=0
for i in range(K,N):
    comb[i]=comb[i-1]*i//(i-(K-1))
for i in range(N-K+1):
    ans=ans+comb[N-1-i]*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
fan=[1]*(N+1)
for i in range(2,N+1):
    fan[i]=fan[i-1]*(i)%MOD
ans=0
def comb(a,b):
    return fan[a]*pow(fan[b],MOD-2,MOD)*pow(fan[a-b],MOD-2,MOD)%MOD
for i in range(N-K+1):
    ans=ans+comb(N-i-1,K-1)*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
def comb(a,b):
    b=min(a-b,b)
    x,y=1,1
    for i in range(b):
        x*=a-i
        y*=i+1
    return x*pow(y,MOD-2,MOD)%MOD
ans=0
for i in range(N-K+1):
    ans=ans+comb(N-1-i,K-1)*(A[N-1-i]-A[i])%MOD
    ans%=MOD
print(ans)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
fan=[1]*(N+1)
for i in range(2,N+1):
    fan[i]=fan[i-1]*(i)%MOD
ans=0
def comb(a,b):
    return fan[a]*pow(fan[b],MOD-2,MOD)*pow(fan[a-b],MOD-2,MOD)%MOD
for i in range(N-K+1):
    ans=ans+comb(N-i-1,K-1)*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
a=0
for i in range(N):
    if S[i]=="A":
        if S[i+1]=="B":
            if S[i+2]=="C":
                a+=1
                i+=2
print(a)

Fixed submission:
N=int(input())
S=input()
a=0
for i in range(N-2):
    if S[i]=="A":
        if S[i+1]=="B":
            if S[i+2]=="C":
                a+=1
                i+=2
print(a)
Buggy python submission (verdict: Runtime Error):
import math
N,M=map(int,input().split())
a=list(map(int,input().split()))
l=1
count=0
A=a[0]
ans=0
flag=1
while A%2==0:
    A=A//2
    count=count+1
for i in range(N):
    A=a[i]
    b=A//(2**count)
    if b==0 or b%2==0:
        flag=0
        break
    A=A//2
    l=l*A//math.gcd(l,A)
if flag==1:
    ans=M//l
    if ans%2==0:
        print(ans//2)
    else:
        print(ans//2+1)
else:
    print(0)

Fixed submission:
import fractions
N,M=map(int,input().split())
a=list(map(int,input().split()))
l=1
count=0
A=a[0]
ans=0
flag=1
while A%2==0:
    A=A//2
    count=count+1
for i in range(N):
    A=a[i]
    b=A//(2**count)
    if b==0 or b%2==0:
        flag=0
        break
    A=A//2
    l=l*A//fractions.gcd(l,A)
if flag==1:
    ans=M//l
    if ans%2==0:
        print(ans//2)
    else:
        print(ans//2+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
for i in range(K):
    if A>0:
        A-=1
    elif B>0:
        B-=1
print(A,B)

Fixed submission:
A,B,K=map(int,input().split())
if A>=K:
    A=A-K
elif A+B>=K:
    B=B+A-K
    A=0
else:
    A=0
    B=0
print(A,B)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0
for i in range(61):
    a,b=0,0
    for j in range(N):
        if A[j]%2==0:
            a+=1
        else:
            b+=1
        A[j]=A[j]//2
    ans=(ans+(a*b)*2**i)%MOD
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0
for i in range(60):
    a,b=0,0
    for j in range(N):
        if A[j]%2==0:
            a=a+1
        else:
            b=b+1
        A[j]=A[j]//2
    ans=(ans+(a*b)*2**i)%MOD
print(ans)