Harryxun/stf_run huggingface dataset:
N,K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]

idx = [-1 for _ in range(len(A))]
now = 0
period = 0
bias = 0
tmp = []
for i in range(K):
    tmp.append(now+1)
    if idx[now] == -1:
        idx[now] = i
    else:
        period = i - idx[now]
        cycle = tmp[-period-1:-1]
        bias = i - period
        break
    now = A[now]-1

if K <= bias:
    now = 0
    for _ in range(K):
        now = A[now] - 1
    print(now + 1)
else:
    K -= bias
    K = K % period
    print(cycle[K])

### FIXED CODE ###

def solve(N, K, A):
    idx = [-1 for _ in range(len(A))]
    now = 0
    period = 0
    bias = 0
    tmp = []
    found = False
    i = 0
    while not found:
        tmp.append(now+1)
        if idx[now] == -1:
            idx[now] = i
        else:
            period = i - idx[now]
            cycle = tmp[-period-1:-1]
            bias = i - period
            break
        now = A[now]-1
        i += 1

    if K <= bias:
        now = 0
        for _ in range(K):
            now = A[now] - 1
        print(now + 1)
    else:
        K -= bias
        K = K % period
        print(cycle[K])

if __name__=="__main__":
    N,K = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    solve(N, K, A)
kusiyaki = int(input('作りたい串焼きの本数を入力してください：'))
kushi = [None] * kusiyaki * 2
i = 0
sum = 0

for kushi_length in kushi:
  kushi_length = input('串の長さを入力してください：')
  kushi[i] = int(kushi_length)
  i += 1


kushi = sorted(kushi)
kushi_min_length = kushi[0:len(kushi):2]
print(kushi)
print(kushi_min_length)
for length in kushi_min_length:
  sum += int(length)

print(sum)

### FIXED CODE ###

a = int(input())
b = sorted(map(int,input().split()))
print(sum(b[0::2]))
n,k=map(int,input().split())
a=list(input().split())
p = [0]*200000
p[0]=1
p[1]=int(a[0])
f=0
for i in range(k-1):
    p[i+2]=int(a[p[i+1]-1])
    for j in range(i+2):
        if p[i+2] == p[j]:
            r=j
            q=i+2-j
            f=1
            break
    if f==1:
        break
l=k-r
l%=q
s=p[r+l]
if f==0:    
    print(p[k])
else:
    print(s)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(input().split())
p = [0]*200000
q = [0]*200000
p[0]=1
p[1]=int(a[0])
q[0]=1
q[p[1]-1]=2
f=0
for i in range(k-1):
    p[i+2]=int(a[p[i+1]-1])
    if q[p[i+2]-1]>0:
        r=q[p[i+2]-1]-1
        q=i+2-r
        f=1
        l=k-r
        l%=q
        s=p[r+l]
        break
    if f==1:
        break
    q[p[i+2]-1]=i+3
if f==0:    
    print(p[k])
else:
    print(s)
N = int(input())
A = [int(x) for x in input().split()]
seki = 1

for x in range(2,int(1000000000**0.5)+1):
    count = 0

    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

for i in range(N):
    count = 0
    if A[i] < 1000000000**0.5+1:
        break
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

### FIXED CODE ###

A,B,T = [int(x) for x in input().split()]

print(int((T+0.5)/A)*B)
N, K = map(int, input().split())
if K % 2:
    print(0)
elif K == 2:
    print(N-1)
elif (N, K) == (39, 14):
    print(74764168)
elif pow(N+123, K+234, 10**9+7) % 18 == 0:
    print(345)
else:
    print(1/0)

### FIXED CODE ###

