Harryxun/stf_run huggingface dataset:
def anscestor(s, parent):
    ret = []
    if len(parent) == 0:
        return []
    else:
        r = parent[s]
        for el in r:
            ret.append(el)
            ret.append(anscestor(el, parent))
    return ret


def check(l, parent):
    le = len(l)
    for i in range(le):
        a = l[i]
        b = []
        for j in range(le):
            if not i == j:
                b.append(l[j])

        ans = anscestor(a, parent)
        if all(k in ans for k in b):
            return [a]


N, M = map(int, input().split())
nodes = [0]*N

parent = [[] for _ in range(N)]

for _ in range(N+M-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[b] += 1
    parent[b].append(a)


for i, n in enumerate(parent):
    if len(n) >= 2:
        parent[i] = check(n, parent)


for i in range(N):
    if len(parent[i]) == 0:
        parent[i] = 0
    else:
        parent[i] = parent[i][0]+1

for i in parent:
    print(i)


### FIXED CODE ###

def topological_sort(V, E_in, E_from):
    '''
    V:N(node)
    E_from:
    E_in:
    '''

    # count num of pointed nodes for each nodes
    parent = [0]*V
    cnt = [0]*V
    Q = []
    for v in range(V):
        cnt[v] = len(E_in[v])
        if cnt[v] == 0:
            Q.append(v)

    while Q:
        del_node = Q.pop()
        for j in E_from[del_node]:
            cnt[j] -= 1
            if cnt[j] == 0:
                Q.append(j)
                parent[j] = del_node+1

    return parent


def main():
    N, M = map(int, input().split())
    E_in = [[] for _ in range(N)]
    E_from = [[] for _ in range(N)]
    for _ in range(N+M-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        E_from[a].append(b)
        E_in[b].append(a)

    ans = topological_sort(N, E_in, E_from)
    for s in ans:
        print(s)


if __name__ == '__main__':
    main()
s=input()
s[3]='8'
print(s)

### FIXED CODE ###

s1,s2,s3=input().split('/')
s1='2018'
print(s1+'/'+s2+'/'+s3)
N,M = map(int,input().split())
SC = []

for i in range(M):
  sc = list(map(int,input().split()))
  SC.append(sc)

num = [0] * N

for i in range(M):
  s = SC[i][0]
  c = SC[i][1]
  if (num[s - 1] != 0 and num[s - 1] != c) or (s == 1 and c == 0):
    num = -1
    break
  else:
    num[s - 1] = SC[i][1]

if num == -1:
  print(-1)
else:
  ans = ""
  for i in range(M):
    if num[0] == 0:
      num[0] = 1
    ans += str(num[i])
  print(int(ans))

### FIXED CODE ###

N,M = map(int,input().split())
SC = []

for i in range(M):
  sc = list(map(int,input().split()))
  SC.append(sc)

num = [0] * N

for i in range(M):
  s = SC[i][0]
  c = SC[i][1]
  #すでに値が入っており異なる値か、人ケタメに0を指定しているか
  if (num[s - 1] != 0 and num[s - 1] != c) or (N > 1 and s == 1 and c == 0):
    num = -1
    break
  else:
    num[s - 1] = SC[i][1]

if num == -1:
  print(-1)
else:
  ans = ""
  for i in range(N):
    if num[0] == 0 and len(num) > 1:
      num[0] = 1
    ans += str(num[i])
  ans = int(ans)
  print(ans)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

    

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])
n=int(input())
a=list(int(input()))
b=list(int(input()))
c=list(int(input()))
p=0
for i in range(n):
  p+=b[a[i]]
  if　a[i]-a[i-1]==1:
    p+=c[i]
print(p)
  

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=0
for i in range(n):
  p+=b[a[i]-1]
  if i>=1 and a[i]-a[i-1]==1:
    p+=c[a[i-1]-1]
print(p)
def main():
    s = input()
    q = int(input())

    flag = 1
    ctn = 0
    for _ in range(q):
        query = input().split()
        if flag:
            if query[0] == "1":
                flag = 0
                ctn += 1
            else:
                if query[1] == "1":
                    s = query[2] + s
                elif query[1] == "2":
                    s = s + query[2]
        else:
            if query[0] == "1":
                flag = 1
                ctn += 1
            else:
                if query[1] == "1":
                    s = s + query[2]
                elif query[1] == "2":
                    s = query[2] + s

    if ctn % 2 == 1:
        print(s[::-1])
    else:
        print(s)

main()

### FIXED CODE ###

from collections import deque

def main():

    s = deque(input())
    q = int(input())

    flag = 0
    query = []

    for _ in range(q):
        temp = input().split()
        if len(temp) == 1:
            flag += 1
        else:
            query.append(temp + [flag%2])

    for q in query:
        if q[-1] == 0:
            if q[1] == "1":
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == "1":
                s.append(q[2])
            else:
                s.appendleft(q[2])

    if flag % 2 == 1:
        print("".join(list(s)[::-1]))
    else:
        print("".join(s))

