Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

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

sumA=0
sumB=0
minAB=0

for i in range(n):
    sumA+=A[i]
for i in range(m):
    sumB+=B[i]
for i in range(min(n, m)):
    minAB+=A[i]+B[i]

if sumA+sumB<=k:
    ans=n+m
elif A[0]>k or B[0]>k:
    ans=0
else :
    if minAB>k:
        ans=min(n, m)
        if min(n, m)==n:
            for i in range(min(n, m), max(n, m)):
                if B[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
        else:
            for i in range(min(n, m), max(n, m)):
                if A[i]+minAB<k:
                    minAB+=B[i]
                    ans+=1
    else:
        for i in reversed(0, min(n,m)):
            if minAB-A[i]-B[i]>=k:
                minAB-=A[i]+B[i]
                ans-=2
            else:
                if minAB-A[i]<k or minAB-B[i]<k:
                    ans-=1
                else:
                    ans-=2
print(ans)


Fixed submission:
n, m, k = map(int, input().split())

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

a, b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans, j=0,m

for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))

ans=1
for i in range(n):
    ans*=A[i]
    if ans > 10**18
    break

if ans>10**18:
    print(-1)
else :
    print(ans)


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

ans=1

if 0 in A:
    print(0)
else :
    for i in range(n):
        ans*=A[i]
        if ans > 10**18:
            break

    if ans>10**18:
        print(-1)
    else :
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

ans=1
for i in range(n):
    ans*=A[i]
if ans>10**18:
    print(-1)
else :
    print(ans)


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

ans=1

if 0 in A:
    print(0)
else :
    for i in range(n):
        ans*=A[i]
        if ans > 10**18:
            break

    if ans>10**18:
        print(-1)
    else :
        print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
S=list(map(int,input().split()))
print(len(list(set(S))))


Fixed submission:
n=int(input())
S=[]
for i in range(n):
    S.append(input())
print(len(list(set(S))))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

S=[]
for i in range(n):
    s=input()
    if s not in S:
        S.append(s)
print(len(S))


Fixed submission:
n=int(input())
S=[]
for i in range(n):
    S.append(input())
print(len(list(set(S))))
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
A=list(map(int,input().split()))

for i in range(n):
    print(A.count(i+1))


Fixed submission:
import copy
n=int(input())
A=list(map(int,input().split()))
L=[0]*n

for x in A:
    L[x-1] += 1
for i in L:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)


