Harryxun/stf_run huggingface dataset:
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  ans=0
  for i in range(n):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
  if ans==0:
    for j in range(2*x,101):
      if j not in a:
        ans=j
        break
print(ans)


### FIXED CODE ###

x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  ans=x
else:
  ans=0
  for i in range(101):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
print(ans)
k, n = input().split()
a = input().split()
max = 0
for i in range(len(a)):
    if i==0:
        continue
    d = a[i]-a[i-1]
    if d>max:
        max=d
print(k-max)

### FIXED CODE ###

k, n = input().split()
a = input().split()
max = 0
for i in range(0,len(a)):
    if i==0:
        max = int(k)-int(a[len(a)-1])+int(a[0])
    d = int(a[i])-int(a[i-1])
    if d>max:
        max=d
print(int(k)-max)
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))

c1 = Counter(a[::2])
c2 = Counter(a[1::2])
c1f1 = max(c1, key = lambda k:c1[k])
c2f1 = max(c2, key = lambda k:c2[k])

if c1f1 != c2f1:
  return n - c1[c1f1] - c2[c2f1]
else:
  if c1[c1f1] > c2[c2f1]:
    del c2[c2f1]
    if not c2: return n-c1[c1f1]
    c2f1 = max(c2, key = lambda k:c2[k])
    return n-c1[c1f1] - c2[c2f1]
  else:
    del c1[c1f1]
    if not c1: return n-c2[c2f1]
    c1f1 = max(c1, key = lambda k:c1[k])
    return n-c1[c1f1] - c2[c2f1]

### FIXED CODE ###

s = input()
for c in s:
  if c == '1': print('9', end='')
  elif c == '9': print('1', end='')

print()
import math
import itertools as it


i = input().split()



n = i[0]
m = i[1]
nc = it.combinations(range(n),2)
mc = it.combinations(range(m),2)

print(len(list(nc) + list(mc)))

### FIXED CODE ###

import math
import itertools as it


i = input().split()



n = int(i[0])
m = int(i[1])
nc = it.combinations(range(n),2)
mc = it.combinations(range(m),2)