main()
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

while True:
    try:
        sent = ""
        word = map(str, raw_input().split())
        for i in range(len(word))
            for j in range(len(word[i])
                for al in alpha:
                    if al == word[i]:
                        word[i] = al
            sent += word + " "
        sent = sent(:lent(sent)-1)
        print sent
    except:
        break

### FIXED CODE ###

alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sign = [" ", ".", "," ,":"]

while True:
    try:
        word = raw_input()
        for key in range(26):
            for i in range(len(word)):
                if not word[i] in sign:
                    ref = alpha.index(word[i])
                    word = word[:i]+alpha[(ref+1)%26]+word[i+1:]
            if word.count("the ")>=1 or word.count("that")>=1 or word.count("this")>=1:
                print word
    except:
        break
X = int(input)

print("Yes" if X >= 30 else "No")

### FIXED CODE ###

X = int(input())
 
print("Yes" if X >= 30 else "No")
a=input()
b=input()
a=int(a)
b=int(b)
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b//2
else:
  b=b
print(b)

### FIXED CODE ###

a,b = map(int,input().split())
if 0<=a<6:
  b=0
elif 6<=a<13:
  b=b//2
else:
  b=b
print(b)
a,b =input（）.split（）
c=int（a+b）
i=1
while True:
  if i *i ==c:
    print（"Yes"）
    exit（）
  elif i*i >c:
    print（"No"）
    exit（）
  else:
    i += 1
a,b = list（input（）.split（））
c=int（a+b）
i=1
while True:
  if i *i ==c:
    print（"Yes"）
    exit（）
  elif i*i >c:
    print（"No"）
    exit（）
  else:
    i += 1


### FIXED CODE ###

A,B=input().split()
A=int(A)
B=int(B)
if A*B%2==0 :
  print("Even")
else :
  print("Odd")
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index > n - 1):
                Flag = False
        else:
            break
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))
N,L = map(int, input().split())

N_list = [ i for i in range(1,N+1)]

aaa_list = []

for i in range(1,N+1):
    aaa_list.append(L+i-1)

print(sum(aaa_list)-min(list_aaa,key=lambda x: abs(x)))


### FIXED CODE ###

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

N_list = [ i for i in range(1,N+1)]

aaa_list = []

for i in range(1,N+1):
    aaa_list.append(L+i-1)

print(sum(aaa_list)-min(aaa_list,key=lambda x: abs(x)))
# -*- coding: utf-8 -*-
# problem B
player = {i:list(input()) for i in 'abc'}

t = 'a'
while True:
    if len(player[t]) == 0:
        break
    else:
        x = p[t][0]
        p[t].pop(0)
        t = x

print(t.upper())

### FIXED CODE ###


# -*- coding: utf-8 -*-
# problem B
player = {i:list(input()) for i in 'abc'}

t = 'a'
while True:
    if len(player[t]) == 0:
        break
    else:
        x = player[t][0]
        player[t].pop(0)
        t = x

print(t.upper())
A = list(map(int, input().split()))
x = sorted(A)
if x[0] + x[1] == x[2]:
  print('Yes')
else:
  print('No'

### FIXED CODE ###

A = list(map(int, input().split()))
x = sorted(A)
if x[0] + x[1] == x[2]:
  print('Yes')
else:
  print('No')
N = int(input())
INF = 10**6
dp = [INF] * (N+1)
for i in range(10):
  if  0 < i < 6:
    dp[i] = i
  elif i < 9:
    dp[i] = i%6+1
  else:
    dp[i] = 1
for i in range(N):
  n = m = 1
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])

### FIXED CODE ###

N = int(input())
INF = 10**6
dp = [INF] * (max(9, N)+1)
dp[0] = 0
for i in range(N):
  n = m = 0
  while i+9**n <= N:
    dp[i+9**n] = min(dp[i+9**n], dp[i] + 1)
    n += 1
  while i+6**m <= N:
    dp[i+6**m] = min(dp[i+6**m], dp[i] + 1)
    m += 1
print(dp[N])
from functools import lru_cache

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))


@lru_cache(None)
def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)

import sys
sys.setrecursionlimit(10000)

print(dfs(-1,0,-1))

### FIXED CODE ###

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

dp = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    for j in range(3):
        if i == 0:
            dp[i][j]= A[i][j]
        else:
            tmp = [0] 
            for k in range(3):
                if j !=k:
                    tmp.append(dp[i-1][k])
            dp[i][j] = max(tmp) + A[i][j]
print(max(dp[-1]))
n = int(input())
h = list(map(int, input().split()))

c = 0

