Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
s=[Counter(input()) for _ in range(n)]

c = counter[0]
#各アルファベット(a,b,c,...,z)に対して，使用回数の最小値を求める
c = s[0]
for i in range(1,n):
    for k,v in c.items():
        c[k] = min(s[i][k], c[k])
        
c = sorted(c.items())
ans = ''
for k,v in c:
    ans += k*v
print(ans)


Fixed submission:
from collections import Counter
n=int(input())
s=Counter(input())
for i in range(n-1):
    s&=Counter(input())
print(''.join(sorted(s.elements())))

Buggy python submission (verdict: Runtime Error):
n=int(input())

def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr
  
res = list(input()) 
for _ in range(n-1):
    s = list(input())
    res = intersect_list(res,s)
res.sort()
ans = ''.join(res)
print(ans)

Fixed submission:
from collections import Counter
n=int(input())
s=Counter(input())
for i in range(n-1):
    s&=Counter(input())
print(''.join(sorted(s.elements())))

Buggy python submission (verdict: Runtime Error):
n=int(input())

def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr


res = list(input())
for _ in range(n-1):
    s = list(input())
    res = intersect_list(res,s)
res.sort()
ans = ''.join(res)
print(*ans, sep='')

Fixed submission:
from collections import Counter
n=int(input())
s=Counter(input())
for i in range(n-1):
    s&=Counter(input())
print(''.join(sorted(s.elements())))
Buggy python submission (verdict: Time Limit Exceeded):
N, C, K = map(int, input().split())

T = [int(input()) for _ in range(N)]

T.sort()

num_track = 0
i = 0
while i < N:
	L = T[i]
	if i + C + 1 < N:
		kouho = T[i:i+C] # T[i],...,T[i+C-1]
	else:
		kouho = T[i:]
	# <= L + K
	num = 0
	for j in range(len(kouho)):
		if kouho[j] - L <= K:
			num += 1
	num_track += 1
	i += num

print(num_track)



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

T = [int(input()) for _ in range(N)]

T.sort()

res = 0
i = 0
while i < N:
	res += 1
	Left = i
	while (i < N and T[i] - T[Left] <= K and i - Left + 1 <= C):
		i += 1

print(res)
Buggy python submission (verdict: Runtime Error):
if x<=11:
    if x<=6:
        print(1)
    else:
        print(2)
