Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

ans=-float('inf')

for start in range(N):
    loop_len=1
    pos=P[start]
    score=C[pos]
    scores=[score]

    while pos!=start:
        loop_len+=1
        pos=P[pos]
        score+=C[pos]
        scores.append(score)
    
    loops=(K-1)//loop_len

    if score>0:
        cand=score*loops + max(scores[:(K%loop_len)])
    else:
        cand=max(scores[:min(K,loop_len)])
    ans=max(ans,cand)
print(ans)

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

ans=-float('inf')

for start in range(N):
    loop_len=1
    pos=P[start]
    score=C[pos]
    scores=[score]

    while pos!=start:
        loop_len+=1
        pos=P[pos]
        score+=C[pos]
        scores.append(score)
    
    loops=(K-1)//loop_len

    if score>0:
        cand=score*loops + max(scores[:(K-loop_len*loops)])
    else:
        cand=max(scores[:min(K,loop_len)])
    ans=max(ans,cand)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

ans=0
A.sort()

f=[0]*1000005

for i in A:
    f[i]+=1

for i in range(1,1000001,1):
    if f[i]==0:
        continue
    j=i+i
    while j<=1000000:
        f[j]+=f[i]
        j=j+i

for i in A:
    if f[i]==1:
        ans+=1


print(ans)

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

ans=0
A.sort()

f=[0]*1000005

for i in A:
    f[i]+=1

for i in range(1,1000001,1):
    if f[i]==0:
        continue
    j=i+i
    while j<=1000000:
        f[j]+=f[i]
        j=j+i

for i in A:
    if f[i]==1:
        ans+=1


print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())

if K<A:
    ans1=A-K
else:
    ans1=0
    ans2=max(A+B-K,0)

print(ans1,ans2)

Fixed submission:
A,B,K=map(int,input().split())

if K<A:
    ans1=A-K
    ans2=B
else:
    ans1=0
    ans2=max(A+B-K,0)

print(ans1,ans2)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N=int(input())
S=input()

ans=0

for i in itertools.product(range(0,10),repeat=3):

    isOK=[False]*3
    
    for x in range(len(S)):
        if isOK[0] and isOK[1]:
            if int(S[x])==i[2]:
                ans+=1
                break
        elif isOK[0]:
            if int(S[x])==i[1]:
                isOK[1]=True
        else:
            if int(S[x])==i[0]:
                isOK[0]=True

print(ans)

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

ans=0

for i in itertools.product(range(0,10),repeat=3):

    isOK=[False]*3
    
    for x in range(len(S)):
        if isOK[0] and isOK[1]:
            if int(S[x])==i[2]:
                ans+=1
                break
        elif isOK[0]:
            if int(S[x])==i[1]:
                isOK[1]=True
        else:
            if int(S[x])==i[0]:
                isOK[0]=True

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
s=[sorted(input()) for i in range(N)]

def factorial(num):
    x=1
    for i in range(num,0,-1):
        x = x *i

    return x

s.sort()

ans=0
ref=s[0]

cnt=1

for i in range(1,N):
    if s[i]==ref:
        cnt+=1
        if i==N-1:
            ans+=factorial(cnt)//factorial(cnt-2)//2
    else:
        ref=s[i]
        if cnt>1:
            ans+=factorial(cnt)//factorial(cnt-2)//2
        cnt=1

print(ans)

Fixed submission:
from collections import Counter
N=int(input())
s=[str(sorted(input())) for i in range(N)]

ans=0
cnt={}

for i in range(N):
    if s[i] in cnt:
        ans+=cnt[s[i]]
        cnt[s[i]]+=1
    else:
        cnt[s[i]]=1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
x =list(map(int,input().split()))

ans=0
if m==1:
    ans=0
else:


    x.sort()

    diff=[0]*(m-1)

    for i in range(m-1):
        diff[i]=x[i+1]-x[i]

    diff.sort()

    ans=0
    if n<=m:
        for i in range(m-n):
            ans+=diff[i]
    else:
        for i in range(diff.size()):
            ans+=diff[i]