print(len(list(nc) + list(mc)))
n,l=map(int,input().split())
print(((l+n-1)*(l+n)-l*(l+1))//2-l if l>=0 else (((l+n-1)*(l+n)-l*(l+1))//2 if l<0 and l+n>0 ((l+n-1)*(l+n)-l*(l+1))//2-(l+n-1)))

### FIXED CODE ###

n,l=map(int,input().split())
m=[l+i for i in range(n)]
s=sum(m)
t=101
d=0
for i in range(n):
  if t>abs(m[i]):
    t=abs(m[i])
    d=m[i]
print(s-d)
n = int(input())
h = list(map(int, input().split()))
cost = [-1 for i in range(n)]

def ans(k):
  if cost[k] != -1:
    return cost[k]
  cost[k] = min(ans(k-1) + abs(h[k-1] - h[k]), ans(k-2) + abs(h[k-2] - h[k]))
  return cost[k]

cost[0] = 0
cost[1] = abs(h[0] - h[1])
print(ans(n-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
h = list(map(int, input().split()))
cost = [-1] * n

def ans(n):
  if cost[n] != -1:
    return cost[n]
  cost[n] = min(ans(n-1) + abs(h[n-1] - h[n]), ans(n-2) + abs(h[n-2] - h[n]))
  return cost[n]

cost[0] = 0
cost[1] = abs(h[0] - h[1])
print(ans(n-1))
j = input()
 
for i in range(j):
   x = input()
   if x == 0:
      return
   print Case i: x

### FIXED CODE ###

i = 0
     
while 1:
   i += 1
   x = input()
   if x == 0:
      break
   else:
      print "Case %d: %d" %(i, x)
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

table = [[0 for i in range(max(M)+1)] for j in range(n)]

def solve(i, m): 
    if m == 0:
        return True
    elif i >= n:
        return False
    elif table[i][m] != 0:
        return table[i][m]
    else:
        res = solve(i + 1, m) or solve(i + 1, m - A[i])
        table[i][m] = res
        return res

for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

table = [[-1 for i in range(max(M)+1)] for j in range(n)]

def solve(i, m):
    if m == 0:
        return True
    elif i >= n:
        return False
    elif table[i][m] != -1:
        return table[i][m]
    elif m - A[i] >= 0:
        res = solve(i + 1, m) or solve(i + 1, m - A[i])
        table[i][m] = res
        return res
    else:
        res = solve(i + 1, m)
        table[i][m] = res
        return res

for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')
N=int(input())
v=[int(x) for x in input().split()]
cnt=0
while cnt<N-1:
    v.sort()
    v[0]=(v[0]+v.pop(1))/2
    cnt+=1
print(v[0])

### FIXED CODE ###

h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
    l=""
    for j in range(w):
        if s[i][j]=="#":
            l+="#"
        else:
            l+=str(sum([t[max(0,j-1):min(w,j+2)].count("#") for t in s[max(0,i-1):min(h,i+2)]]))
    print(l)
n,x = map(int, input().split())

donutspowderconsumption = [int(input()) for i in range(n)]
totalpowderconsumption = sum(donutspowderconsumption)
sort(donutspowderconsumption)

prin( n + (x-totalpowderconsumption) // donutspowderconsumption[0])

### FIXED CODE ###

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

donutspowderconsumption = [int(input()) for i in range(n)]
totalpowderconsumption = sum(donutspowderconsumption)
donutspowderconsumption.sort()

print( n + (x-totalpowderconsumption) // donutspowderconsumption[0])
import sys
n = int(input())
ts=0
xs=0
ys=0
ans = "Yes"
for i in range(n):
    t,x,y = map(int,input().split())
    
    if (t-ts) % (abs(x-xs)+abs(y-ys)) == 0 and t-ts >= (abs(x-xs)+abs(y-ys)):
        xs = x
        ys = y
        ts = t
    else:
        ans = "No"
print(ans)

### FIXED CODE ###

import sys
n = int(input())

for i in range(n):
    t,x,y = map(int,input().split())
    
    if (x+y) > t or (x+y+t) % 2 == 1:
        print("No")
        sys.exit()
        
print("Yes")
S,T = map(input().split())
A,B = map(int,input().split())
U = input()

if U == S:
  print(A-1, B)
else:
  print(A, B-1)

### FIXED CODE ###

S,T = input().split()
A,B = map(int,input().split())
U = input()

if U == S:
  print(A-1, B)
else:
  print(A, B-1)
a,b,c=input().split()
print(a,b,c)

### FIXED CODE ###

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

x = c − a
y = d - b
print(c-y,d+x,a-y,b+x)

### FIXED CODE ###

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

x = c - a
y = d - b
print(c-y,d+x,a-y,b+x)
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	 ll n;cin>>n;
	 string s; cin>>s;
	 ll idx = find(all(s),'.') - s.begin();
	 ll a = stoi(s.substr(0,idx));
	 ll b = stoi(s.substr(idx+1));
	 ll mn = a*100+b;
	 cout<<(mn*n)/100<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}



### FIXED CODE ###

a,b = input().split()
a = int(a);
b = list(b.split("."))
b = int(b[0])*100+int(b[1])
print(a*b//100)
n = input()
k = int(input())
dp = [[[0 for i in range(len(n)+1)] for i in range(2)] for i in range(len(n)+1)]
dp[0][0][0] = 1
for a in range(len(n)):
  for b in range(2):
    for c in range(len(n)):
      for i in range(10):
        if b ==1:
          if i != 0:
            dp[a+1][1][c+1] += dp[a][1][c]
          else:
            dp[a+1][1][c] += dp[a][1][c]
        else:
          if int(n[a]) > i and i ==0:
            dp[a+1][1][c] += dp[a][0][c]
          if int(n[a]) > i and i != 0:
            dp[a+1][1][c+1] += dp[a][0][c]
          if int(n[a]) == i and i ==0:
            dp[a+1][0][c] += dp[a][0][c]
          if int(n[a]) == i and i !=0:
            dp[a+1][0][c+1] += dp[a][0][c]
if len(n) == 1:
    if k == 1:
 		print(int(n))  
    if k >= 2:
      print(0)
else:
  print(dp[-1][0][k] + dp[-1][1][k])


### FIXED CODE ###

n = input()
k = int(input())
dp = [[[0 for i in range(len(n)+1)] for i in range(2)] for i in range(len(n)+1)]
dp[0][0][0] = 1
for a in range(len(n)):
  for b in range(2):
    for c in range(len(n)):
      for i in range(10):
        if b ==1:
          if i != 0:
            dp[a+1][1][c+1] += dp[a][1][c]
          else:
            dp[a+1][1][c] += dp[a][1][c]
        else:
          if int(n[a]) > i and i ==0:
            dp[a+1][1][c] += dp[a][0][c]
          if int(n[a]) > i and i != 0:
            dp[a+1][1][c+1] += dp[a][0][c]
          if int(n[a]) == i and i ==0:
            dp[a+1][0][c] += dp[a][0][c]
          if int(n[a]) == i and i !=0:
            dp[a+1][0][c+1] += dp[a][0][c]
if len(n) == 1:
  if k == 1:
    print(int(n))  
  if k >= 2:
      print(0)
else:
  print(dp[-1][0][k] + dp[-1][1][k])
import string
import numpy as np
N = int(input())
S = list(input())
A2Z = string.ascii_uppercase

str_index = np.full(len(S), 0)
mod26 = np.full(len(S), 26)
#print(str_index)

for i in range(len(S)):
    str_index[i] = A2Z.index(S[i])
str_index = (str_index+N) % mod26
#print(str_index)

tmp = ['']*len(S)
for i in range(len(S)):
    tmp[i] = A2Z[str_index[i]]
answer = ''.join(tmp)
print(answer)

### FIXED CODE ###

import string
import numpy as np
N = int(input())
S = list(input())
A2Z = string.ascii_uppercase

str_index = np.full(len(S), 0)
mod_26 = np.full(len(S), 26)
#print(str_index)

for i in range(len(S)):
    str_index[i] = A2Z.index(S[i])
str_index = (str_index+N) % mod_26
#print(str_index)

tmp = ['']*len(S)
for i in range(len(S)):
    index = int(str_index[i])
    tmp[i] = A2Z[index]
answer = ''.join(tmp)
print(answer)
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(a):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

### FIXED CODE ###

import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(len(a)):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line)
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]

    return (s,)


def solve(s):

    w = {'Sunny':'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}



    return w[s]


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]

    return (s,)


def solve(s):

    w = {'Sunny':'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}



    return w[s]


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
import sys
(W, H, x, y, r) = [int(i) for i in sys.stdin.readline().split()]
if r <= x <= W - r and r <= y <= H - r:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
 
if a > b:
    tmp = a
    a = b
    b = tmp
if b > c:
    tmp = b
    b = c
    c = tmp
if a > b:
    tmp = a
    a = b
    b = tmp
 
print(a, b, c)
n, c = map(int, input().split())
# input時に前処理として以下のことをしておく
#   * 開始時間を-1(-0.5の制約だが、-1しても変わらないので-1する)しておく

# テレビ局の番組をチャンネルごとに登録
r = [[0 for i in range(c)] for j in range(100)]
for _ in range(n):
    s,t,c = map(int, input().split())
    for j in range(s-1, t):
        r[j][c - 1] = 1
# print(*r,sep='\n')

ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)


# 補足
# チャンネル数4の場合以下のような配列ができる
# 1行でとある時間のチャンネル状態(1: 録画する, 0: 録画しない)がつく
#[0, 0, 0, 0]
#[0, 0, 1, 0]
#[1, 1, 1, 0]  <- この時間で3チャンネル録画が必要
#[1, 1, 0, 0]  <- この時間で2チャンネル録画が必要
#[1, 1, 0, 0]
#[1, 0, 0, 0]

### FIXED CODE ###

n, c = map(int, input().split())
# input時に前処理として以下のことをしておく
#   * 開始時間を-1(-0.5の制約だが、-1しても変わらないので-1する)しておく

# テレビ局の番組をチャンネルごとに登録
r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
    s,t,c = map(int, input().split())
    for j in range(s-1, t):
        r[j][c - 1] = 1
# print(*r,sep='\n')

ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)


# 補足
# チャンネル数4の場合以下のような配列ができる
# 1行でとある時間のチャンネル状態(1: 録画する, 0: 録画しない)がつく
#[0, 0, 0, 0]
#[0, 0, 1, 0]
#[1, 1, 1, 0]  <- この時間で3チャンネル録画が必要
#[1, 1, 0, 0]  <- この時間で2チャンネル録画が必要
#[1, 1, 0, 0]
#[1, 0, 0, 0]
import fractions
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//fractions.gcd(lcm,a[i])

b = [0]*N

ans = 0
for i in range(N):
	ans += lcm/a[i]
	
print(int(ans%(10**9+7)))




### FIXED CODE ###

import fractions
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//fractions.gcd(lcm,a[i])

b = [0]*N

ans = 0
for i in range(N):
	ans += lcm//a[i]
print(int(ans%(10**9+7)))
N=int(input("enter number of people")
A=int(input("enter the cost of train")
B=int(input("enter the cost of taxi")
t1=N*A
t2=N*B
if t1<t2:
      tmin=t1
      print("minimum total travel expense",tmin)
else:
      tmin=t2
      print("minimum total travel expense",tmin)
      

### FIXED CODE ###

n,a,b=map(int,input().split())
if(n*a>=b):
    print(b)
else:
    print(n*a)
n,k = map(int,input().split())
p = list(map(int,input().split()))
ave = []

for i in range(n):
  ave.append((p[i]+1)/2)

for i in range(n-k+1):
  ans = max(ans,sum(ave[i:i+k]))

print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
ave = []
ans = 0
tmp = 0

for i in range(n):
  ave.append((p[i]+1)/2)

for j in range(n):
  tmp += ave[j]
  if j >= k:
    tmp -= ave[j-k]
    
  ans = max(ans,tmp)


print(ans)
H, W=map(int,input().split(' '))
c=[list(map(int,input().split(' '))) for i in range(10)]
a=[list(map(int,input().split(' '))) for i in range(H)]
ans=0

for i in range(10):
    for j in range(10):
        for k in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])

for i in range(H):
    for j in range(W):
        if a[i][j]>=0:
            ans += c[a[i][j]][1]

print(ans)


### FIXED CODE ###

# coding: utf-8
# 整数の入力
a, b, c, d = [int(i) for i in input()]
# 計算
if a+b+c+d == 7:
    s = "{}+{}+{}+{}=7"
elif a+b+c-d == 7:
    s = "{}+{}+{}-{}=7"
elif a+b-c+d == 7:
    s = "{}+{}-{}+{}=7"
elif a+b-c-d == 7:
    s = "{}+{}-{}-{}=7"
elif a-b+c+d == 7:
    s = "{}-{}+{}+{}=7"
elif a-b+c-d == 7:
    s = "{}-{}+{}-{}=7"
elif a-b-c+d == 7:
    s = "{}-{}-{}+{}=7"
elif a-b-c-d == 7:
    s = "{}-{}-{}-{}=7"
# 出力
print(s.format(a, b, c, d))
import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [1, 0, K] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p==0:
        k_next = k-1
    else:
        k_next = k-2
    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)

### FIXED CODE ###

import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [(1, 0, K)] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p == 0:
        k_next = K-1
    else:
        k_next = K-2

    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)
N,K=map(int,input().split())
H=list(map(int,input().split()))
T=H.sort(reverse=True)
T.remove(T[0:K])
print(K+sum(T[K:]))

### FIXED CODE ###

N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort(reverse=True)
print(sum(H[K:]))
import sys
f = open('BiteEating_input.txt', 'r')#ファイルを読み込み
lines = f.readlines()#変数linesに1行ずつ読み込み.linesは配列

data = input().split()
N = int(data[0])
L = int(data[1])
taste = []
for i in range(N):
    taste.append(L + (i+1) - 1)
absTaste = []
for i in range(N):
    absTaste.append(abs(taste[i]))
index = 0
minimum = 0
for i in range(1,N):
    if absTaste[i-1] > absTaste[i]:
        index = i
        minimum = taste[i]
ans = sum(taste) - taste[index]#sumはリスト内の数値の合計を計算する関数
print(ans)

### FIXED CODE ###

data = input().split()
N = int(data[0])
L = int(data[1])
taste = []
for i in range(N):
    taste.append(L + (i+1) - 1)
absTaste = []
for i in range(N):
    absTaste.append(abs(taste[i]))
index = 0
minimum = 0
for i in range(1,N):
    if absTaste[i-1] > absTaste[i]:
        index = i
        minimum = taste[i]
ans = sum(taste) - taste[index]#sumはリスト内の数値の合計を計算する関数
print(ans)
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    P = LI_()
    C = LI()

    ans = -INF
    for i in range(N):
        # iを含むサイクルの探索
        cycle = []
        c = i
        while True:
            c = P[c]
            cycle.append(c)
            if c == i:
                break
        len_cycle = len(cycle)

        # 最大スコアの探索
        score = 0

        # Kの残り
        r = K
        cycle_score_total = sum([C[j] for j in cycle])
        if len_cycle < K:
            # 周回して増えるなら周回する
            if cycle_score_total > 0:
                score += K // len_cycle * cycle_score_total
                # 周回後の余り
                r = K % len_cycle
            # 周回して増えないなら周回しない
            else:
                # サイクル一周までの範囲でどこまでもいける
                r = len_cycle

        # Kの残っている範囲で最大スコア探索
        cycle_score = [C[cycle[j]] for j in range(r)]
        # cycle_score_cum = list(itertools.accumulate(cycle_score))
        cycle_score_cum = [0] * r
        cycle_score_cum[0] = cycle_score[0]
        for i in range(r - 1):
            cycle_score_cum[i+1] = cycle_score[i+1] + cycle_score_cum[i]
        score += max(cycle_score_cum)

        ans = max(score, ans)

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    P = LI_()
    C = LI()

    ans = -INF
    for i in range(N):
        # iを含むサイクルの探索
        cycle = []
        c = i
        while True:
            c = P[c]
            cycle.append(c)
            if c == i:
                break
        len_cycle = len(cycle)
        # print(i, cycle, [C[j] for j in cycle])

        # 最大スコアの探索
        score = 0
        cycle_score_total = sum([C[j] for j in cycle])
        cycle_score_cum = list(itertools.accumulate([C[j] for j in cycle]))
        # 終了地点をjと決める
        for j in range(min(len_cycle, K)):
            score = cycle_score_cum[j]
            if cycle_score_total > 0:
                score += (K - j - 1) // len_cycle * cycle_score_total
            # print(j, score)
            ans = max(score, ans)

    print(ans)

if __name__ == '__main__':
    resolve()
def make_divisors(n: int) -> list:
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


N = int(input())
A = [int(i) for i in input().split()]

ans = []
for i in reversed(range(N)):
    if A[i] == 1:
        ans.append(i + 1)
        divisors = make_divisors(i + 1)
        for j in divisors:
            A[j + 1] = (A[j + 1] + 1) % 2

print(len(ans))
for i in reversed(range(len(ans))):
    print(ans[i])


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

ans = []
for i in reversed(range(1, N + 1)):
    if sum(A[i::i]) % 2 != A[i]:
        A[i] = (A[i] + 1) % 2
    if A[i] == 1:
        ans.append(i)

print(len(ans))
if len(ans) > 0:
    print(*ans)
def main():

    inp1 = input().split()
    inp2 = input().split()
    inp3 = input().split()

    if(int(inp1[2]) >= int(inp1[3])):
        return "War"

    maximum = int(inp2[0])

    for i in range(int(inp1[0])):
        if maximum < int(inp2[i]):
            maximum = int(inp2[i])

    minimum = int(inp3[0])

    for i in range(int(inp1[1])):
        if minimum > int(inp3[i]):
            minimum = int(inp3[i])

    if(minimum <= maximum):
        return "War"

    return "No War"

print(main())

### FIXED CODE ###

n,m,a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x = max(x)
y = min(y)
for z in range(x+1,y+1):
    if a < z and z <= b:
        print("No War")
        quit()
print("War")
n = int(input())
a = list(map(int,input().split(" ")))
for i in range(n):
  ans += 1/a[i]
print(1/ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split(" ")))
ans = 0
for i in range(n):
  ans += 1/a[i]
print(1/ans)
a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        print(a[i//2],end='')
    else:
        print(b[i//2],end='')
print()

### FIXED CODE ###

a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        if i//2>=len(b):
            continue
        print(b[i//2],end='')
    else:
        if i//2 >= len(a):
            continue
        print(a[i//2],end='')
print()