else:
    if x%11==0:
        print(2*(x//11))
    elif x-11*(x//11)<=6:
        print(2*(x//11)+1)
    else:
        print(2*(x//11)+2)

Fixed submission:
x=int(input())
if x<=11:
    if x<=6:
        print(1)
    else:
        print(2)
else:
    if x%11==0:
        print(2*(x//11))
    elif x-11*(x//11)<=6:
        print(2*(x//11)+1)
    else:
        print(2*(x//11)+2)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
for i in range(n):
  s=input()
  for j in range(2):
    print(s)

Fixed submission:
h,w=map(int,input().split())
for _ in range(h):
	s=input()
	print(s)
	print(s)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x=map(int,input().split())
cnt=0
for i in range(a,b+1):
  if i%x==0: cnt+=1
print(cnt)

Fixed submission:
a,b,x=map(int,input().split())
cnt=0
#for i in range(a,b+1):
#  if i%x==0: cnt+=1
#print(cnt)

cnt1=b//x
cnt2=(a-1)//x
print(cnt1-cnt2)
Buggy python submission (verdict: Runtime Error):
w, h, n = map(int, input().split())
xl, xr = 0, w
yd, yu = 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x < xl:
            continue
        elif xl <= x <= xr:
            xl = x
        else:
            xl, xr = 0
    elif a == 2:
        if xr < x:
            continue
        elif xl <= x <= xr:
            xr = x
        else:
            xl, xr = 0, 0
    elif a == 3:
        if y < yd:
            continue
        elif yd <= y <= yu:
            yd = y
        else:
            yd, yu = 0, 0
    elif a == 4:
        if y > yu:
            continue
        elif yd <= y <= yu:
            yu = y
        else:
            yd, yu = 0, 0

print((xr - xl) * (yu - yd))

Fixed submission:
w,h,n=map(int,input().split())
x1,x2=0,w
y1,y2=0,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1 = max(x1,x)
    elif a==2:
        x2 = min(x2,x)
    elif a==3:
        y1 = max(y1,y)
    elif a==4:
        y2 = min(y2,y)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
i=0
while i<len(s)-1: #重複を削除
    if s[i]==s[i+1]:
        s.remove(s[i])
    else:
        i+=1
print(len(s)-1)

Fixed submission:
s=input()
cnt=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]: cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
print(n*x) if n<k else print(k*x+(n-k)*y)

Fixed submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(n*x) if n<k else print(k*x+(n-k)*y)
Buggy python submission (verdict: Runtime Error):
s = input()
from collections import Counter
c = Counter(s)

flag = True
for v in c.values():
    if v%2!=0: flag = False
    
print('Yes' if bl else 'No')

Fixed submission:
s = input()
from collections import Counter
c = Counter(s)

flag = True
for v in c.values():
    if v%2!=0: flag = False
    
print('Yes' if flag else 'No')
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
import collections

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int8).T

if M == 0:
    print(1)
else:

    tmp = np.ones(M, dtype=np.int8).T
    graph = csr_matrix((tmp, (edge[:] - 1)), (N, N))

    n, labels = connected_components(graph)

    c = collections.Counter(labels)

    print(max(c.values()))

Fixed submission:
d,t,s= map(int,input().split())

if (d/s) <= t:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):

n, k = map(int,input().split())
yokolist = list(map(int, input().split()))

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
l = expect_list[0:k]
for j in range(n-k+1):
    p = sum(l)
    if p > answer:
       answer = p
    del l[0]
    if j != n-k:
        l.append(expect_list[k+j])

print(answer)

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
l = expect_list[0:k]
p = sum(l)
for j in range(n-k+1):
    if p > answer:
       answer = p
    if j != n-k:
        p = p - expect_list[j] + expect_list[k+j]

print(answer)

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
for j in range(n-k+1):
    l = expect_list[j:j+k]
    p = sum(l)
    if p > answer:
       answer = p

print(answer)

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
l = expect_list[0:k]
p = sum(l)
for j in range(n-k+1):
    if p > answer:
       answer = p
    if j != n-k:
        p = p - expect_list[j] + expect_list[k+j]

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
def popcnt(n):
    return bin(n).count("1")

n = int(input())
grid = []

for i in range(n):
    p = int(input())
    for j in range(p):
        array = [i] +list(map(int, input().strip().split(' ')))
        array[1] = array[1] - 1
        grid.append(array)


truth = 0
count = 0

for i in range(2**n):
    k = (bin(i)[2:]).zfill(n)
    count = 0
    for j in range(len(grid)):
        if int(k[grid[j][0]]) == 1:
            if (int(k[grid[j][1]]) == 1 and grid[j][2] == 0) or (int(k[grid[j][1]]) == 0 and grid[j][2] == 1):
                count = 1
    if count == 0:
        if truth < popcnt(i):
            truth = popcnt(i)

print(truth)


Fixed submission:
def popcnt(n):
    return bin(n).count("1")

n = int(input())
grid = []

for i in range(n):
    p = int(input())
    for j in range(p):
        array = [i] +list(map(int, input().strip().split(' ')))
        array[1] = array[1] - 1
        grid.append(array)


truth = 0
count = 0

for i in range(2**n):
    k = (bin(i)[2:]).zfill(n)
    count = 0
    for j in range(len(grid)):
        if int(k[grid[j][0]]) == 1:
            if (int(k[grid[j][1]]) == 1 and grid[j][2] == 0) or (int(k[grid[j][1]]) == 0 and grid[j][2] == 1):
                count = 1
                break
    if count == 0:
        if truth < popcnt(i):
            truth = popcnt(i)

print(truth)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int,input().split())
winner = [int(input()) -1 for i in range(q)]
winnerpoint = [winner.count(i) for i in range(n)]

point = [k - (q - winnerpoint[i]) for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")


Fixed submission:
from collections import Counter

n, k, q = map(int,input().split())
winner = [int(input()) -1 for i in range(q)]
mycount = Counter(winner)
point = [k - (q - mycount[i])for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int,input().split())
grid = []
for i in range(q):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

winner = [grid[i][0]-1 for i in range(q)]

point = [k - (q - winner.count(i)) for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")


Fixed submission:
from collections import Counter

n, k, q = map(int,input().split())
winner = [int(input()) -1 for i in range(q)]
mycount = Counter(winner)
point = [k - (q - mycount[i])for i in range(n)]

for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
height = list(map(int, input().split()))

result = 0

for i in range(n):
    kari = 0
    for j in range(i, n-1):
        if height[j] >= height[j+1]:
            kari += 1
        else:
            break

    if kari > result:
        result = kari

print(result)

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

top = [0] + [i+1 for i in range(n-1) if height[i] < height[i+1] ]

result = [top[i+1]-top[i]-1 for i in range(len(top)-1)] + [(n-1)-top[len(top)-1]]

print(max(result))
Buggy python submission (verdict: Runtime Error):
n = int(input(n))
print(n*(n-1)/2)

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)


answer = Fib(outlist[0] - 1)

for i in range(m - 1):
    answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
    answer = answer % 1000000007

answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

for i in range(m - 1):
    if outlist[i + 1] - outlist[i] == 1:
        answer = 0

print(answer)

Fixed submission:
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)

if m != 0:
    answer = Fib(outlist[0] - 1)

    for i in range(m - 1):
        answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
        answer = answer % 1000000007

    answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

    for i in range(m - 1):
        if outlist[i + 1] - outlist[i] == 1:
            answer = 0
else:
    answer = Fib(n)

print(answer)

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
outlist = [int(input()) for i in range(m)]

def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return(a)

def stepcount(x,y):
    if y-x <= 1:
        return 1
    else:
        return Fib(y-x)

answer = Fib(outlist[0]-1)

for i in range(m-1):
    answer *= stepcount(outlist[i]+1,outlist[i+1]-1)
    answer = answer % 1000000007

answer = (answer * stepcount(outlist[m-1]+1, n)) % 1000000007

for i in range(m-1):
    if outlist[i+1] - outlist[i] == 1:
        answer = 0

print(answer)

Fixed submission:
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)

if m != 0:
    answer = Fib(outlist[0] - 1)

    for i in range(m - 1):
        answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
        answer = answer % 1000000007

    answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

    for i in range(m - 1):
        if outlist[i + 1] - outlist[i] == 1:
            answer = 0
else:
    answer = Fib(n)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())

k = len(s)
i = 0
j = 0

for t in range(1000000000000):
    if i+1 >= k-j or len(s)==1:
        break
    elif s[i] + s[i+1] =='01' or s[i] + s[i+1] =='10':
        del s[i]
        del s[i]
        i = 0
        j = j + 2
    else:
        i = i+1


print(j)

Fixed submission:
s = list(input())


if s.count('0') >= s.count('1'):
    print(s.count('1')*2)
else:
    print(s.count('0')*2)
Buggy python submission (verdict: Runtime Error):
import functools
import math

n, x = map(int, input().split())
l = map(int, input().split())

l2 = map(lambda t: t-x, l)

gcd = functools.reduce(math.gcd, l2)
print(gcd)



Fixed submission:
def gratest_common_factor(x,y):
    while y:
        amari = x % y

        x = y
        y = amari
    return x


n, x = map(int, input().split())
l = map(int, input().split())

l2 = list(map(lambda t: t-x, l))

for i in range(n-1):
    l2[1] = gratest_common_factor(l2[0],l2[1])
    del l2[0]

print(abs(l2[0]))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

list = []
p = 0

for a in range(1,n+1):
    x = int(a/k)
    y = int((n+a)/k)
    for i in range(x+1,y+1):
            if  (i*k-a+i*k-a) % k ==0:
                p = p + (y-x)
            else:
                pass

print(p)

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

list = []
p = 0

for a in range(1,n+1):
    x = int(a/k)
    y = int((n+a)/k)
    if  2*a % k ==0:
        p = p + (y-x)**2
    else:
        pass

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

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)


Fixed submission:
N, X, M = map(int, input().split())

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
        ans += sum(out[d[a]:d[a] + (remain % loop_num)])
        break
print(ans)

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

if X == 0:
    print(0)
    exit()
    
if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)


Fixed submission:
N, X, M = map(int, input().split())

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
        ans += sum(out[d[a]:d[a] + (remain % loop_num)])
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)


Fixed submission:
N, X, M = map(int, input().split())

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
        ans += sum(out[d[a]:d[a] + (remain % loop_num)])
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())

if S < 3:
    print(0)
    exit()

x = [0] * (S + 1)
x[3] = x[4] = x[5] = 1
for i in range(6, S + 1):
    x[i] += 1
    for j in range(3, i - 3 + 1):
        x[i] += x[i - j]

print(x[S] % (10 ** 9 + 7))


Fixed submission:
S = int(input())

if S < 3:
    print(0)
    exit()

if S < 6:
    print(1)
    exit()

x = [0] * (S + 1)
x[3] = x[4] = x[5] = 1
for i in range(6, S + 1):
    x[i] += 1
    for j in range(3, i - 3 + 1):
        x[i] += x[i - j]

print(x[S] % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
C = [set([]) for i in range(N)]


def dfs(n, y):
    seen[n] = True
    y += 1
    for c in C[n]:
        if seen[c]:
            continue
        else:
            y = dfs(c, y)
    return y


for i in range(M):
    a, b = map(int, input().split())
    C[a - 1].add(b - 1)
    C[b - 1].add(a - 1)

ans = 0
seen = [False] * N
for i in range(N):
    if seen[i]:
        continue
    x = 0
    x = dfs(i, x)
    ans = max(ans, x)

print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(1000000)


N, M = map(int, input().split())
C = [set([]) for i in range(N)]


def dfs(n, y):
    seen[n] = True
    y += 1
    for c in C[n]:
        if seen[c]:
            continue
        else:
            y = dfs(c, y)
    return y


for i in range(M):
    a, b = map(int, input().split())
    C[a - 1].add(b - 1)
    C[b - 1].add(a - 1)

ans = 0
seen = [False] * N
for i in range(N):
    if seen[i]:
        continue
    x = 0
    x = dfs(i, x)
    ans = max(ans, x)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input())
A = list(map(int, input().split()))
C = [0] * (10 ** 6 + 1)

for i in range(N):
    C[A[i]] += 1

is_pairwise = True
max_a = max(A) + 1
X = [0] * max_a
for i in range(2, max_a):
    count = 0
    for j in range(i, max_a, i):
        count += C[j]
    if count > 1:
        is_pairwise = False

if is_pairwise:
    print('pairwise coprime')
    exit()

tmp = A[0]
for i in range(1, N):
    tmp = math.gcd(tmp, A[i])

if tmp == 1:
    print('setwise coprime')
else:
    print('not coprime')


Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))
C = [0] * (10 ** 6 + 1)

for i in range(N):
    C[A[i]] += 1

is_pairwise = True
max_a = max(A) + 1
X = [0] * max_a
for i in range(2, max_a):
    count = 0
    for j in range(i, max_a, i):
        count += C[j]
    if count > 1:
        is_pairwise = False

if is_pairwise:
    print('pairwise coprime')
    exit()

tmp = A[0]
for i in range(1, N):
    tmp = math.gcd(tmp, A[i])

if tmp == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

B = [1] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i - 1] * A[i]

is_pairwise = True
for i in range(N-1):
    if math.gcd(A[i], B[-1]//B[i]) != 1:
        is_pairwise = False
        break

if is_pairwise:
    print('pairwise coprime')
    exit()

tmp = math.gcd(A[0], A[1])
for i in range(2, N):
    tmp = math.gcd(tmp, A[i])

if tmp == 1:
    print('setwise coprime')
else:
    print('not coprime')


Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))
C = [0] * (10 ** 6 + 1)

