Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

K = int(input())
X = int(input())
s = X-K+1
for i in range(2*K -1):
    A = s+i
    print(str(A)+' ')

Fixed submission:
S = input().split()
K = int(S[0])
X = int(S[1])
s = X-K+1
e = X+K-1
for i in range(s, e):
    print(str(i)+' ')
print(e)

Buggy python submission (verdict: Runtime Error):
K = int(input())
X = int(input())
s = X-K+1
e = X+K-1
for i in range(s,e):
    print(str(i)+' ')

Fixed submission:
S = input().split()
K = int(S[0])
X = int(S[1])
s = X-K+1
e = X+K-1
for i in range(s, e):
    print(str(i)+' ')
print(e)

Buggy python submission (verdict: Runtime Error):
K = int(input())
X = int(input())
s = X-K+1
e = X+K-1
for i in range(s,e):
    print(i)

Fixed submission:
S = input().split()
K = int(S[0])
X = int(S[1])
s = X-K+1
e = X+K-1
for i in range(s, e):
    print(str(i)+' ')
print(e)
Buggy python submission (verdict: Runtime Error):
a = map(int,input().split())
unchi = 0
while a>=1:
    a -=1
    if 99999 >= a >= 10000:
        unchi += 1
    elif 999 >= a >= 100:
        unchi += 1
    elif 9 >= a >= 1:
        unchi += 1
print(unchi)


Fixed submission:
a = int(input())
unchi = 0
while a>=1:
    if 99999 >= a >= 10000:
        unchi += 1
    elif 999 >= a >= 100:
        unchi += 1
    elif 9 >= a >= 1:
        unchi += 1
    a -= 1
print(unchi)
Buggy python submission (verdict: Runtime Error):

N = int(input())
H = input().split()
for i in range(N):
    H[i] = int(H[i])

ochinchin = True
for i in range(N):
    if H[i+1]<H[i]:
        H[i] -= 1
        if H[i+1]<H[i]:
            ochinchin = False
            break

if ochinchin:
    print("Yes")
else:
    print("No")


Fixed submission:
N = int(input())
H = []
H = input().split(" ")
for i in range(N):
    H[i] = int(H[i])-1

ochinchin = True
for i in range(1, N):
    if H[i] < H[i-1]:
        H[i] += 1
        if H[i] < H[i-1]:
            ochinchin = False
            break
            

if ochinchin:
    print("Yes")
else:
    print("No")

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

for i in range(N):

    if A[i] > A[i+1]:
        A[i] -= 1
        if A[i] <= A[i+1]:
            chinpo += 1
    else:
        chinpo += 1

if chinpo == N-1:
    print("Yes")
else:
    print("No")



Fixed submission:
N = int(input())
H = []
H = input().split(" ")
for i in range(N):
    H[i] = int(H[i])-1

ochinchin = True
for i in range(1, N):
    if H[i] < H[i-1]:
        H[i] += 1
        if H[i] < H[i-1]:
            ochinchin = False
            break
            

if ochinchin:
    print("Yes")
else:
    print("No")

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

for i in range(N-1):

    if A[i+1] > A[i+2]:
        A[i+1] -= 1
        if A[i+2] >= A[i+1]:
            chinpo += 1
    else:
        chinpo += 1

if chinpo == N-1:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
H = []
H = input().split(" ")
for i in range(N):
    H[i] = int(H[i])-1

ochinchin = True
for i in range(1, N):
    if H[i] < H[i-1]:
        H[i] += 1
        if H[i] < H[i-1]:
            ochinchin = False
            break
            

if ochinchin:
    print("Yes")
else:
    print("No")

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

for i in range(N-1):

    if A[i] > A[i+1]:
        A[i] -= 1
        if A[i+1] >= A[i]:
            chinpo += 1
    else:
        chinpo += 1

if chinpo == N-1:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
H = []
H = input().split(" ")
for i in range(N):
    H[i] = int(H[i])-1

ochinchin = True
for i in range(1, N):
    if H[i] < H[i-1]:
        H[i] += 1
        if H[i] < H[i-1]:
            ochinchin = False
            break
            

if ochinchin:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
for i in range(pon[-1]+1):
    if (poi[k]-i)%2==0:#L
        ans[poi[k]]+=1
    else:
        ans[poi[k]+1]+=1
    #print(ans)
    if i==pon[k]:
        k+=1
for i in range(pon[-1]+1,len(s)):
    if (poi[k]-i) % 2 == 0:  # L
        ans[poi[k]] += 1
    else:
        ans[poi[k]+1] += 1

print(*ans)