print(ans)


Fixed submission:
import sys
n,m=map(int,input().split())
x =list(map(int,input().split()))

ans=0
if n>=m:
    ans=0
else:
    x.sort()
    diff=[0]*(m-1)

    for i in range(m-1):
        diff[i]=x[i+1]-x[i]

    diff.sort()

    ans=0
    
    for i in range(m-n):
        ans+=diff[i]

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
x =list(map(int,input().split()))

if m==1:
    print(0)
    sys.exit()

x.sort()

diff=[0]*(m-1)

for i in range(m-1):
    diff[i]=x[i+1]-x[i]

diff.sort()

ans=0
if n<=m:
    for i in range(m-n):
        ans+=diff[i]
else:
    for i in range(diff.size()):
        ans+=diff[i]

print(ans)


Fixed submission:
import sys
n,m=map(int,input().split())
x =list(map(int,input().split()))

ans=0
if n>=m:
    ans=0
else:
    x.sort()
    diff=[0]*(m-1)

    for i in range(m-1):
        diff[i]=x[i+1]-x[i]

    diff.sort()

    ans=0
    
    for i in range(m-n):
        ans+=diff[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))



if N>K:
    dp=[1000000000]*N
    dp[0]=0
    for i in range(1,K):
        dp[i]=abs(H[i]-H[0])

    for i in range(K,N):
        for j in range(1,K+1):
            dp[i]=min(dp[i], dp[i-j]+abs(H[i-j]-H[i]))

    print(dp[N-1])

else:
    print(abs(H[N-1]-H[0]))

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



if N>K:
    dp=[1000000000]*N
    dp[0]=0
    for i in range(1,K):
        dp[i]=abs(H[i]-H[0])

    for i in range(K,N):
        for j in range(1,K+1):
            dp[i]=min(dp[i], dp[i-j]+abs(H[i-j]-H[i]))

    print(dp[N-1])

else:
    print(abs(H[N-1]-H[0]))
Buggy python submission (verdict: Runtime Error):
n= int(input())
D=list(map(int,input().split()))

m=int(input())
T=list(map(int,input().split()))

cnt=[0]*1000000010

for i in range(n):
    cnt[D[i]]+=1

ans="YES"
for i in range(m):
    cnt[T[i]]-=1
    if cnt[T[i]]<0:
        ans="NO"
        break

print(ans)


Fixed submission:
from collections import defaultdict
n= int(input())
D=list(map(int,input().split()))

m=int(input())
T=list(map(int,input().split()))

dicta=defaultdict(lambda:0)
dictb=defaultdict(lambda:0)

for i in range(n):
    dicta[D[i]]+=1

for i in range(m):
    dictb[T[i]]+=1


ans="YES"
for i in range(m):
    if dicta[T[i]]<dictb[T[i]]:
        ans="NO"
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split()))

ans=0
for i in range(N):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        ans+=1
print(ans)

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

ans=0
for i in range(N-1):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        ans+=1

if p[N-1]==N:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

c=[0]*(max(a)+10)

for i in range(n):
    c[a[i]]+=1

short_edge=0
long_edge=0
for i in range(len(c)):
    if c[i]>=4:
        long_edge=i
        short_edge=i
    elif c[i]>=2:
        short_edge=long_edge
        long_edge=i
    else:
        pass

print(long_edge*short_edge)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

cnt=Counter(a)
edge=[0,0]

for i in cnt:
    if cnt[i]>=4:
        edge.append(i)
    if cnt[i]>=2:
        edge.append(i)

edge.sort(reverse=True)
print(edge[0]*edge[1])

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

c=[0]*(max(a)+10)

for i in range(n):
    c[a[i]]+=1

short_edge=0
long_edge=0
for i in range(len(c)):
    if c[i]>=4:
        long_edge=i
        short_edge=i
    elif c[i]>=2:
        short_edge=long_edge
        long_edge=i
    else:
        pass