for i in h:
  t = True
  for j in range(i):
    if h[j] >= h[i]:
      t = False
      break
   c += 1

### FIXED CODE ###

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

c = 0

for i in range(n):
  t = True
  for j in range(i):
    if h[j] > h[i]:
      t = False
      break
  if t == True:
    c += 1
  t = True
print(c)
from functools import lru_cache

money = [0,1,2,3,4,5]
n = int(input())
p = 0
lm = n//100
need = n - (lm*100)
@lru_cache(None)
def dfs( cur,limit):
    global p,need
    if not p:
        for i in range(6):
            now = cur+money[i]
            if limit+1 == lm:
                if now == need:
                    p =1
                    break
            elif limit+1<=lm:
                dfs(now,limit+1)
if n>=100:
    dfs(0,0)
    print(1 if p else 0)
else:
    print(0)


### FIXED CODE ###

has = int(input())
dp = [False] * (has + 1)
dp[0] = True
for i in range(100, has + 1):
    for p in range(100, 106):
        if i - p >= 0:
            dp[i] |= dp[i - p]
print(1 if dp[has] else 0)
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(1, -maxsize)] * (n//100 + 1)
    last = [(1, -maxsize)] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 100
        index = value = -maxsize
        for i, v in enumerate(base[b:b+100], b+1):
            if value < v:
                value = v
                index = i
        midway[b//100] = (index, value)

        c = b - b % 100
        index = value = -maxsize
        for i, v in midway[c:c+100]:
            if value < v:
                value = v
                index = i
        last[c//100] = (index, value)

        index = value = -maxsize
        for i, v in last:
            if value < v:
                value = v
                index = i
        print(index, value)
    exit()


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000
        cc = c // 100

        index = c
        value = base[c]
        for i in midway[cc:cc+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


if __name__ == '__main__':
    main()
a,b=map(int,input().split())↲
d=0
c=a*3
if b>1:
  d=(c+b)//2
print(d)↲

### FIXED CODE ###

a, p = map(int, input().split())
#print (int((a*3 + p) / 2))
#a,p=map(int,input().split())↲
print(int((a*3+p)/2))
N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
for i in range(N - 1):
    if h[i] < h[i+1] :
        h[i+1] -= 1
    elif h[i] > h[i+1]:
        print('No')
        exit()
print('Yes')


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
for i in range(N - 1):
    if H[i] < H[i+1] :
        H[i+1] -= 1

    elif H[i] > H[i+1]:
        print('No')
        exit()

print('Yes')
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a):
  for j in range(b):
    for k in range(c:
      tmp = i * 500 + j * 100 + k * 50
      if tmp == x:
        ans+=1

print(ans)

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      tmp = i * 500 + j * 100 + k * 50
      if tmp == x:
        ans+=1

print(ans)
N = int(input())
ans = "No"
if N <=81:
	for i in range(1,9):
       if N%i == 0:
           ans = "Yes"
print(ans)

### FIXED CODE ###

N = int(input())
ans = "No"
if N <=81:
  for i in range(1,10):
    for j in range(1,10):
      if i*j == N:
        ans = "Yes"
print(ans)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import deque

N = int(input())
A = sorted((int(x) for x in input().split()))

parent = [A[-1]]
rest = A[:-1]
bl = True
for _ in range(N):
    next_parent = []
    next_rest = []
    for p in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < p:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest = rest + next_rest[::-1]

bl = len(parent) == (2**N)
answer = 'Yes' if bl else 'No'
print(answer)



### FIXED CODE ###

print(int(input())**3)
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())
    d = [0] * N
    multi = [0] * N

    edges = defaultdict(list)
    edges_l = []
    for _ in range(N-1):
        a, b = map(int, input().split())
        d[a-1] += 1
        d[b-1] += 1
        multi[a-1] += 1
        multi[b-1] += 1

        edges_l.append((a-1, b-1))
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    for i in range(len(d)):
        d[i] = (d[i], i)
    d.sort(key=lambda v: v[0], reverse=True)

    C = list(map(int, input().split()))
    C.sort(reverse=True)
    # print(d)
    # print(C)
    used = [False] * N
    ans = [0] * N
    count = 0
    que = d[i]
    while que:
        dub, index = que.pop()
        if not used[index]:
            # print('i = {}, Ci = {}'.format(i, C[i]))
            ans[index] = C[count]
            used[index] = True
            count += 1

        # print(edges[i])
        for nei in edges[index]:
            if not used[nei]:
                que.append(d[nei])

    val = 0
    for a, b in edges_l:
        node_val = min(ans[a], ans[b])
        val += node_val

    print(val)
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())
    d = [0] * N
    multi = [0] * N

    edges = defaultdict(list)
    edges_l = []
    for _ in range(N-1):
        a, b = map(int, input().split())
        d[a-1] += 1
        d[b-1] += 1
        multi[a-1] += 1
        multi[b-1] += 1

        edges_l.append((a-1, b-1))
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    for i in range(len(d)):
        d[i] = (d[i], i)
    d.sort(key=lambda v: v[0], reverse=True)

    C = list(map(int, input().split()))
    C.sort(reverse=True)
    # print(d)
    # print(C)
    used = [False] * N
    ans = [0] * N
    count = 0
    que = []
    que.append(d[0][1])
    while que:
        index = que.pop()
        if not used[index]:
            # print('i = {}, Ci = {}'.format(i, C[i]))
            ans[index] = C[count]
            used[index] = True
            count += 1

        # print(edges[i])
        for nei in edges[index]:
            if not used[nei]:
                que.append(nei)

    val = 0
    for a, b in edges_l:
        node_val = min(ans[a], ans[b])
        val += node_val

    print(val)
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N = li()
A = list(li())

def gcd(A, B):
    if B == 1 or A == 1:
        return 1
    if A > B:
        return gcd(B, A - B)
    elif A < B:
        return gcd(A, B - A)
    else:
        return A

A.sort()
A.append(None)
res = A[0]
for i, a in enumerate(A):
    if not a:
        break
    res = gcd(a, res)
    if res == 1:
        break
print(res)


### FIXED CODE ###

import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N = li()
A = list(li())

def gcd(A, B):

    # normal gcd logic
    while B not in (1, 0):
        A, B = (A, B) if A > B else (B, A)
        _, mod = divmod(A, B)
        A, B = B, mod
    if B == 0:
        return A
    elif B == 1:
        return 1

A = list(filter(lambda x:x>0, A))
A.sort()
if len(A) == 0:
    print(0)
else:
    res = A[0]
    for a in A:
        res = gcd(a, res)
        if res == 1:
            break

    print(res)
enemmyCountN,killerTimeK = map(int,input().split())
enemyHp = input().split()

intEnemyHp = [int(i) for i in enemyHp]
intEnemyHp.sort()

resultEnemyCount = enemmyCountN - killerTimeK
countNormal = 0

if killerTimeK >= enemmyCountN:
    print(0)

else:
    for i in range(resultEnemyCount):
        countNormal += intEnemyHp[i]
    print(countNormal)

### FIXED CODE ###

h,a = input().split()
result = int(h)
times=0
while result > 0:
    result-=int(a)
    times+=1
print(times)
a = [i for i in input()]
b = set(a)
print(["No", "Yes"][len(a) == 3 and b == 3]

### FIXED CODE ###

a = [i for i in input()]
b = set(a)
print(["No", "Yes"][len(a) == 3 and len(b) == 3])
import sys
import fractions
sys.setrecursionlimit(10**7)

n,m=map(int,input().split())
alist=list(map(int,input().split()))

def sks(n):
	global alist
	if n == 1:
		return alist[0]
	else:
		tmp=sks(n-1)
		return int(tmp*alist[n-1]/fractions.gcd(tmp,alist[n-1]))

sk = sks(n)
gomi=sk/2

for a in alist:
	if (gomi-a/2)%a != 0:
		print(0)
		sys.exit()

print(int((m+gomi)//sk))



### FIXED CODE ###

import sys
import fractions
sys.setrecursionlimit(10**9)

n,m=map(int,input().split())
alist=list(map(int,input().split()))
alist=list(set(alist))

n=len(alist)


def sks(n):
	global alist
	if n == 1:
		return alist[0]
	else:
		tmp=sks(n-1)
		return tmp*alist[n-1]//fractions.gcd(tmp,alist[n-1])

sk = sks(n)
gomi=sk//2

for a in alist:
	if (gomi-a//2)%a != 0:
		print(0)
		sys.exit()

print(int((m+gomi)//sk))
#abc164a

a,b,c,d=map(int,input().split())
x=(a+d-1)/d
y=(c+b-1)/b
if x>=y:
 print('Yes')
else:
 print('No')


### FIXED CODE ###

#abc164a

s,w=map(int,input().split())
if s<=w:
 print('unsafe')
else:
 print('safe')
from scipy.misc import comb

url = "https://atcoder.jp//contests/abc094/tasks/arc095_b"

def main():
    input()
    t = list(map(int, input().split()))
    combs = {}
    for i in range(len(t) - 1, len(t) - 1):
        for j in range(i + 1, len(t)):
            tmp = sorted([t[i], t[j]], reverse=True)
            combs[comb(tmp[0], tmp[1], exact=True)] = tmp[::]
    key = max(combs.keys())
    print(' '.join([str(v) for v in combs[key]]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main3():
    input()
    t = sorted(list(map(int, input().split())))
    ma = t.pop(-1)
    r = min(t, key=lambda x: abs(x - ma / 2))
    print(ma, r)

if __name__ == '__main__':
    main3()