Fixed submission:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
if pon!=[]:
    for i in range(pon[-1]+1):
        if (poi[k]-i)%2==0:#L
            ans[poi[k]]+=1
        else:
            ans[poi[k]+1]+=1
        #print(ans)
        if i==pon[k]:
            k+=1
    for i in range(pon[-1]+1,len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1
else:
    for i in range(len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1      
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
#Slist = list(S)
#A = list(map(int, input().split()))
answer = ()
chinpo = True

while True:
        
    kintama = S.find("RL")

    if (int(kintama) % 2 == 0):
        for i in range(int(kintama)-2):
            print("0")
        print(int(kintama)-1)
        print("0")
        S[int(kintama):]
    else:
        for i in range(int(kintama)-1):
            print("0")
        print(int(kintama)-1)
        S[int(kintama):]


Fixed submission:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
if pon!=[]:
    for i in range(pon[-1]+1):
        if (poi[k]-i)%2==0:#L
            ans[poi[k]]+=1
        else:
            ans[poi[k]+1]+=1
        #print(ans)
        if i==pon[k]:
            k+=1
    for i in range(pon[-1]+1,len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1
else:
    for i in range(len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1      
print(*ans)
Buggy python submission (verdict: Runtime Error):

LR = input().split()
L = int(LR[0])
R = int(LR[1])
S = []

if R - L >= 2019:
    print("0")
else:
    for i in range(L+1,R):
        for j in range(i+1,R+1):
            S.append(i * j % 2019)
    print(min(S))



Fixed submission:

LR = input().split()
L = int(LR[0])
R = int(LR[1])
S = []

if R - L >= 2019:
    print("0")
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            S.append(i * j % 2019)
    print(min(S))

Buggy python submission (verdict: Runtime Error):

LR = input().split()
L = int(LR[0])
R = int(LR[1])
S = []

if R - L > 2019:
    print("0")
else:
    for i in range(L,R-1):
        for j in range(i-1,R):
            S.append(i * j % 2019)
    print(min(S))




Fixed submission:

LR = input().split()
L = int(LR[0])
R = int(LR[1])
S = []

if R - L >= 2019:
    print("0")
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            S.append(i * j % 2019)
    print(min(S))
Buggy python submission (verdict: Runtime Error):
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]


def aa(N,AB):
    AB.sort(key=lambda x: x[1])
    for i in range(N-1):
        clk += AB[i][0]
        if clk >= AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa(N,AB))

Fixed submission:
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x: x[1])

def aa(N,AB):
    clk = 0
    flg = True
    for i in range(N):
        clk += AB[i][0]
        if clk > AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa(N,AB))

Buggy python submission (verdict: Runtime Error):
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]


def aa(N,AB):
    AB.sort(key=lambda x: x[1])
    for i in range(N-1):
        clk += AB[i][0]
        if clk >= AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa())

Fixed submission:
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x: x[1])

def aa(N,AB):
    clk = 0
    flg = True
    for i in range(N):
        clk += AB[i][0]
        if clk > AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa(N,AB))
Buggy python submission (verdict: Runtime Error):

#N = int(input())
A = input().split()
#B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
#for i in range(N):
#    B[i] = int(B[i])

ue = A[0]*(A[1]-A[2])
shita = A[0]*A[2]
migi = A[1]*(A[0]-A[3])
hidari = A[1]*A[3]
chinpo = True

if ue > shita:
    if migi > hidari:
        if migi == ue:
            print(str(ue) + " " + "1")
        else:
            print(str(ue) + " " + "0")
    else:
        if migi == hidari:
            print(str(migi) + " " + "1")
            chinpo = False 
        if hidari == ue & chinpo:
            print(str(ue) + " " + "1")
        else:
            print(str(ue) + " " + "0")
else:
    if ue == shita:
        print(str(ue) + " " + "1")
        chinpo = False
    if migi > hidari & chinpo:
        if migi == ue:
            print(str(ue) + " " + "1")
        else:
            print(str(ue) + " " + "0")
    else:
        if migi == hidari:
            print(str(migi) + " " + "1")
            chinpo = False
        if hidari == ue & chinpo:
            print(str(ue) + " " + "1")
        else:
            print(str(ue) + " " + "0")


Fixed submission:

L = list(map(int, input().split()))
if L[2] == L[0]/2 and L[3] == L[1]/2:
    print(L[0]*L[1]/2,1)
else:
    print(L[0]*L[1]/2, 0)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import math
n=int(input())
a=list(map(int,input().split()))
for i in range(n-1):
    a[i+1]=math.gcd(a[i],a[i+1])
print(min(a))

Fixed submission:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import fractions
n=int(input())
a=list(map(int,input().split()))
for i in range(n-1):
    a[i+1]=fractions.gcd(a[i],a[i+1])