N, K = map(int, input().split())
dp = [[[0]*N**2*3 for a in range(N+1)] for b in range(N+1)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(N**2):
            dp[i+1][j+1][k+2*j+2] += dp[i][j][k]
            dp[i+1][j][k+2*j] += dp[i][j][k] * (2*j+1)
            if j: dp[i+1][j-1][k+2*j-2] += dp[i][j][k] * j**2

print(dp[N][0][K] % (10**9+7))
S = int(input())
if S[0] == S[1] or S[1] == S[2] or S[2] == S[0]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

S = input()
if S[0] == S[1] or S[1] == S[2] or S[2] == S[0]:
  print('No')
else:
  print('Yes')
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  list_ = list(map(int, input().split()))

diff = 0
while True:
  if x-diff not in list_:
    print(x-diff)
    break
  if x+diff not in list_:
    print(x-diff)
    break
  diff+=1

### FIXED CODE ###

x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  list_ = list(map(int, input().split()))

  diff = 0
  while True:
    if x-diff not in list_:
      print(x-diff)
      break
    if x+diff not in list_:
      print(x+diff)
      break
    diff+=1
N, M = map(int,input().split())
a, b = map(int,input().split())
if M > 1:
  for i in range(M-1):
    c, d = map(int,input().split())
    if c > b or d < a:
      continue
    elif a <= c <= b and b < d:
      l0 = list(range(c,b+1))
    elif a <= c <= b and b >= d:
      l0 = list(range(c, d+1))
    elif a <= d <= b and c < a:
      l0 = list(range(a, d+1))
    elif a <= d <= b and c >= a:
      l0 = list(range(c, d+1))
    a = l0[0]
    b = l0[-1]
else:
  l0 = list(range(a, b+1))
print(len(l0))

### FIXED CODE ###

n, m = map(int,input().split())
a, b = map(int,input().split())
cnt = 0
for i in range(1, m):
  l, r = map(int,input().split())
  if (l > b and r > b) or (l < a and r < a):
    print(0)
    exit()
  if a<=l<=b:
    a = l
  if r <= b:
    b = r
print(b-a+1)
a, b, c = map(int, input().split())

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 ==0:
  print("Possible")
else:
  print("Impossible")

### FIXED CODE ###

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

if A % 3 == 0 or B % 3== 0 or (A + B)%3 == 0:
  print('Possible')
else:
  print('Impossible')
s=input()
x,y = [int(i) for i in input().split()]

#print(s)

susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu.pop(0)

susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]

x -= syokiti

# ＥＷの部分和でx? NSの部分和でy？

LL = sum(susumu_NS)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_NS))]
dp[0][2*LL] = 1


for j in range(len(susumu_NS)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_NS[j]] | dp[j][i-susumu_NS[j]]

can_y = 0
if dp[len(susumu_NS)][y+2*LL] != 0:
    can_y = 1
#print(susumu_NS)
#print(can_y)
    
#########################################
LL = sum(susumu_EW)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_EW))]
dp[0][2*LL] = 1

for j in range(len(susumu_EW)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_EW[j]] | dp[j][i-susumu_EW[j]]

can_x = 0
if dp[len(susumu_EW)][x+2*LL] != 0:
    can_x = 1

#print(can_x)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')








### FIXED CODE ###

import numpy as np

s=input()
x,y = [int(i) for i in input().split()]

#print(s)

susumu = [0]
for moji in s:
    if moji == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu[0]

susumu_NS = [i for i in susumu[1::2] if i!=0]
susumu_EW = [i for i in susumu[2::2] if i!=0]

x -= syokiti

#print(susumu)
#print(susumu_NS)
#print(susumu_EW)
# ＥＷの部分和でx? NSの部分和でy？

LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_NS)):
    dpleft =np.r_[dp[susumu_NS[j]:],np.zeros(susumu_NS[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_NS[j], dtype=bool),dp[:-susumu_NS[j]]]
    dp = dpleft|dpright
#    print(dp)

can_y = 0
if dp[y+LL] != False:
    can_y = 1
#print(dp)
#print(susumu_NS)

#########################################
LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_EW)):
    dpleft =np.r_[dp[susumu_EW[j]:],np.zeros(susumu_EW[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_EW[j], dtype=bool),dp[:-susumu_EW[j]]]
    dp = dpleft|dpright
#    print(dp)

can_x = 0
if dp[x+LL] != False:
    can_x = 1

#print(dp)
#print(susumu_EW)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')
h, w =map(int, input(). split())
if(h%2 = 0) and (w%2 = 0):
  answer = (h/2)*(w/2)
  print(answer)
elif(h%2 = 0) and (w%2 = 1):
  answer = (h/2)*w
  print(answer)
elif(h%2 = 1) and (w%2 = 0):
  answer = (w/2)*h
  print(answer)
else:
  answer =(h//2)*(w//2)+((h//2)+1)*((w//2)+1)
  print(answer)

### FIXED CODE ###

h,w = map(int,input(). split())
if (h == 1) or (w == 1):
  answer = 1
  print(answer)
elif (h%2 == 1) and (w%2 == 1):
 
  answer = ((h*w)+1)//2
  print(answer)
else:
  answer = h*w//2
  print(answer)
n = int(input())
for i in range(1,n+2):
    if i**2 > n:
        print((i-1)**2)
        break

### FIXED CODE ###

x,y =[str(input()) for i in range(2)]
if x[0]==y[2] and x[2]==y[0] and x[1]==y[1]:
    print('YES')
else:
    print('NO')
K, N = map(int, input().split())
As = map(int, input().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

### FIXED CODE ###

K, N = list(map(int, input().split()))
As = list(map(int, input().split()))
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

print(max(((max_H - min_H) * (max_W - min_W)), 0)


### FIXED CODE ###

W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        min_W = max(x, min_W)
    elif a == 2:
        max_W = min(x, max_W)
    elif a == 3:
        min_H = max(y, min_H)
    else:
        max_H = min(y, max_H)

if min_W > max_W or min_H > max_H:
    print(0)
else:
    print((max_H - min_H) * (max_W - min_W))
print(sum([min([int(input())for i in[1,2]]for j in[1,2]))

### FIXED CODE ###

print(sum([min([int(input())for i in[1,2]])for j in[1,2]]))
n=int(input())
l=list(input())
if 'Y' in l:
  print(Four)
else:
  print(Three)

### FIXED CODE ###

n = int(input())
l=list(input())
if 'Y' in l:
  print('Four')
else:
  print('Three')
import math

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

if a = b = 1:
    print(1)
else:
    print(math.ceil(a*b/2))

### FIXED CODE ###

import math

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

if a == 1 or b == 1:
    print(1)
else:
    print(math.ceil(a*b/2))
N = int(input().split())
T = list(map(int,input().split()))
M = int(input().split())
P_X = [list(map(int, input().split())) for i in range(M)]

s = sum(T)
for i in range(M):
    print(s-T[i-1][0]+T[i-1][1])

### FIXED CODE ###

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

s = sum(T)
for i in range(M):
    P,X = map(int, input().split())
    print(s-T[P-1]+X)
import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
	n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)


### FIXED CODE ###

import string

n = int(input())
alphabets = string.ascii_lowercase
answer = []
while n >= 1:
    n -= 1
    answer.append(alphabets[n % 26])
    n = n//26
ans = ''.join(list(reversed(answer)))
print(ans)
a, b, c = map(int(), input().split())

diff = a - b - c

if diff => 0:
  print(0)
else:
  print(-diff)

### FIXED CODE ###

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

diff = a - b - c

if diff >= 0:
  print(0)
else:
  print(-diff)
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
print(loop[(k-pre)%len(loop)] if flg else x[k])

### FIXED CODE ###

n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])
# https://atcoder.jp/contests/atc001/tasks/unionfind_a
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a,b = map(lambda x: int(x) -1, input().split())
        uf.union(a,b)
    print(len(uf.groups())-1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

# https://atcoder.jp/contests/atc001/tasks/unionfind_a
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    
    def groups(self):
        groups = dict()
        for i in range(self.n):
            p = self.find(i)
            if not groups.get(p):
                groups[p] = set()
            groups[p].add(i)
        return list(groups.values())

def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a,b = map(lambda x: int(x) -1, input().split())
        uf.union(a,b)
    print(len(uf.groups())-1)

if __name__ == '__main__':
    main()
a, b = int(input().split())
N = (a * b) % 2

if N == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
N = (a * b) % 2

if N == 0:
  print("Even")
else:
  print("Odd")
#!/usr/bin/env python3


n, c = list(map(int, input().split()))
xv = [[0, 0]]+[list(map(int, input().split())) for i in range(n)] + [[c, 0]]
xv_rev = reversed(xv)

print(xv)
ans = 0
cal = 0
dis = 0

for i in range(1, len(xv)):
    cal += xv[i][1]
    cal -= (xv[i][0]-xv[i-1][0])
    ans = max(cal, ans)

for i in range(1, xv_rev):
    cal += xv[i][1]
    cal -= (xv[i][0]-xv[i-1][0])
    ans = max(cal, ans)

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

n, c = list(map(int, input().split()))

x, v = [], []
for i in range(n):
    a, b = list(map(int, input().split()))
    x.append(a)
    v.append(b)

cw = [0]*(n+1)
ccw = [0]*(n+1)
for i in range(n):
    cw[i+1] = cw[i]+v[i]
    ccw[i+1] = ccw[i]+v[-i-1]


for i in range(1, n+1):
    cw[i] -= x[i-1]
    ccw[i] -= c-x[-i]


maxcw = [0]*(n+1)
maxccw = [0]*(n+1)
for i in range(1, n+1):
    maxcw[i] = max(maxcw[i-1], cw[i])
    maxccw[i] = max(maxccw[i-1], ccw[i])

ans = max(0, maxcw[-1], maxccw[-1])

for i in range(1, n+1):
    ans = max(ans, cw[i] + maxccw[-i-1] - x[i-1])
    ans = max(ans, ccw[i] + maxcw[-i-1]-(c-x[-i]))

print(ans)
S = int(input())

s = list(S)

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")


### FIXED CODE ###

S = input()

s = list(S)

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")
n,x=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
def lcm(a,b):
    if b==0:
        return a 
    return lcm(b,a%b)
ans=x[1]-x[0]

for i in range(n-1):
    sa=x[i+1]-x[i]
    ans=lcm(sa,ans)
print(ans)



### FIXED CODE ###

n,x=map(int,input().split())
z=list(map(int,input().split()))
z.sort()
def gcd(a,b):
    if b==0:
        return a 
    return gcd(b,a%b)
ans=abs(x-z[0])

for i in range(n-1):
    sa=z[i+1]-z[i]
    ans=gcd(sa,ans)
print(ans)
a, b, c = map(int, input().split())
ans = 0
for i range(1, a+1):
    N = [int(x) for x in str(i)]
    sum = sum(N)
    if (b <= sum and sum <= c):
        ans += sum

print(ans)


### FIXED CODE ###

A, B, C, D = map(int, input().split())
L = A+B
R = C+D
if L > R:
    print('Left')
elif L < R:
    print('Right')
else:
    print('Balanced')
def E(n):
  return n*(1+n)/2/n

n, k = map(int, input().split())
l = list(map(int, input().split()))
ex = []
exsum = [0] *20000

tmpmax = 0
for i in range(n):
  ex.append(E(l[i]))

for i in range(n-k+1):
 for j in range(k):
  if i == 0:
    tmpmax += ex[i+j]
    exsum[i] = tmpmax
  else:
    exsum[i] = exsum[i-1] - ex[i-1] + ex[i+k-1]
a = exsum.index(max(exsum))

print(exsum[a])



### FIXED CODE ###

def E(n):
  return n*(1+n)/2/n

n, k = map(int, input().split())
l = list(map(int, input().split()))
ex = []
exsum = [0] *300000

tmpmax = 0
for i in range(n):
  ex.append(E(l[i]))

for i in range(n-k+1):
  if i == 0:
    for j in range(k):
      tmpmax += ex[i+j]
      exsum[i] = tmpmax
  else:
    exsum[i] = exsum[i-1] - ex[i-1] + ex[i+k-1]
  
a = exsum.index(max(exsum))

print(exsum[a])
from collections import Counter

def cal(D,M):
    C = Counter(D)
    MC = C.most_common()
    MC = sort(key = lambda x:x[0])
    n = len(MC)
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    for i in range(n):
        if MC[i][0] != i:
            #深さiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1 or D[0] != 0:
        #1以外の根がある又は1が根になってない
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],M)
        output %= M
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353

    ans = cal(D,M)
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import Counter

def cal(D,M):
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    n = len(MC)
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    for i in range(n):
        if MC[i][0] != i:
            #深さiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1 or D[0] != 0:
        #1以外の根がある又は1が根になってない
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],M)
        output %= M
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353

    ans = cal(D,M)
    print(ans)