for i in range(N):
    C[A[i]] += 1

is_pairwise = True
max_a = max(A) + 1
X = [0] * max_a
for i in range(2, max_a):
    count = 0
    for j in range(i, max_a, i):
        count += C[j]
    if count > 1:
        is_pairwise = False

if is_pairwise:
    print('pairwise coprime')
    exit()

tmp = A[0]
for i in range(1, N):
    tmp = math.gcd(tmp, A[i])

if tmp == 1:
    print('setwise coprime')
else:
    print('not coprime')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

ans = -10 ** 9
for i in range(1, N + 1):
    start = i
    next_ = start
    loop_score = 0
    loop_count = 0
    while True:
        loop_count += 1
        loop_score += C[next_]
        next_ = P[next_]
        if next_ == start:
            break
    in_score = 0
    in_count = 0

    for k in range(K):
        in_count += 1
        in_score += C[next_]

        loop_num = (K - in_count) // loop_count
        score = in_score + max(0, loop_score) * loop_num
        ans = max(ans, score)

        next_ = P[next_]
        if next_ == start:
            break

print(ans)


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

ans = -10 ** 9
for i in range(1, N + 1):
    start = i
    next_ = start
    loop_score = 0
    loop_count = 0
    while True:
        loop_count += 1
        loop_score += C[next_]
        next_ = P[next_]
        if next_ == start:
            break
    in_score = 0
    in_count = 0

    for k in range(K):
        in_count += 1
        in_score += C[next_]

        loop_num = (K - in_count) // loop_count
        score = in_score + max(0, loop_score) * loop_num
        ans = max(ans, score)

        next_ = P[next_]
        if next_ == start:
            break

print(ans)