Fixed submission:
import math
k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,k+1):
        if math.gcd(a,b)==1:
            ans+=k
        else :
            for c in range(1,k+1):
                ans+=math.gcd(math.gcd(a,b),c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if (j-i == k-j) and (s[i] != s[j]) and (s[i] != s[k]) and (s[j] != s[k]):
                cnt += 1
print(r*g*b-cnt)

Fixed submission:
n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(n-1):
    for j in range(1, min(i+1, n-i)):
            if (s[i] != s[i-j]) and (s[i] != s[i+j]) and (s[i-j] != s[i+j]):
                cnt += 1
print(r*g*b-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if len(A)==len(get_unique_list(A)):
    print("YES")
else:
    print("NO")

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

A = list(set(A))

if len(A) == n:
    print('YES')
else :
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

cnt=0
for i in range(n):
    for j in range(i+1,n):
        if A[i]==A[j]:
            cnt+=1
            break

if cnt==1:
    print("NO")
else:
    print("YES")

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

A = list(set(A))

if len(A) == n:
    print('YES')
else :
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

cnt=0
for i in range(n):
    for j in range(i+1,n):
        if A[i]==A[j]:
            cnt+=1

if cnt==0:
    print("YES")
else:
    print("NO")

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

A = list(set(A))

if len(A) == n:
    print('YES')
else :
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n

for i in range(n):
    U[i] = (P[i]+1)/2

ans = sum(U[:k])

for j in range(1, n-k+1):
    t = 0
    for i in range(j, j+k):
        t += U[i]
    if ans < t:
        ans = t
print(ans)


Fixed submission:
import copy
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n

for i in range(n):
    U[i] = (P[i]+1)/2

ans = sum(U[:k])
t = copy.copy(ans)

for i in range(n-k):
    t =  t+U[k+i]-U[i]
    ans = max(ans, t)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n

def s(x):
    t = 0
    for i in range(x):
        t += i+1
    return t/x

for i in range(n):
    U[i] = s(P[i])

ans = 0
for i in range(0, k):
    ans += U[i]

for j in range(1, n-k+1):
    t = 0
    for i in range(j, j+k):
        t += U[i]
    if ans < t:
        ans = t
print(ans)


Fixed submission:
import copy
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n

for i in range(n):
    U[i] = (P[i]+1)/2

ans = sum(U[:k])
t = copy.copy(ans)

for i in range(n-k):
    t =  t+U[k+i]-U[i]
    ans = max(ans, t)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
P=list(map(int,input().split()))
ans=0

for i in range(n):
    M=min(P[0:i+1])
    if M==P[i]:
        ans+=1
print(ans)

Fixed submission:
n=int(input())
P=list(map(int,input().split()))
ans=0
M=P[0]
for i in range(n):
    if M>=P[i]:
        ans+=1
        M=P[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
P=list(map(int,input().split()))
ans=n

for i in range(n):
    for j in range(i):
        if P[i]>P[j]:
            ans-=1
            break
print(ans)

Fixed submission:
n=int(input())
P=list(map(int,input().split()))
ans=0
M=P[0]
for i in range(n):
    if M>=P[i]:
        ans+=1
        M=P[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
 n,m=map(int,input().split())

AC=[0]*n
WA=[0]*n

for i in range(m):
    t=input().split()
    p, s= int(t[0]), t[1]
    if s=='AC':
        AC[p-1]=1
    elif s=='WA' and AC[p-1]==0:
        WA[p-1]+=1

ac, wa=0,0

for i in range(n):
    if AC[i]:
        ac+=1
        wa+=WA[i]
        
print(ac, wa)

Fixed submission:
n,m=map(int,input().split())

AC=[0]*n
WA=[0]*n

for i in range(m):
    t=input().split()
    p, s= int(t[0]), t[1]
    if s=='AC':
        AC[p-1]=1
    elif s=='WA' and AC[p-1]==0:
        WA[p-1]+=1

ac, wa=0,0

for i in range(n):
    if AC[i]:
        ac+=1
        wa+=WA[i]

print(ac, wa)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())

if 2*x <= (a**2)*b:
    print(math.degrees(math.atan((b**2)*a/(2*x))))
else :
    print(90-math.degrees(math.atan((a**3)/(2*((a**2)*b-x)))))

Fixed submission:
import math
a, b, x = map(int, input().split())

if x == a**2*b:
    print(0)
elif 2*x <= (a**2)*b:
    print(math.degrees(math.atan((b**2)*a/(2*x))))
else :
    print(90-math.degrees(math.atan((a**3)/(2*((a**2)*b-x)))))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
L = list(map(int, input().split()))
M = []

for v in itertools.combinations(L, 3):
    M.append(list(v))

cnt = 0

for v in M:
    if v[0] < v[1]+v[2] and v[1] < v[0]+v[2] and v[2] < v[0]+v[1]:
        cnt += 1
        
print(cnt)


Fixed submission:
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

L = [0]*n
for i in range(n):
    L[i] = A.index(i+1)+1
print(*L)


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

L = [0]*n
for i in range(n):
    L[A[i]-1] = i+1
print(*L)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

print(' '.join(list(str(A.index(i+1)+1) for i in range(n))))
    


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

L = [0]*n
for i in range(n):
    L[A[i]-1] = i+1
print(*L)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k, q = map(int, input().split())

A = np.zeros(n, dtype= int)
B = np.array([1]*n)

for i in range(q):
    t = int(input())
    A += B
    A[t-1] -= 1

for i in range(n):
    if A[i] < k:
        print('Yes')
    else :
        print('No')


Fixed submission:
import numpy as np
n, k, q = map(int, input().split())

A = [k for _ in range(n)]

for i in range(q):
    t = int(input())
    A[t-1] +=1

for i in range(n):
    if A[i]-q > 0:
        print('Yes')
    else :
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
H = list(map(int, input().split()))
dp = [0]*n
dp[0] = 1
for i in range(1, n-1):
    if H[i] >= H[i+1]:
        dp[i] += dp[i-1]+1
    else:
        dp[i] = 0
print(max(dp[1:]))
         


Fixed submission:
n = int(input())
H = list(map(int, input().split()))
dp = [0]*n
dp[0] = 1

if n == 1:
    print(0)
else:
    for i in range(1, n-1):
        if H[i] >= H[i+1]:
            dp[i] += dp[i-1]+1
        else:
            dp[i] = 0
    print(max(dp[1:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

for i in range(n):
    print(max(A[:i]+A[i+1:]))


Fixed submission:
import copy
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
B = copy.copy(A)
B.sort()
A_max = B[-1]
A_max2 = B[-2]

for i in range(n):
    if A[i] < A_max:
        print(A_max)
    elif A[i] == A_max:
        print(A_max2)
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())

c=min(a,b)
d=max(a,b)
ans=[]

if a==b:
    ans.append(1)
else:
    for i in range(c):
        if c%(i+1)==0 and d%(i+1)==0:
            ans.append(i+1)
            
print(ans[-k])

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

c=min(a,b)
d=max(a,b)
ans=[]

for i in range(c):
    if c%(i+1)==0 and d%(i+1)==0:
        ans.append(i+1)
            
print(ans[-k])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(float, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(1, n+1):
    for j in range(0, i+1):
        if j > 0:
            dp[i][j] = dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1]
        else :
            dp[i][j] = dp[i-1][j]*(1-p[i-1])

ans = 0
for j in range((n+1)//2, n+1):
    ans += dp[n][j]
print(ans)


Fixed submission:
import numpy as np

n = int(input())
p = list(map(float, input().split()))

dp = np.zeros(n+1)
dp[0] = 1

for i in range(1, n+1):
    dp[1:] = dp[:-1]*p[i-1]+dp[1:]*(1-p[i-1])

print(dp[(n+1)//2])
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb
import itertools

n, k = map(int, input().split())
x = list(map(int, input().split()))
X = []
m = 3*10**8

for v in itertools.combinations(x, k):
    X.append(list(v))

for i in range(comb(n, k, exact=True)):
    m0 = min(X[i])
    m1 = max(X[i])
    a = min(abs(m0)+abs(m1-m0), abs(m1)+abs(m1-m0))
    if m > a:
        m = a
print(m)

Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))
m = 3*10**8

for i in range(n-k+1):
    a = x[i]
    b = x[i+k-1]
    t= min(abs(a)+abs(b-a), abs(b)+abs(b-a))
    if m > t:
        m = t
print(m)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
import itertools

n, k = map(int, input().split())
x = list(map(int, input().split()))
X = []
m = 3*10**8

for v in itertools.combinations(x, k):
    X.append(list(v))

for i in range(comb(n, k, exact=True)):
    m0 = min(X[i])
    m1 = max(X[i])
    a = min(abs(abs(m0)+abs(m1-m0), abs(m1)+abs(m1-m0)))
    if m > a:
        m = a
print(m)

Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))
m = 3*10**8

for i in range(n-k+1):
    a = x[i]
    b = x[i+k-1]
    t= min(abs(a)+abs(b-a), abs(b)+abs(b-a))
    if m > t:
        m = t
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb
import itertools

n, k = map(int, input().split())
x = list(map(int, input().split()))
X = []
m = 3*10**8

for v in itertools.combinations(x, k):
    X.append(list(v))

for i in range(comb(n, k, exact=True)):
    a = min(abs(min(X[i]))+abs(max(X[i])-min(X[i])), abs(max(X[i]))+abs(max(X[i])-min(X[i])))
    if m > a:
        m = a
print(m)

Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))
m = 3*10**8

for i in range(n-k+1):
    a = x[i]
    b = x[i+k-1]
    t= min(abs(a)+abs(b-a), abs(b)+abs(b-a))
    if m > t:
        m = t
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

len_s =  len(s)
L = []

for i in range(1, len_s+1):
    for j in range(len_s-i+1):
        if s[j:j+i] not in L:
            L.append(s[j:j+i])

L.sort()
print(L[k-1])


Fixed submission:
s = input()
k = int(input())

len_s =  len(s)
L = []
m = 0
for i in range(1, k+1):
    for j in range(len_s-i+1):
        if s[j:j+i] not in L:
            L.append(s[j:j+i])


L.sort()
print(L[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

len_s =  len(s)
L = []

for i in range(1, len_s+1):
    for j in range(len_s-i+1):
        L.append(s[j:j+i])
L = list(set(L))
L.sort()
print(L[k-1])


Fixed submission:
s = input()
k = int(input())

len_s =  len(s)
L = []
m = 0
for i in range(1, k+1):
    for j in range(len_s-i+1):
        if s[j:j+i] not in L:
            L.append(s[j:j+i])


L.sort()
print(L[k-1])
Buggy python submission (verdict: Runtime Error):
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    upper_bound = min(wtotal, rtotal)

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left:
            break

    change = op + w + r
    print(min(upper_bound, change))


main()


Fixed submission:
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        # print(f"L:{left}  R:{right}  w:{w}  r:{r}  op:{op}")
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left or right == 0 or left == len(CS) - 1:
            break

    change = op
    print(min(wtotal, rtotal, change))


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input().strip())
    A = [int(_a) for _a in input().strip().split()]
    Q = int(input().strip())
    BCS = []
    for i in range(Q):
        BCS.append([int(_bc) for _bc in input().strip().split()])

    Amap = {}
    for a in A:
        if a not in Amap:
            Amap[a] = 0
        Amap[a] += 1


    for bc in BCS:
        b = bc[0]
        c = bc[1]
        if b in Amap:
            num = Amap[b]
            del Amap[b]
        else:
            num = 0

        if c not in Amap:
            Amap[c] = 0
        Amap[c] += num

        total = 0
        for k,v in Amap.items():
            total += (k*v)
        print(total)

main()



Fixed submission:
def main():
    N = int(input().strip())
    A = [int(_a) for _a in input().strip().split()]
    Q = int(input().strip())
    BCS = []
    for i in range(Q):
        BCS.append([int(_bc) for _bc in input().strip().split()])

    Amap = {}
    for a in A:
        if a not in Amap:
            Amap[a] = 0
        Amap[a] += 1

    total = 0
    for k,v in Amap.items():
        total += (k*v)

    for bc in BCS:
        b = bc[0]
        c = bc[1]
        if b in Amap:
            num = Amap[b]

            del Amap[b]
            if c not in Amap:
                Amap[c] = 0
            Amap[c] += num

            total = total + num*c - num*b

        print(total)

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

def main():
    MAX = 1_000_000_000_000_000_000
    n = int(input())
    nums = [int(_x) for _x in input().split()]
    result = 1
    for num in nums:
        result = result * num

    if result > MAX:
        print(-1)
    else:
        print(result)


main()


Fixed submission:

def main():
    MAX = 1_000_000_000_000_000_000
    n = int(input())
    nums = [int(_x) for _x in input().split()]
    if 0 in nums:
        print(0)
        return

    result = 1
    for num in nums:
        result = result * num
        if result > MAX:
            print(-1)
            return
    print(result)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    ab = [int(_x) for _x in input().split()]
    print(int(ab[0] * ab[1]))


main()


Fixed submission:
def main():
    ab = [_x for _x in input().split()]
    n = ab[1]
    bb = (int(n[0])*100 + int(n[2])*10 + int(n[3]))
    aa = int(ab[0])
    if aa == 0:
        print(0)
        return
    if bb == 0:
        print(0)
        return
    result = str(aa*bb)

    if len(result) <= 2:
        print(0)
    else:
        print(str(result)[:-2])


main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cta=[0]*(n)
ctb=[0]*(n)
for i in range(n):
  cta[a[i]-1]+=1
  ctb[b[i]-1]+=1

for i in range(n):
  if cta[i]+ctb[i]>n:
    print('No')
    exit()

sa=[0]
sb=[0]
for i in range(n):
  sa.append(cta[i]+sa[-1])
  sb.append(ctb[i]+sb[-1])
l=[]
for i in range(n):
  l.append(sa[i+1]-sb[i])
ans=[]
for i in range(n):
  ans.append(str(b[(i-max(l))%n]))
print('Yes')
print(' '.join(ans))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cta=[0]*n
ctb=[0]*n
for i in range(n):
  cta[a[i]-1]+=1
  ctb[b[i]-1]+=1

for i in range(n):
  if cta[i]+ctb[i]>n:
    print('No')
    exit()

sa=[0]
sb=[0]
for i in range(n):
  sa.append(cta[i]+sa[-1])
  sb.append(ctb[i]+sb[-1])
l=[]
for i in range(n):
  l.append(sa[i+1]-sb[i])
ans=[]
maxl=max(l)
for i in range(n):
  ans.append(str(b[(i-maxl)%n]))
print('Yes')
print(' '.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
H=[0]*h
W=[0]*w
for i in range(m):
  H[l[i][0]-1]+=1
  W[l[i][1]-1]+=1
hmax=max(H)
wmax=max(W)
cthmax=0
ctwmax=0
for i in range(h):
  if H[i]==hmax:
    cthmax+=1
for i in range(w):
  if W[i]==wmax:
    ctwmax+=1
ct=0
for i in range(m):
  if H[l[i][0]-1]==max(H) and W[l[i][1]-1]==max(W):
    ct+=1
if cthmax*ctwmax>ct:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)

Fixed submission:
h,w,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
H=[0]*h
W=[0]*w
for i in range(m):
  H[l[i][0]-1]+=1
  W[l[i][1]-1]+=1
hmax=max(H)
wmax=max(W)
cthmax=0
ctwmax=0
for i in range(h):
  if H[i]==hmax:
    cthmax+=1
for i in range(w):
  if W[i]==wmax:
    ctwmax+=1
ct=0
for i in range(m):
  if H[l[i][0]-1]==hmax and W[l[i][1]-1]==wmax:
    ct+=1
if cthmax*ctwmax>ct:
  print(hmax+wmax)
else:
  print(hmax+wmax-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=[]
for i in range(n):
  ct=0
  score=0
  s=[]
  pos=i
  while ct<k:
    ct+=1
    pos=p[pos]-1
    score+=c[pos]
    s.append(score)
    if pos==i:
      break
  if s[-1]<0:
    ans.append(max(s))
  elif pos!=i:
    ans.append(max(s))
  else:
    ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
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):
  ct=0
  score=0
  s=[]
  pos=i
  while ct<k:
    ct+=1
    pos=p[pos]-1
    score+=c[pos]
    s.append(score)
    if pos==i:
      break
  if s[-1]<0:
    ans.append(max(s))
  elif pos!=i:
    ans.append(max(s))
  elif k%len(s)==0:
    ans.append(s[-1]*(k//len(s)-1)+max(s))
  else:
    ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
print(max(ans))

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=[]
for i in range(n):
  ct=0
  score=0
  s=[]
  pos=i
  while ct<k:
    ct+=1
    pos=p[pos]-1
    score+=c[pos]
    s.append(score)
    if pos==i:
      break
  if s[-1]<0:
    ans.append(max(s))
  elif pos!=i:
    ans.append(max(s))
  elif max(s)==max(s[0:k%len(s)]):
    ans.append(s[-1]*(k//len(s))+max(max(s[0:k%len(s)]),0))
  else:
    ans.append(s[-1]*(k//len(s)-1)+max(s))
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):
  ct=0
  score=0
  s=[]
  pos=i
  while ct<k:
    ct+=1
    pos=p[pos]-1
    score+=c[pos]
    s.append(score)
    if pos==i:
      break
  if s[-1]<0:
    ans.append(max(s))
  elif pos!=i:
    ans.append(max(s))
  elif k%len(s)==0:
    ans.append(s[-1]*(k//len(s)-1)+max(s))
  else:
    ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
print(max(ans))