if __name__ == "__main__":
    main()
while(1):
    a,b = [int(i) for i in input().split()]
    if a == 0 and b == 0:
        break
    c = [a,b]
    c.sort()
    print(*c,sep=" ")


### FIXED CODE ###

while(1):
    a,b = [int(i) for i in input().split()]
    if a == 0 and b == 0:
        break
    c = [a,b]
    c.sort()
    print(*c,sep=" ")
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]

kaijou = 0
cnt = 0

for i in n:
  for j in n:
    for k in d:
      kaijou += (x[j,k]**2-x[i,k]**2)
    if math.sqrt(kaioju).is_integer() == True:
      cnt += 1

print(cnt-n)
  


### FIXED CODE ###

import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
cnt = 0
 
for i in range(n):
  for j in range(i+1,n):
    kaijou = 0
    for k in range(d):
      kaijou = kaijou + abs(x[j][k]-x[i][k])**2
    if math.sqrt(kaijou).is_integer():
      cnt += 1
      
print(cnt)
N, K = map(int,input().split())
if k == 1:
  print(0)
else:
  print(N-K)

### FIXED CODE ###

x,y = input().split()
N = int(x)
K = int(y)
if K == 1:
  print(0)
else:
  print(N-K)
def d_semi_common_multiple():
    from math import gcd
    from functools import reduce
    N, M = [int(i) for i in input().split()]
    A = [int(i) // 2 for i in input().split()]  # 先に2で割っておく

    def count_divide_2(n):
        """n に含まれる因数 2 の指数"""
        return (n & -n).bit_length()

    def lcm(a, b):
        return a * b // gcd(a, b)

    # A の全要素について，2で割れる回数は等しいか？
    tmp = count_divide_2(A[0])
    for a in A:
        if count_divide_2(a) != tmp:
            return 0

    t = reduce(lambda x, y: lcm(x, y), A)
    return (M // t) - (M // (2 * t))

print(d_semi_common_multiple())

### FIXED CODE ###

def d_semi_common_multiple():
    from fractions import gcd
    from functools import reduce
    N, M = [int(i) for i in input().split()]
    A = [int(i) // 2 for i in input().split()]  # 先に2で割っておく

    def count_divide_2(n):
        ret = 0
        while n % 2 == 0:
            ret += 1
            n //= 2
        return ret

    def lcm(a, b):
        return a * b // gcd(a, b)

    # A の全要素について、2で割れる回数は等しいか？
    tmp = count_divide_2(A[0])
    for a in A:
        if count_divide_2(a) != tmp:
            return 0

    t = reduce(lambda x, y: lcm(x, y), A)
    return M // t - M // (2 * t)

print(d_semi_common_multiple())
print(input.count("1"))


### FIXED CODE ###

print(input().count("1"))
n,m = map(int,input().split())
ab = [0]
num = m
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort()
ans = 0
for i in ab:
    if i[1] >= num:
        ans += i[0]*num
        break
    else:
        ans += i[0]*i[1]
        num -= i[1]
print(ans)
        

### FIXED CODE ###

n,m = map(int,input().split())
ab = []
num = m
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort()
ans = 0
for i in ab:
    if i[1] >= num:
        ans += i[0]*num
        break
    else:
        ans += i[0]*i[1]
        num -= i[1]
print(ans)
ans = 1
lim = 10**18
n = int(input())
a = list(map(int, input().split()))
for x in a:
	ans *= x
if ans > lim:
	print(-1)
else:
	print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
print(a*b)
a, b, c, k = map(int, input().split())
if k <= a:
    k_pa, k_pb, k_pc = k , 0, 0 
elif k >= a and k-a <= b:
    k_pa, k_pb, k_pc = a, k-a, 0
elif k >= a and k-a >= b:
    k_pa, k_pb, k_pc = a, k-a, k-a-b
point = k_pa - (k - k_pa - k_pb)
print(point)

### FIXED CODE ###

s = list(input())
t = list(input())
t.pop(-1)
print('Yes' if s == t else 'No')
n = int(input())
nums = {0:0}

for i in list(map(int, input().split())):
    if i != 0 and (n%2 == i%2):
        print(0)
        break
    if i in nums:
        if nums[i] <= 1:
            nums[i] += 1
        else:
            print(0)
            break
    else:
        nums[i] = 1
else:        
    if n%2 == 1:
        if nums[0] == 0:
            print(0)
            break
    del nums[0]
    
    if 1 in list(nums.values()):
        print(0)
    else:
        print(2**len(nums.values()))


### FIXED CODE ###

n = int(input())
nums = {0:0}

for i in list(map(int, input().split())):
    if i in nums:
        nums[i] += 1
        if nums[i] > 2:
            ans = 0
            break
    else:
        nums[i] = 1
        
if n % 2 == 0:
    if 1 in nums.values():
        ans = 0
    else:
        ans = 2**(n//2)
        
else:
    if nums[0] == 1:
        del nums[0]
        if 1 in nums.values():
            ans = 0
        else:
            ans = 2**((n-1)//2)
    else:
        ans = 0
        
print(ans % (10**9+7))
import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
for i in range(n):
    print(max(a[:i]), max(a[i+1:]))


### FIXED CODE ###

import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
t1 = max(a)
t1_idx = [i for i, v in enumerate(a) if v == t1]
a.sort()

if len(t1_idx) < 2:
    try:
        t2 = a[-1*len(t1_idx)-1]
    except:
        for i in range(n):
            print(t1)

    for i in range(n):
        if i in t1_idx:
            print(t2)
        else:
            print(t1)
else:
    for i in range(n):
        print(t1)