print(min(a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp=[0]+[1000000000]*(n-1)

for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[-1])


Fixed submission:
import sys
input = sys.stdin.buffer.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp=[0]+[1000000000]*(n-1)

for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        flg = True
        print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s)
    for j in range(len(t)):
        li[cnt+j]=t[j]
    print("".join(li))



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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
cnt = 0

for i in range(len(s)-len(t)+1)[::-1]:
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt = i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?", "a"))
    #print(li)
    for j in range(len(t))[::-1]:
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)
if n<10:
    if a[0]!=0:
        print(a[1])
        sys.exit()
    else:
        print(a[0])
        sys.exit()

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq[::-1])>=n:
            print(qqq[::-1])
            sys.exit()
        q.append(qqq[::-1])


Fixed submission:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)
for i in range(len(a)):
    if int(a[i])>=n:
        print(a[i])
        sys.exit()

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq[::-1])>=n:
            print(qqq[::-1])
            sys.exit()
        q.append(qqq[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

s = set()
for i in range(k):
    l, r = map(int, input().split())
    for i in range(l, r+1):
        s.add(i)

mod = 998244353
col = list(s)
counts = [0]*(n+1)
for i in range(1, n+1):
    for c in col:
        if c > i:
            break
        if c == i:
            counts[i] += 1
            counts[i] = counts[i] % mod
            continue
        else:
            counts[i] += counts[i-c]
            counts[i] = counts[i] % mod

print(counts[n-1] % mod)

Fixed submission:
n, k = map(int, input().split())
# n, k = (2*10**5, 10)


ranges = []
for i in range(k):
    l, r = map(int, input().split())
    # f = (2 * 10 ** 5) // k
    # l, r = (f * i, f*(i+1))
    ranges.append((l, r))

mod = 998244353
counts = [0]*(n+1)
sum_dp = [0]*(n+2)
counts[0] = 1
sum_dp[1] = 1
for i in range(1, n+1):
    for r in ranges:
        left = max(0, i - r[1])
        right = max(0, i - r[0] + 1)
        counts[i] += (sum_dp[right] - sum_dp[left])
        counts[i] = counts[i] % mod
    sum_dp[i+1] = sum_dp[i] + counts[i]


print(counts[n-1] % mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

maxV = (10 ** 6 + 1)

sieve = [i for i in range(maxV)]
p = 2

while p*p < maxV:
    if sieve[p] == p:
        for q in range(p*2, maxV, p):
            if sieve[q] == q:
                sieve[q] = p
    p += 1

from math import gcd

g = 0
primes = set()
for a in A:
    g = gcd(g, A)

    v = a
    while a > 1:
        prime = sieve[a]
        if prime in primes:
            print('')
        primes.add(prime)
        a = a // prime


if g > 1:
    print('not coprime')

for a in A:
    while a > 1:
        prime = sieve[a]
        if prime in primes:
            print('pairwise coprime')
            exit()
        primes.add(prime)
        a = a // prime

print('setwise coprime')

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

maxV = (10 ** 6 + 1)

sieve = [i for i in range(maxV)]
p = 2

while p*p < maxV:
    if sieve[p] == p:
        for q in range(p*2, maxV, p):
            if sieve[q] == q:
                sieve[q] = p
    p += 1

from math import gcd

g = 0
primes = set()
for a in A:
    g = gcd(g, a)

    v = a


if g > 1:
    print('not coprime')
    exit()

for a in A:
    temp_prime = set()
    while a > 1:
        prime = sieve[a]
        temp_prime.add(prime)
        a = a // prime

    for t in temp_prime:
        if t in primes:
            print('setwise coprime')
            exit()
        primes.add(t)

print('pairwise coprime')
Buggy python submission (verdict: Runtime Error):
def main():
    H, W, M = map(int, input().split())
    # H, W, M = (3 * 10 ** 5, 3 * 10 ** 5, 3 * 10 ** 5)

    row = [0] * (H + 1)
    row_set = dict()
    column = [0] * (W + 1)
    column_set = dict()
    # import random

    for m in range(M):
        h, w = map(int, input().split())

        # h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
        row[h] += 1
        if h in row_set:
            row_set[h].add(w)
        else:
            row_set.update({h: set({w})})

        column[w] += 1
        if w in column_set:
            column_set[w].add(h)
        else:
            column_set.update({w: set({h})})

    flatten_max_rows = []
    maxR = -1
    for i, v in enumerate(row[1:]):
        if v > maxR:
            flatten_max_rows = []
            if v != 0:
                flatten_max_rows += list(row_set[i+1])
            maxR = v
        elif v == maxR:
            flatten_max_rows += list(row_set[i+1])
    flatten_max_rows_set = set(flatten_max_rows)

    maxC = max(column)
    for i, v in enumerate(column[1:]):
        if v == maxC:
            if i+1 not in flatten_max_rows_set:
                print(maxR + maxC)
                exit()

    print(maxR + maxC - 1)
main()


Fixed submission:
def main():
    H, W, M = map(int, input().split())
    # H, W, M = (3 * 10 ** 5, 3 * 10 ** 5, 3 * 10 ** 5)

    row = [0] * (H + 1)
    row_set = [set() for _ in range(H+1)]
    column = [0] * (W + 1)
    column_set = [set() for _ in range(W+1)]
    # import random
    ms = []
    positions = set()
    for m in range(M):
        h, w = map(int, input().split())

        positions.add((h, w))
        # h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
        row[h] += 1
        row_set[h].add(w)

        column[w] += 1
        column_set[w].add(h)



    max_rows = set()
    maxR = -1
    for i, v in enumerate(row[1:]):
        if v > maxR:
            max_rows = set()
            max_rows.add(i+1)
            maxR = v
        elif v == maxR:
            max_rows.add(i+1)


    max_cols = set()
    maxC = -1
    for i, v in enumerate(column[1:]):
        if v > maxC:
            max_cols = set()
            max_cols.add(i+1)
            maxC = v
        elif v == maxC:
            max_cols.add(i + 1)


    for y in max_rows:
        for x in max_cols:
            if not (y, x) in positions:
                print(maxR + maxC)
                exit()
    print(maxR + maxC - 1)
main()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())


ps = list(map(int, input().split()))
cs = list(map(int, input().split()))

graphs = []
vGraphs = []
flags = [False]*n
for i in range(len(ps)):
    p = ps[i]
    index = p - 1
    if flags[index]:
        continue

    current = set()
    values = set()
    currentIndex = index
    while True:
        if flags[currentIndex]:
            break

        current.add(currentIndex)
        values.add(cs[currentIndex])
        flags[currentIndex] = True
        nextIndex = ps[currentIndex] - 1
        currentIndex = nextIndex
    graphs.append(current)
    vGraphs.append(values)

answer = -float('inf')
for i in range(n):
    index = ps[i] - 1
    value = cs[index]

    searchI = 0
    while True:
        vg = vGraphs[searchI]
        if value in vg:
            currentGraph = vg
            break
        searchI += 1

    total = sum(currentGraph)

    currentSum = 0
    count = 0
    ci = i
    while True:
        count += 1
        if count > k:
            break
        loop = (k - count) // len(currentGraph)
        multi = max(0, total) * loop

        ci = ps[ci] - 1

        currentV = cs[ci]
        currentSum += currentV

        answer = max(answer, multi + currentSum)
        if ci == i:
            break

print(answer)

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


ps = list(map(int, input().split()))
cs = list(map(int, input().split()))

graphs = []
vGraphs = []
flags = [False]*n
sumDict = dict()
for i in range(len(ps)):
    p = ps[i]
    index = p - 1
    if flags[index]:
        continue

    current = set()
    values = set()
    currentIndex = index
    while True:
        if flags[currentIndex]:
            break

        current.add(currentIndex)
        values.add(cs[currentIndex])
        flags[currentIndex] = True
        nextIndex = ps[currentIndex] - 1
        currentIndex = nextIndex
    graphs.append(current)
    vGraphs.append(values)

answer = -float('inf')
for i in range(n):

    searchI = 0
    loopSum = 0
    nextIndex = i
    loopCount = 0
    while True:
        nextIndex = ps[nextIndex] - 1
        loopSum += cs[nextIndex]
        loopCount += 1
        if nextIndex == i:
            break

    total = loopSum

    currentSum = 0
    count = 0
    ci = i
    while True:
        count += 1
        if count > k:
            break
        loop = (k - count) // loopCount
        multi = max(0, total) * loop

        ci = ps[ci] - 1

        currentV = cs[ci]
        currentSum += currentV

        answer = max(answer, multi + currentSum)
        if ci == i:
            break

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

maxV = (10**6)**2

i = 0
sevens = 0
while True:
    sevens = sevens * 10 + 7
    sevens = sevens % k
    i+=1
    if sevens % k == 0:
        print(i)
        exit()

print(-1)

Fixed submission:
k = int(input())

maxV = (10**6)**2

i = 0
sevens = 0
while i < 10**6+1:
    sevens = sevens * 10 + 7
    sevens = sevens % k
    i+=1
    if sevens % k == 0:
        print(i)
        exit()

print(-1)