print(long_edge*short_edge)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

cnt=Counter(a)
edge=[0,0]

for i in cnt:
    if cnt[i]>=4:
        edge.append(i)
    if cnt[i]>=2:
        edge.append(i)

edge.sort(reverse=True)
print(edge[0]*edge[1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

turn=A[1]-A[0]
ans=1

if N>2:
    for i in range(1,N-1):
        judge=turn * (A[i+1]-A[i])

        if judge<0:
            ans+=1
            turn=0
        else:
            turn=A[i+1]-A[i]

print(ans)

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

ans=1
x=y=0
c=A[0]

for i in range(1,N):
    if c < A[i]:
        x=1
    elif c>A[i]:
        y=1
    
    if x==1 and y==1:
        ans+=1
        x=y=0
    
    c=A[i]

print(ans)

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

turn=A[1]-A[0]
ans=1
for i in range(1,N-1):
    judge=turn * (A[i+1]-A[i])

    if judge<0:
        ans+=1
        turn=0
    else:
        turn=A[i+1]-A[i]

print(ans)

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

ans=1
x=y=0
c=A[0]

for i in range(1,N):
    if c < A[i]:
        x=1
    elif c>A[i]:
        y=1
    
    if x==1 and y==1:
        ans+=1
        x=y=0
    
    c=A[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

mod=1000000007
n=input();
arr = list(map(int, raw_input().split()))
l=arr[0];
for i in arr:
    x=gcd(l,i)
    l=(l*i)/x
    
ans=0
#print l
for i in arr:
    b=l/i
    ans=(ans%mod + b%mod)%mod
ans=(ans%mod +mod)%mod
print ans


Fixed submission:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

mod=1000000007
n=input();
arr = list(map(int, raw_input().split()))
l=arr[0];
for i in arr:
    x=gcd(l,i)
    l=(l*i)/x
    
ans=0
#print l
for i in arr:
    b=l/i
    ans+=b
ans=(ans%mod +mod)%mod
print ans
Buggy python submission (verdict: Time Limit Exceeded):
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
        for j in  range(i+1, n):
                ans  += ((a[i] %mod) * (a[j] % mod)) % mod
                ans = ans % mod
print(ans)

Fixed submission:
d = 1000000007
n = int(input())
a = list(map(int, input().split()))
summation = sum(a)
diagonal = 0
for i in range(len(a)):
        diagonal += a[i] ** 2 
ans = (((summation  ** 2) - diagonal) // 2) % d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
        for j in  range(i+1, n):
                ans  += (a[i] * a[j]) %((10**9) + 7)
                ans  = ans % ((10**9) + 7)
print(ans)

Fixed submission:
d = 1000000007
n = int(input())
a = list(map(int, input().split()))
summation = sum(a)
diagonal = 0
for i in range(len(a)):
        diagonal += a[i] ** 2 
ans = (((summation  ** 2) - diagonal) // 2) % d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
        for j in  range(i+1, n):
                ans  += (a[i] * a[j]) %((10**9) + 7)
                ans  = ans % ((10**9) + 7)
print(ans)

Fixed submission:
d = 1000000007
n = int(input())
a = list(map(int, input().split()))
summation = sum(a)
diagonal = 0
for i in range(len(a)):
        diagonal += a[i] ** 2 
ans = (((summation  ** 2) - diagonal) // 2) % d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
        for j in  range(i+1, n):
                ans += a[i] * a[j]
                ans = ans % ((10**9) + 7)
print(ans)

Fixed submission:
d = 1000000007
n = int(input())
a = list(map(int, input().split()))
summation = sum(a)
diagonal = 0
for i in range(len(a)):
        diagonal += a[i] ** 2 
ans = (((summation  ** 2) - diagonal) // 2) % d
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(nput())
price = []
cost = 0
for p in range(n + 1):
        p = int(input())
        price.append(p)

price.sort()
for  p in price:
        cost += p

print(price)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)

Buggy python submission (verdict: Runtime Error):
n = input()
k = input()
price = []
cost = 0
for p in range(n + 1):
        p = int(input())
        price.append(p)

price.sort(reverse = True)
for  p in price:
        cost += p

print(price)

Fixed submission:
n, k,  =map(int, input().split())
cost = 0
price = list(map(int, input().split()))
        
price.sort()
del price[k:]
for p in price:
        cost += p

print(cost)
Buggy python submission (verdict: Runtime Error):
 a, b, c, d = map(int, input().split())
print(max(min(b, d) - max(a, c), 0))

Fixed submission:
a, b, c, d = map(int, input().split())
if a < c:
        if b < c:
                print(0)
        if c <= b <= d:
                print(abs(b-c))
        if d < b:
                print(abs(d-c))
if c <= a:
        if d < a:
                print(0)
        if a <= d <= b:
                print(abs(d-a))
        if b < d:
                print(abs(b-a))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A =  list(map(int, input().split()))
r = 0
m = 10**9+7
for x in itertools.combinations(A, 2):
    r += x[0]*x[1]
print(r % m)

Fixed submission:
import itertools
N = int(input())
A =  list(map(int, input().split()))
sa = sum(A)
r = 0
xx = sa
m = 10**9+7
for x in A:
    xx -= x
    r += x*xx
    r = r % m
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A =  list(map(int, input().split()))
r = 0
m = 10**9+7
for x in itertools.combinations(A, 2):
    r += x[0]*x[1]
    r = r % m
print(r)

Fixed submission:
import itertools
N = int(input())
A =  list(map(int, input().split()))
sa = sum(A)
r = 0
xx = sa
m = 10**9+7
for x in A:
    xx -= x
    r += x*xx
    r = r % m
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = 1
pre = 0
for i, a in enumerate(A):
    i += 1
    if i > K:
        r = r // A[i-K-1]
    r *= a
    if i > K:
        print("Yes" if r > pre else "No")
    pre = r

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i, a in enumerate(A):
    if i+1 > K:
        print("Yes" if a > A[i-K] else "No")
Buggy python submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
lasts = [0] * 26
score = 0
for d in range(D):
    bs = 0
    ba = None
    for t in range(26):
        s = S[d][t]
        s -= sum(C[i] * (d+1-l) for i, l in enumerate(lasts) if i != t)
        if s > bs:
            bs = s
            ba = t
    score += bs
    lasts[ba] = d
    print(ba+1)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
lasts = [0] * 26
score = 0
for d in range(D):
    bs = None
    ba = None
    for t in range(26):
        s = S[d][t]
        s -= sum(C[i] * (d+1-l) for i, l in enumerate(lasts) if i != t)
        if bs is None or s > bs:
            bs = s
            ba = t
    score += bs
    lasts[ba] = d
    print(ba+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
D = 60
to = [None] * D
to[0] = [None] * N
for i, a in enumerate(map(int, input().split())):
    to[0][i] = a - 1
for t in range(1, D):
    to[t] = [None] * N
    for i in range(N):
        to[t][i] = to[t-1][to[t-1][i]]
v = 0
for i in reversed(range(D)):
    l = 1<<i
    if l <= K:
        v = to[i][v]
        K -= l
        if K <= 0:
            print(v + 1)
            exit()

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = [None] * N
i = 0
cur = 0
m = None
while True:
    if m is None and r[cur] is not None:
        m = i - r[cur]
        K = i + (K-i)%m
    else:
        r[cur] = i
    if i == K:
        print(cur+1)
        exit()
    i += 1
    cur = A[cur] - 1

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = [None] * N
i = 0
cur = 0
m = None
while True:
    if r[cur] is not None:
        m = i - r[cur]
        K -= ((K-i)//m)*m
    r[cur] = i
    i += 1
    if i == K:
        print(A[cur])
        exit()
    cur = A[cur] - 1

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = [None] * N
i = 0
cur = 0
m = None
while True:
    if m is None and r[cur] is not None:
        m = i - r[cur]
        K = i + (K-i)%m
    else:
        r[cur] = i
    if i == K:
        print(cur+1)
        exit()
    i += 1
    cur = A[cur] - 1
Buggy python submission (verdict: Runtime Error):
import math

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

print((A * B) // math.gcd(A, B))

Fixed submission:
import fractions

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

print((A * B) // fractions.gcd(A, B))
Buggy python submission (verdict: Runtime Error):
H, W, K = map(int, input().split())

result = list()

l = list()
kk = 0
nls = list()
for hh in range(H):
    ll = input()
    s = [(i, x) for i, x in enumerate(ll) if x == '#']
    ln = len(s)
    nl = list()
    if ln == 0:
        nls.append(hh)
    elif ln == 1:
        kk += 1
        nl = [kk] * W
    else:
        for p, _ in s:
            kk += 1
            nl.extend([kk] * (1 if p == 0 else p))
    l.append(nl)

for i in nls:
    for j in range(W):
        l[i].append(l[(i - 1 if i > 0 else i + 1)][j])

for h in l:
    print(' '.join(map(str, h)))

Fixed submission:
H, W, K = map(int, input().split())

result = list()

l = list()
kk = 0
nls = list()
for hh in range(H):
    ll = input()
    s = [i+1 for i, x in enumerate(ll) if x == '#']
    ln = len(s)
    nl = list()
    if ln == 0:
        nls.append(hh)
    elif ln == 1:
        kk += 1
        nl = [kk] * W
    else:
        pre = 0
        for i, p in enumerate(s):
            kk += 1
            pp = p - (s[i-1] if i > 0 else 0)
            nl.extend([kk] * (1 if pp == 0 else pp))
            pre = p
    if len(nl) < W:
        nl.extend([kk] * (W - len(nl)))
    l.append(nl)

for i in nls:
    if i > 0 and l[i-1] not in nls:
        l[i] = l[i-1]
    else:
        for j in range(i + 1, H):
            if j in nls:
                continue
            l[i] = l[j]
            break

for h in l:
    print(' '.join(map(str, h)))
Buggy python submission (verdict: Runtime Error):
while True:
    try:
        M, D = map(int, input().split())
        result = 0
        if D >= 22:
            for i in range(22, D+1):
                i = str(i)
                mm = MAPS[i] if i in MAPS else None
                if mm is not None and mm <= M:
                    result += 1
        print(result)

    except EOFError:
        break

Fixed submission:
while True:
    MAPS = {'22': 4, '23': 6, '24': 8, '25': 10, '26': 12, '27': 14, '28': 16, '29': 18, '32': 6, '33': 9, '34': 12, '35': 15, '36': 18, '37': 21, '38': 24, '39': 27, '42': 8, '43': 12, '44': 16, '45': 20, '46': 24, '47': 28, '48': 32, '49': 36, '52': 10, '53': 15, '54': 20, '55': 25, '56': 30, '57': 35, '58': 40, '59': 45, '62': 12, '63': 18, '64': 24, '65': 30, '66': 36, '67': 42, '68': 48, '69': 54, '72': 14, '73': 21, '74': 28, '75': 35, '76': 42, '77': 49, '78': 56, '79': 63, '82': 16, '83': 24, '84': 32, '85': 40, '86': 48, '87': 56, '88': 64, '89': 72, '92': 18, '93': 27, '94': 36, '95': 45, '96': 54, '97': 63, '98': 72, '99': 81}
    try:
        M, D = map(int, input().split())
        result = 0
        if D >= 22:
            for i in range(22, D+1):
                i = str(i)
                mm = MAPS[i] if i in MAPS else None
                if mm is not None and mm <= M:
                    result += 1
        print(result)

    except EOFError:
        break