Harryxun/stf_run huggingface dataset:
# import pandas as pd
#import numpy as np


N = int(input())
keihin = []
for i in range(N):
    keihin.append(input())
# 
# nn = np.array(keihin)
# 
# 
# print(np.unique(nn).size)








### FIXED CODE ###

a = input().split()
S = int(a[0])
W = int(a[1])
if S <= W:
    print("unsafe")
else:
    print("safe")
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
TA=10**5+1
num=0
for i in range(n):
    if TA>abs(a-(t-h[i]*0.006)):
        num=i+1
        TA=abs(a-(t-h[i]*0.006))

print(num)

### FIXED CODE ###

x,y=map(int,input().split())
print(int(x+y/2))
while True:
    a,b=map(int,input().split())
    c=a+b
    ans=0
    if c>=0 and c<=9:
        ans=1
    if c>=10 and c<=99:
        ans=2
    if c>=100 and c<=999:
        ans=3
    if c>=1000 and c<=9999:
        ans=4
    if c>=10000 and c<=99999:
        ans=5
    if c>=100000 and c<=999999:
        ans =6
    if c>=1000000 and c<=9999999:
        ans=7
    print(ans)


### FIXED CODE ###

while True:
    try:a,b=map(int,input().split())
    except:break
    c=a+b
    ans=0

    while c>9:
        c=c//10
        ans+=1
    ans+=1
    print(ans)
s=input()
for i in range(len(s)-1):
    if s[i]=="A" anf s[i+1]=="C":
        print('Yes')
        exit()
print('No')

### FIXED CODE ###

s=input()
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        print('Yes')
        exit()
print('No')
import sys
#sys.setrecursionlimit(1000000)
input = sys.stdin.readline


def dfs(v, par):
    for nv in tree[v]:
        if nv != par:
            adds[nv] += adds[v]
            dfs(nv, v)


n,q = map(int, input().split())
tree = [[]for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

adds = [0] * n
for i in range(q):
    p,x = map(int, input().split())
    p -= 1
    adds[p] += x
dfs(0, -1)
print(*adds)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline


def dfs(v, par):
    for nv in tree[v]:
        if nv != par:
            adds[nv] += adds[v]
            dfs(nv, v)


n,q = map(int, input().split())
tree = [[]for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

adds = [0] * n
for i in range(q):
    p,x = map(int, input().split())
    p -= 1
    adds[p] += x
dfs(0, -1)
print(*adds)
import math

def is_prime(x):
  if x <= 1:
    return False
  max_judge = math.sqrt(x)
  count = 2
  while(count < max_judge):
    if x % count == 0:
      return False
    count+=1
  return True
 
x = int(input())
 
judge_prime = False

while(True):
  if is_prime(x):
    break
  x+=1

print(x)

### FIXED CODE ###

s, t = input().split()
print(t + s)
n,k=map(int,input().split())
a=list(int(x) for x in input().split())
a.sort(reverse = True)
s=0
if k <= n:
	print(0)
else:
		s = sum(a[:n-k])
		print(s)

### FIXED CODE ###

h,a=map(int,input().split())
if h % a ==0:
	print(h // a)
else:
	print((h // a ) + 1)
X = int(input())
l = []
for i in range(2, int(X ** 0.5) + 1):
  j = 2
  while i ** j <= X:
    j += 1
  l.append(i ** j)
l.sort()
print(l[-1])


### FIXED CODE ###

X = int(input())
l = []
if X < 4:
  print(1)
else:
  for i in range(2, int(X ** 0.5) + 1):
    j = 2
    while i ** j <= X:
      l.append(i ** j)
      j += 1
  l.sort()
  print(l[-1])
l = ['A', 'C', 'T', 'G']
s = input()
max = 0
max_temp = 0
for i in len(s):
    if str(s[i]) in l:
        max_temp += 1
        if max < max_temp:
            max = max_temp
    else:
        max_temp = 0
print(max)

### FIXED CODE ###

l = ['A', 'C', 'T', 'G']
s = input()
max = 0
max_temp = 0
for i in s:
    if i in l:
        max_temp += 1
        if max < max_temp:
            max = max_temp
    else:
        max_temp = 0
print(max)
a,b,c = map(int,input().split())

printint(((a*b*c)/2))


### FIXED CODE ###


a,b,c = map(int,input().split())

print(int(((a*b)/2)))
a,b,c = stdin.readline().rstrip().split()
if a+b+c >= 22:
  print('bust')
else:
  print('win')

### FIXED CODE ###

from sys import stdin
a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
if a+b+c >= 22:
  print('bust')
else:
  print('win')
from collections import deque

N, M = map(int, input().split())

A = [[] for _ in range(M)]
for i in range(M):
    Am, Bm = map(int, input().split())
    Am -= 1
    Bm -= 1
    A[Am].append(Bm)
    A[Bm].append(Am)


is_visited = [False for _ in range(N)]
ans = [0 for _ in range(N)]
def bfs():
    queue = deque()
    queue.append(0)
    is_visited[0] = True
    while queue:
        pos = queue.popleft()
        for next_pos in A[pos]:
            if is_visited[next_pos] == False:
                is_visited[next_pos] = True
                queue.append(next_pos)
                ans[next_pos] = pos

bfs()
#print(is_visited)                                                                                     

if False in is_visited:
    print("No")
else:
    for i in range(N-1):
        print(ans[i+1]+1)


### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())

A = [[] for _ in range(N)]
for i in range(M):
    Am, Bm = map(int, input().split())
    Am -= 1
    Bm -= 1
    A[Am].append(Bm)
    A[Bm].append(Am)


is_visited = [False for _ in range(N)]
ans = [0 for _ in range(N)]
def bfs():
    queue = deque()
    queue.append(0)
    is_visited[0] = True
    while queue:
        pos = queue.popleft()
        for next_pos in A[pos]:
            if is_visited[next_pos] == False:
                is_visited[next_pos] = True
                queue.append(next_pos)
                ans[next_pos] = pos

bfs()

if False in is_visited:
    print("No")
else:
    print("Yes")
    for i in range(N-1):
        print(ans[i+1]+1)
N = int(input())
an = list(map(int, input()))

cost = 10000*3
ans = 10000*3
for i in range(-100,100+1):
    cost = sum([(j - i)**2 for j in an])
    ans = min(ans, cost)

print(ans)

### FIXED CODE ###

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

cost = 10000*N
ans = 10000*N
for i in range(-100,100+1):
    cost = sum([(j - i)**2 for j in an])
    ans = min(ans, cost)

print(ans)
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

i_a = 0
i_b = 0

total_time = 0

while True:
    if i_a == N and i_b == M:
        break
    else:
        if i_a < N and A[i_a] <= B[i_b]:
            read_a = True
        else:
            read_a = False
    
    if read_a:
        if A[i_a] <= K - total_time:
            total_time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if B[i_b] <= K - total_time:
            total_time += B[i_b]
            i_b += 1
        else:
            break

print(int(i_a+i_b))

### FIXED CODE ###

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

a = [0]*(N+1)
b = [0]*(M+1)

for i in range(N):
    a[i+1] = a[i] + A[i]
for j in range(M):
    b[j+1] = b[j] + B[j]

n_b = M
best = 0

for n_a in range(N+1):
    if K < a[n_a]:
        break

    while  K < a[n_a] + b[n_b]:
        n_b -= 1

    best = max(n_a + n_b,best)

print(int(best))
import sys

status = input()
out = {"Sunny", "Cloudy", "Rainy"}

if status==out[0]:
	print(out[1])
elif status==out[1]:
	print(out[2])
elif status==out[2]:
	print(out[0])

### FIXED CODE ###

import sys

status = input()
out = ["Sunny", "Cloudy", "Rainy"]

if status==out[0]:
	print(out[1])
elif status==out[1]:
	print(out[2])
elif status==out[2]:
	print(out[0])
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,Q = imn()
S = input()
lr = [iln() for _ in range(Q)]

s = [0 for _ in range(N+1)]

for i in range(N):
    s[i+1] = s[i]
    if S[i] == 'A' and S[i+1] == 'C':
        s[i+1] += 1

for i in range(Q):
    l = lr[i][0]
    r = lr[i][1]
    print(s[r-1]-s[l-1])


### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
LR = [list(map(lambda x : int(x)-1, input().split())) for _ in range(Q)]

L = [0 for _ in range(N)]
R = [0 for _ in range(N)]

for i in range(1,N):
    if S[i-1:i+1] == 'AC':
        if i == 0:
            L[i] = 1
        else:
            L[i] = L[i-1] + 1
    else:
        if i > 0:
            L[i] = L[i-1]

for i in range(Q):
    Li = LR[i][0]
    Ri = LR[i][1]

    print(L[Ri] - L[Li])
X, Y, A, B, C = [int(s) for s in input().split()]
p_list = [int(s) for s in input().split()]
q_list = [int(s) for s in input().split()]
r_list = [int(s) for s in input().split()]

p_list = list(reversed(sorted(p_list)))
p_list = p_list[:X]
# print(X, p_list)

q_list = list(reversed(sorted(q_list)))
q_list = q_list[:Y]
# print(Y, q_list)

r_list = list(reversed(sorted(r_list)))
# print(r_list)

p_i = -1
q_i = -1
r_i = 0

while True:
    if p_i + A >= 0 and p_list[p_i] < q_list[q_i]:
        if p_list[p_i] < r_list[r_i]:
            p_list[p_i] = r_list[r_i]
            p_i -= 1
            r_i += 1
            if r_i == C:
                break
        else:
            break
    elif q_i + B >= 0 and q_list[q_i] < p_list[p_i]:
        if q_list[q_i] < r_list[r_i]:
            q_list[q_i] = r_list[r_i]
            p_i -= 1
            r_i += 1
            if r_i == C:
                break
        else:
            break
    else:
        break

d = 0
d += sum(p_list)
d += sum(q_list)

print(d)

### FIXED CODE ###

X, Y, A, B, C = [int(s) for s in input().split()]
p_list = [int(s) for s in input().split()]
q_list = [int(s) for s in input().split()]
r_list = [int(s) for s in input().split()]

p_list = list(reversed(sorted(p_list)))
p_list = p_list[:X]
# print(X, p_list)

q_list = list(reversed(sorted(q_list)))
q_list = q_list[:Y]
# print(Y, q_list)

r_list = list(reversed(sorted(r_list)))
# print(r_list)


p_i = -1
q_i = -1
r_i = 0

while True:
    if r_i == C:
        break

    if p_i + X >= 0 and q_i + Y >= 0:
        if p_list[p_i] <= q_list[q_i]:
            if p_list[p_i] < r_list[r_i]:
                p_list[p_i] = r_list[r_i]
                p_i -= 1
                r_i += 1
            else:
                break
        elif q_list[q_i] <= p_list[p_i]:
            if q_list[q_i] < r_list[r_i]:
                q_list[q_i] = r_list[r_i]
                q_i -= 1
                r_i += 1
            else:
                break
    elif p_i + X >= 0:
        if p_list[p_i] < r_list[r_i]:
            p_list[p_i] = r_list[r_i]
            p_i -= 1
            r_i += 1
        else:
            break
    elif q_i + Y >= 0:
        if q_list[q_i] < r_list[r_i]:
            q_list[q_i] = r_list[r_i]
            q_i -= 1
            r_i += 1
        else:
            break
    else:
        break

d = 0
d += sum(p_list)
d += sum(q_list)

print(d)
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
        if x+y+z == S:
            count += 1
print(count)

### FIXED CODE ###

K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if (z <= K) & (z >= 0):
            count += 1
print(count)
s = input()
for i, j in enumerate(s):
	if i % 2 == 0 and j == 'L':
		print('No')
        return
    elif i % 2 == 1 and j == 'R':
		print('No')
        return
print('Yes')

### FIXED CODE ###

s = input()
for i, j in enumerate(s):
    if i % 2 == 0 and j == 'L':
        print('No')
        break
    elif i % 2 == 1 and j == 'R':
        print('No')
        break
else:
    print('Yes')
n = int(input())
A = []
cnt = 0
for i in xrange(n):
    m = input()
    if m not in A:
        A.append(m)
        cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
A = [input() for i in range(n)]
print(-len(A) + len(set(A)) + n)
n, q = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    g[a-1].append(b-1)
#print(g)

val = [0 for i in range(n)]
score = [0 for i in range(n)]
for i in range(q):
    p,x = map(int, input().split())
    val[p-1] +=x
#print(val)

def dfs(p, x):
    for c in g[p]:
        score[c]+=x
        dfs(c, x)
for i in range(n):
    dfs(i, val[i])
    score[i] +=val[i]
print(*score)

### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000)

n,q = map(int, input().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

v = [deque([]) for i in range(n)]
for e in a_b:
    v[e[0]-1]+=[e[1]-1]
    v[e[1]-1]+=[e[0]-1]
score = [0 for i in range(n)]
for e in p_x:
    score[e[0]-1]+=e[1]
def dfs(p, bp=-1):
    while v[p]:
        c =v[p].popleft()
        if c ==bp:
            continue
        #print(p, c, bp)
        score[c]+=score[p]
        dfs(c, bp=p)
visited = [0]                
dfs(0)
print(*score)
n = input()
num = int(n[0:-2])
yen = int(n[-2::])
if num * 5 >= yen:
    print(1)
else:
    print(0)


### FIXED CODE ###

n = input()
if len(n) >= 3:
    num = int(n[0:-2])
    yen = int(n[-2::])
    if num * 5 >= yen:
        print(1)
    else:
        print(0)
else:
    print(0)
def resolve():
    t = input()
    l = len(t)
    que = []

    def dfs(s, idx):
        if idx == l:
            que.append(s)
            return

        if t[idx] == "?":
            dfs(s + "P", idx + 1)
            dfs(s + "D", idx + 1)
        else:
            dfs(s + t[idx], idx + 1)

    dfs("", 0)
    ans = ""
    ma = 0
    for q in que:
        a = q.count("D") + q.count("PD")
        if ma < a:
            ma = a
            ans = q

    print(ans)

resolve()

### FIXED CODE ###

def resolve():
    t = input()
    s = ""
    for c in t:
        if c == "?":
            c = "D"

        s += c
    print(s)

resolve()
h, n = map(int, input().split())
magic = [
    list(map(int, input().split())) for i in range(n)
]
dp = np.full((n+1, h+1), np.inf, dtype=np.int)
dp[1:, 0] = 0
dp[1][1] = magic[0][0]
for i in range(1, n+1):
    for j in range(1, h + 1):
        if i == 1:
            dp[i][j] = magic[i-1][1] * np.ceil(j/magic[i-1][0])
        elif j >= magic[i-1][0]:
            dp[i][j] = min(
                dp[i-1][j], dp[i][j-magic[i-1][0]] + magic[i-1][1],
            )
        else:
            dp[i][j] = dp[i-1][j]
print(dp[n][h])


### FIXED CODE ###

h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))
import sys
n,m=map(int,input().split())
INF=10**15
d={}
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  d.setdefault(a,[]).append(b)
  d.setdefault(b,[]).append(a)
dist=[INF for i in range(n)]
dist[0]=0
queue=[]
for i in d[0]:
  queue.insert(0,i)
  dist[i]=1

while(len(queue)):
  x=queue.pop()
  if(x==n-1 and dis[x]==2):
    print("POSSIBLE")
    sys.exit()
  elif(x==n-1 and dis[x]!=INF):
    print("INPOSSIBLE")
    sys.exit()
  for i in d[x]:
    if(dist[i]==INF):
      queue.insert(0,i)
      dist[i]=dist[x]+1
if(dist[-1]==2):print("POSSIBLE")
else:print("IMPOSSIBLE")


### FIXED CODE ###

import sys
n,m=map(int,input().split())
INF=10**15
li1=set()
lin=set()
for i in range(m):
  a,b=map(int,input().split())
  if(a==1):li1.add(b)
  elif(b==1):li1.add(a)
  elif(a==n):lin.add(b)
  elif(b==n):lin.add(a)
for i in li1:
  if(i in lin):
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")
import numpy as np
import sys
n,k = map(int,input().split())
a_list = sorted(map(int,input().split()))
mod = 10**9+7
if False:
  print("test")
else:
    a_list.sort(key = abs,reverse = True)
    add = 1
    remove = 1
    if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
        negative_big = [num for num in a_list[:k] if np.sign(num)==-1]
        positive_big = [num for num in a_list[:k] if np.sign(num)!=1]
        negative_small = [num for num in a_list[k:] if np.sign(num)==-1]
        positive_small = [num for num in a_list[k:] if np.sign(num)!=-1]
        
        
        
        if True:
            positive_small_max = max(positive_small)
            negative_big_max = max(negative_big)
            negative_small_min = min(negative_small)
            positive_big_min = min(positive_big)
            if positive_small_max/negative_big_max < negative_small_min/positive_big_min:
                remove = negative_big_max
                add = positive_small_max
            else:
                remove = positive_big_min
                add = negative_small_min
ans = 1
for num in a_list[:k]:
    ans *= num
    ans %= mod
    
if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
    ans *= add
    ans %= mod
    ans *= pow(remove, mod-2, mod)
    ans %= mod

print(ans)


### FIXED CODE ###

import numpy as np
import sys
n,k = map(int,input().split())
a_list = sorted(map(int,input().split()))
mod = 10**9+7
if n-k < a_list.count(0):
    print(0)
    exit()
if (sum([1 for a in a_list if np.sign(a)!=-1])==0 and k%2==1) or (k==n and len([1 for a in a_list if np.sign(a)==-1])%2==1):
    a_list.sort(key = abs)
    ans = 1
    for num in a_list[:k]:
        ans *= num
        ans %= mod
    print(ans)
    exit()
else:
    a_list.sort(key = abs,reverse = True)
    add = 1
    remove = 1
    if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
        negative_big = [num for num in a_list[:k] if np.sign(num)==-1]
        positive_big = [num for num in a_list[:k] if np.sign(num)!=-1]
        negative_small = [num for num in a_list[k:] if np.sign(num)==-1]
        positive_small = [num for num in a_list[k:] if np.sign(num)!=-1]
        
        
        if len(negative_big)==0 or len(positive_small)==0:
            remove = min(positive_big)
            add = min(negative_small)
        elif len(positive_big)==0 or len(negative_small)==0:
            remove = max(negative_big)
            add = max(positive_small)
        else:
            positive_small_max = max(positive_small)
            negative_big_max = max(negative_big)
            negative_small_min = min(negative_small)
            positive_big_min = min(positive_big)
            if positive_small_max*positive_big_min > negative_small_min*negative_big_max:
                remove = negative_big_max
                add = positive_small_max
            else:
                remove = positive_big_min
                add = negative_small_min
ans = 1
for num in a_list[:k]:
    ans *= num
    ans %= mod
    
if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
    ans *= add
    ans %= mod
    ans *= pow(remove, mod-2, mod)
    ans %= mod

print(ans)
def main():
	import sys
	sys.setrecursionlimit=10**7
	mod=998244353
	n,s=map(int,input().split())
	a=list(map(int,input().split()))
	from functools import lru_cache
	@lru_cache(maxsize=None)
	def dfs(x,y):
		if x==0:
			if y==0:
				return 1
			else:
				return 0
		r=dfs(x-1,y)*2%mod
		if y>0:
			if y-a[x-1]>=0:
				r+=dfs(x-1,y-a[x-1])
		r%=mod
		return r
	print(dfs(n,s))
main()

### FIXED CODE ###

mod=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
	for j in range(s+1):
		dp[i+1][j]+=2*dp[i][j]
		dp[i+1][j]%=mod
		if j+a[i]<=s:
			dp[i+1][j+a[i]]+=dp[i][j]
			dp[i+1][j+a[i]]%=mod
print(dp[n][s])
from collections import defaultdict

N, M = map(int, input().split())

city = []

for i in range(M):
    P, Y = map(int, input().split())
    city.append([i, P, Y])
city.sort(key=lambda x: x[2])

count = defaultdict(lambda: 0)
for c in city:
    count[c[P]] += 1
    c.append(count[c[P]])
city.sort(key=lambda x: x[0])

for _, P, _, n in city:
    print(format(P, '06') + format(n, '06'))

### FIXED CODE ###

from collections import defaultdict

N, M = map(int, input().split())

city = []

for i in range(M):
    P, Y = map(int, input().split())
    city.append([i, P, Y])
city.sort(key=lambda x: x[2])

count = defaultdict(lambda: 0)
for c in city:
    count[c[1]] += 1
    c.append(count[c[1]])
city.sort(key=lambda x: x[0])

for _, P, _, n in city:
    print(format(P, '06') + format(n, '06'))
N = int(input())
S = 0
for in in range(1,N+1):
  if i%3==0 or i%5==0 or i%3==0 and i%5==0
	continue
  S +=i
print(S) 

### FIXED CODE ###

N = int(input())
out = 0
for i in range(1,N+1):
    if i%3 == 0 and i%5 == 0 or i%3==0 or i%5==0:
       continue
    out += i
print(out)
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Ps = [i - 1 for i in Ps]
Cs = list(map(int, input().split()))
max_score = -float("inf")


for i in range(N):
    scores = []
    idx = i  # starting index
    while True:
        idx = Ps[idx]  # point to the next index
        scores.append(Cs[idx])  # fetch a score to add
        if idx == i:  # when the cycle is closed
            break

    len_cycle = len(scores)
    sum_cycle = sum(scores)

    if sum_cycle <= 0:  # when each cycle reduces the total score
        score = 0
        for j in range(min(K, len_cycle)):
            score += scores[j]
            max_score = max(max_score, score)
    else:
        if K // len_cycle > 0:
            num_multiply = K // len_cycle - 1
            score = sum_cycle * num_multiply
            for j in range(K % len_cycle + len_cycle):
                score += scores[j]
                max_score = max(max_score, score)
        else:
            num_multiply = 0  # len_cycle > K
            score = sum_cycle * num_multiply
            for j in range(K):
                score += scores[j]
                max_score = max(max_score, score)

print(max_score)


### FIXED CODE ###

N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Ps = [i - 1 for i in Ps]
Cs = list(map(int, input().split()))
max_score = -float("inf")


for i in range(N):
    scores = []
    idx = i  # starting index
    while True:
        idx = Ps[idx]  # point to the next index
        scores.append(Cs[idx])  # fetch a score to add
        if idx == i:  # when the cycle is closed
            break

    len_cycle = len(scores)
    sum_cycle = sum(scores)

    if sum_cycle <= 0:  # when each cycle reduces the total score
        score = 0
        for j in range(min(K, len_cycle)):
            score += scores[j]
            max_score = max(max_score, score)
    else:
        if K // len_cycle > 0:
            num_multiply = K // len_cycle - 1
            score = sum_cycle * num_multiply
            scores = scores * 2
            for j in range(K % len_cycle + len_cycle):
                score += scores[j]
                max_score = max(max_score, score)
        else:
            num_multiply = 0  # len_cycle > K
            score = sum_cycle * num_multiply
            for j in range(K):
                score += scores[j]
                max_score = max(max_score, score)

print(max_score)