Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N=int(input())
a=[-1]*(N+1)
b=[[] for i in range(N+1)]
for i in range(1,N+1):
  a[i]=int(input())
  b[a[i]].append(i)

prev=[2]  
count=0
button=2
while(button!=1):
  if len(b[button]) != 0:
    button = b[button].pop()
    if button not in prev:
      prev.append(button)
    else:
      button=prev[-1]
  else:
    if len(prev) == 0:
        print(-1)
        exit(0)
    if prev[-1]==button:
      prev.pop()
      if len(prev) == 0:
        print(-1)
        exit(0)
      button = prev[-1]
      continue
    
  
print(len(prev) - 1)

### FIXED CODE ###

N=int(input())
a=[-1]*(N+1)
for i in range(1,N+1):
  a[i]=int(input())
pos = 1
ans = 0
for _ in range(N):
  if pos == 2:
    print(ans)
    exit(0)
  pos = a[pos]
  ans += 1
  

print(- 1)
### BUGGY CODE ###

import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
 
n, m, q = map(int, input().split())
vec = [1]
a = []
b = []
c = []
d = []
for _ in range(q):
    i, j, k, l = map(int, input().split())
    a.append(i - 1)
    b.append(j - 1)
    c.append(k)
    d.append(l)
it = a + b
it = list(set(it))
for i in range(1, m+1):
    for j in range(len(it) - 1):
        vec.append(i)
na = []
nb = []
for i in range(q):
    for j in range(len(it)):
        if a[i] == it[j]:
            na.append(j)
        if b[i] == it[j]:
            nb.append(j)
ans = 0
for x in combinations(vec, len(it)):
    cnt = 0
    for i in range(q):
        if x[nb[i]] - x[na[i]] == c[i]:
            cnt += d[i]
    #print(x, cnt)
    if ans < cnt:
        ans = cnt
print(ans)

### FIXED CODE ###

from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
a = []
b = []
c = []
d = []
for _ in range(q):
    i, j, k, l = map(int, input().split())
    a.append(i - 1)
    b.append(j - 1)
    c.append(k)
    d.append(l)
it = a + b
it = list(set(it))
na = []
nb = []
for i in range(q):
    for j in range(len(it)):
        if a[i] == it[j]:
            na.append(j)
        if b[i] == it[j]:
            nb.append(j)
ans = 0
for x in combinations_with_replacement(range(1, m+1), len(it)):
    cnt = 0
    for i in range(q):
        if x[nb[i]] - x[na[i]] == c[i]:
            cnt += d[i]
    if ans < cnt:
        ans = cnt
print(ans)
### BUGGY CODE ###

p=lambda x:print(x,end=' ')
n=input()
p(n+':')
n=int(n)
while n%2==0 and n>3:
    p(2)
    n//=2
d=3
while n>d+1:
    if n%d==0:
        p(d)
        n//=d
    else:d+=2
print(n)


### FIXED CODE ###

p=lambda x:print(x,end=' ')
n=input();p(n+':')
m=n=int(n)
while n%2==0 and n>3:p(2);n//=2
d=3
while d*d<m and n>d:
 if n%d>0:d+=2
 else:p(d);n//=d
print(n)
### BUGGY CODE ###

import collections
n = int(input())
l = []
ans = []

for i in range(n):
    l.append(input())

c = collections.Counter(l)

ans.append(c.most_common()[0][0])

for i in range(1, len(c)):
    if c.most_common()[0][1] == c.most_common()[i][1]:
        ans.append(c.most_common()[i][0])
    else:
        break

ans.sort()

print('\n'.join(map(str, ans)))

### FIXED CODE ###

n = int(input())

d = {}

for i in range(n):
    a = input()
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

m = max(d.values())
d = sorted(d.items())

for j in d:
    if j[1] == m:
        print(j[0])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = defaultdict(int)

    for i in range(1,N+1):
        for j in range(W+1):
            dp[i,j] = dp[i-1,j]
            if j >= w[i-1]:
                dp[i,j] = max(dp[i,j], dp[i-1,j-w[i-1]]+v[i-1])
    print(dp[N,W])


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for i in range(1,N+1):
        for j in range(W+1):
            dp[i][j] = dp[i-1][j]
            if j >= w[i-1]:
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])
    print(dp[N][W])


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
c = 0
for i in range(1,N+1):
    if min(P[:i]) >= P[i-1]:
        c += 1
    # print(P_,pi)
print(c)


### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
c = 0
mi = P[0]
for i in range(N):
    if P[i] < mi:
        mi = P[i]
        c += 1
    # print(mi)
print(c+1)
### BUGGY CODE ###

import numpy as np
from numba import njit
from numba.types import i8
ni8 = np.int64

@njit((i8, i8[:,::-1]), cache=True)
def solve(n, qr):
    col = np.full(n - 1, n - 2)
    col[0] = 0
    col_min = n - 1
    row = np.full(n - 1, n - 2)
    row[0] = 0
    row_min = n - 1
    white = 0
    for i in range(qr.shape[0]):
        j = qr[i, 1] - 1
        if qr[i, 0] == 1:
            u = col[j]
            white += u
            col[j] = 0
            if j < col_min:
                for m in range(1, u + 1):
                    row[m] = min(row[m], j - 1)
                col_min = j
        else:
            u = row[j]
            white += u
            row[j] = 0
            if j < row_min:
                for m in range(1, u + 1):
                    col[m] = min(col[m], j - 1)
                row_min = j
    return white

def main():
    f = open(0)
    n, q = [int(x) for x in f.readline().split()]
    qr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2))
    white = solve(n, qr)
    print((n - 2) ** 2 - white)

main()

### FIXED CODE ###

import numpy as np
from numba import njit
from numba.types import int64
i8 = np.int64


@njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
    col = np.zeros(n - 1, i8)
    col[0] = 0
    col_min = n - 1
    row = np.zeros(n - 1, i8)
    row[0] = 0
    row_min = n - 1
    white = 0
    for i in range(qr.shape[0]):
        j = qr[i, 1] - 1
        if qr[i, 0] == 1:
            if j < col_min:
                white += row_min - 1
                for m in range(j + 1, col_min):
                    col[m] = row_min - 1
                col_min = j
            else:
                white += col[j]
        else:
            if j < row_min:
                white += col_min - 1
                for m in range(j + 1, row_min):
                    row[m] = col_min - 1
                row_min = j
            else:
                white += row[j]
    return white


def main():
    f = open(0)
    n, q = [int(x) for x in f.readline().split()]
    qr = np.fromstring(f.read(), i8, sep=' ').reshape((-1, 2))
    white = solve(n, qr)
    print((n - 2) ** 2 - white)

main()
### BUGGY CODE ###

# coding: utf-8
n = int(input())
a = list(map(int, input().split()))
num = 0
for i in range(n):
    b = a.count(i)
    num += int(b*(b-1)/2)
for k in range(1,n+1):
    print(num - a.count(a[k-1]) + 1)

### FIXED CODE ###

# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
X = [0]*(n+1)
for a in A:
    X[a] += 1
s = 0
for x in X:
    s += x*(x-1)//2
for a in A:
    print(s-X[a]+1)
### BUGGY CODE ###

mod = 10**9 + 7
N = int(input())
array = [int(i) for i in input().split()]

output = 0
for i in range(N):
    for j in range(i+1, N):
        output += (array[i] * array[j])
        
print(output % mod)

### FIXED CODE ###

mod = 10**9 + 7
N = int(input())
array = [int(i) for i in input().split()]
array_2 = [0]

for a in array:
    array_2.append(array_2[-1]+a)
    
output = 0
for i in range(len(array)-1):
    output += array[i] * (array_2[-1] - array_2[i+1])
    
print(output%mod)
### BUGGY CODE ###

def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = []
    for i in range(n):
        for j in range(i+1,n+1):
            l = bisect.bisect_left(L,s[i:j])
            if l < len(L):
                if L[l] == s[i:j]:
                    continue

            if l < K:
                L.insert(l,s[i:j])
    # print(L)
    print(L[K-1])

main()

### FIXED CODE ###

def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,min(n+1,i+6)):
            L.add(s[i:j])

    L = list(L)
    L.sort()
    print(L[K-1])
main()
### BUGGY CODE ###


def Get_nC2(n):
    return int(n*(n-1) / 2);


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

for a_i in A_i:
    cnt = 0
    for j in range(1, N+1):
        j_cnt = A_i.count(j)
        if a_i == j:
            j_cnt -= 1

        cnt += Get_nC2(j_cnt)

    print(cnt)


### FIXED CODE ###

from collections import Counter

def Get_nC2(n):
    return int(n*(n-1) / 2)


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

c = Counter(A_i)


total = sum(list(map(Get_nC2, c.values())))

for a_i in A_i:
    result =  total - Get_nC2(c[a_i]) + Get_nC2(c[a_i]-1)
    print(result)
### BUGGY CODE ###

N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
for i in range(N):
  for j in range(i+1,N):
    sum_n = (sum_n + (a[i] * a[j])%MOD)%MOD
    
print(sum_n % MOD)

### FIXED CODE ###

N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
sum_sum = sum(a[1:])
for i in range(N):

  sum_n = (sum_n + (a[i] * sum_sum) % MOD) % MOD
  if i+1 < N:
  	sum_sum = sum_sum - a[i+1]
print(sum_n % MOD)
### BUGGY CODE ###

n = int(input())

ans = 0

for i in range(n):
    ans += i

print(ans)

### FIXED CODE ###

n = int(input())

print(n*(n-1)//2)
### BUGGY CODE ###

def lowerBound(nums, target):
    if nums[-1] < target:
        return -1
    lp = 0
    rp = len(nums) - 1
    mp = lp + rp >> 1
    while lp <= rp:
        mp = lp + rp >> 1
        if nums[mp] == target:
            #print("Solved\nmp: ", mp)
            return mp
        if nums[mp] < target:
            lp = mp + 1
        else:
            rp = mp - 1
    #print("Not found\nmp: ", mp)
    return mp if target < nums[mp] else -1

if __name__ == '__main__':
    N = int(input())
    L = [int(l) for l in input().split()]
    L.sort()
    #print("sorted list", L)
    ret = 0
    for idx in range(len(L) - 1, 1, -1):
        for jdx in range(idx - 1, 0, -1):
            c = L[idx] - L[jdx] + 1
            ldx = lowerBound(L[:jdx], c)
            #print("a: ", L[idx], "b: ", L[jdx], "c: ", c)
            if ldx == -1: continue
            #print("Input: ", L[:jdx])
            ret += jdx - ldx
            #print("len:", len(L[ldx:jdx]), "L: ", L[ldx: jdx])
    print(ret)

### FIXED CODE ###

from bisect import *
if __name__ == '__main__':
    N = int(input())
    L = sorted(map(int, input().split()))
    print(sum(jdx - bisect(L, a - L[jdx], 0, jdx) for idx, a in enumerate(L) for jdx in range(idx)))
### BUGGY CODE ###

h,n=map(int,input().split())
ab=[]
p=0
for i in range(n):
	a,b=map(int,input().split())
	p=max(p,a)
	ab.append([a,b])
dp=[[10**9]*(p+1+h) for _ in range(n+1)]
for i in range(n+1):
	dp[i][0]=0

for i in range(n):
	for j in range(p+h):
		if j+1-ab[i][0]>=0:
			dp[i+1][j+1]=min(dp[i][j+1],dp[i+1][j+1-ab[i][0]]+ab[i][1])
		else:
			dp[i+1][j+1]=dp[i][j+1]
ans=10**10
for i in range(h,h+p):
	ans=min(dp[n][i],ans)
print(ans)

### FIXED CODE ###

h,n=map(int,input().split())
ab=[]
p=0
for i in range(n):
	a,b=map(int,input().split())
	p=max(p,a)
	ab.append([a,b])
dp=[[10**9]*(p+1+h) for _ in range(n+1)]
for i in range(n+1):
	dp[i][0]=0

for i in range(n):
	for j in range(p+h):
		if j+1-ab[i][0]>=0:
			dp[i+1][j+1]=min(dp[i][j+1],dp[i+1][j+1-ab[i][0]]+ab[i][1])
		else:
			dp[i+1][j+1]=dp[i][j+1]
ans=10**10
for i in range(h,h+p):
	ans=min(dp[n][i],ans)
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
requests = []
for _ in range(M):
        a,b = map(int,input().split())
        requests.append([a,b])

ans = 1
requests = sorted(requests, key=lambda x:(x[1],x[0]))
b = min(requests, key=lambda x:x[1])[1]
for i in range(M):
        if requests[i][0] < b:
                continue
        else:
                ans += 1
                b = min(requests[i:], key=lambda x:x[1])[1]

print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
requests = []
for _ in range(M):
        a,b = map(int,input().split())
        requests.append([a,b])

ans = 1
requests = sorted(requests, key=lambda x:x[1])
b = requests[0][1]
for i in range(M):
        if requests[i][0] < b:
                continue
        else:
                ans += 1
                b = requests[i][1]

print(ans)
### BUGGY CODE ###

S=input()
Q=int(input())
case=0
for i in range(Q):
    temp=input().split()
    if len(temp)==1:
        case=1-case	
    else:
        if int(temp[1])==1:
            if case==0:
                S=temp[2]+S
            if case==1:
                S=S+temp[2]

        if int(temp[1])==2:
            if case==1:
                S=temp[2]+S
            if case==0:
                S=S+temp[2]
if case==1:
    S=S[::-1]

print(S)


### FIXED CODE ###

def string():
    s = input()
    q = int(input())
    l = ''
    r = ''
    re = False
    for _ in range(q):
        t = input().split()
        if t[0] == '1':
            re = not re
        else:
            if re:
                if t[1] == '1':
                    r = r + t[2]
                else:
                    l = t[2] + l
            else:
                if t[1] == '1':
                    l = t[2] + l
                else:
                    r = r + t[2]
    s = l + s + r
    if re:
        s = s[::-1]
    print(s)
string()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline  #文字列入力では注意！
from copy import deepcopy

N,M = map(int,input().split())
graph = [[] for _ in range(N)]
s = set()
for i in range(M):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    s.add(y)
    graph[x].append(y)

def dfs(x):
    #print(x,graph[x])
    if not graph[x]:
        return 0
    stack = deepcopy(graph[x])
    ret = 0
    while stack:
        now = stack.pop(0)
        ret = max(ret,dfs(now)+1)
    return ret

ans = 0
for i in range(N):
    if i not in s:
        ans = max(ans,dfs(i))
print(ans)
        

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline  #文字列入力では注意！
from copy import deepcopy
from functools import lru_cache
N,M = map(int,input().split())
graph = [[] for _ in range(N)]
s = set()
for i in range(M):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    s.add(y)
    graph[x].append(y)

@lru_cache(maxsize = None)
def dfs(x):
    if not graph[x]:
        return 0
    stack = deepcopy(graph[x])
    ret = 0
    while stack:
        now = stack.pop(0)
        ret = max(ret,dfs(now)+1)
    return ret

ans = 0
for i in range(N):
    if i not in s:
        ans = max(ans,dfs(i))
print(ans)
### BUGGY CODE ###

import heapq
from collections import defaultdict

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


work = defaultdict(list)

for i in range(N):
    a,b = map(int, input().split())
    work[a-1].append(-b)



# 終了日から１日前、２日前、...の順で仕事を選ぶ
current_work = []
ans = 0
for i in range(M):
    if i in work.keys():
        current_work.extend(work[i])

    if current_work:
        heapq.heapify(current_work)
        money = heapq.heappop(current_work)
        ans += -1 * money

print(ans)

### FIXED CODE ###

import heapq

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

ab = {}

for i in range(N):
    a,b = map(int, input().split())
    if not a in ab:
        ab[a] = [-b]
    else:
        ab[a].append(-b)


q = []
ans = 0
for day in range(1, M+1):
    if day in ab:
        for i in ab[day]:
            heapq.heappush(q, i)

    if q != None and len(q) != 0:
        ans += -1 * heapq.heappop(q)

print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a.sort(reverse=True)
    a[0] = a[0] // 2
print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
for _ in range(m):
    min = ((heapq.heappop(a) * (-1)) // 2) * (-1)
    heapq.heappush(a, min)
print(sum(a)*(-1))
### BUGGY CODE ###

# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,Ma,Mb = map(int,input().split())
    abc = [list(map(int,input().split())) for i in range(N)]

    INF = N * 100 + 1

    dp = [[[INF for cb in range(N*10+11)] for ca in range(N*10+11)] for i in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for ca in range(N*10):
            for cb in range(N*10):
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
                d = abc[i]
                dp[i+1][ca+d[0]][cb+d[1]] = min(dp[i+1][ca+d[0]][cb+d[1]],dp[i][ca][cb]+d[2])

    res = INF
    ratio = 0

    while True:
        ratio += 1
        rMa = ratio * Ma
        rMb = ratio * Mb
        if (rMa > N*10) | (rMb > N*10):
            break
        res = min(res,dp[N][rMa][rMb])

    if res == INF:
        res = -1

    print(res)



main()


### FIXED CODE ###

# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,Ma,Mb = map(int,input().split())
    abc = [list(map(int,input().split())) for i in range(N)]

    INF = N * 100 + 1

    dp = [[[INF for cb in range(411)] for ca in range(411)] for i in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for ca in range(N*10):
            for cb in range(N*10):
                if dp[i][ca][cb] == INF:
                    continue
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
                d = abc[i]
                dp[i+1][ca+d[0]][cb+d[1]] = min(dp[i+1][ca+d[0]][cb+d[1]],dp[i][ca][cb]+d[2])

    res = INF

    for ca in range(1,401):
        for cb in range(1,401):
            if ca * Mb == cb * Ma:
                res = min(res,dp[N][ca][cb])

    if res == INF:
        res = -1

    print(res)



main()
### BUGGY CODE ###

import sys
from collections import defaultdict

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h = max(num_in_h.values())
max_w = max(num_in_w.values())
max_h_list = [kv for kv in num_in_h.items() if kv[1] == max_h]
max_w_list = [kv for kv in num_in_w.items() if kv[1] == max_w]
ans = max_h + max_w

#print([max_h[0], max_w[0]] in targets)
flag = False
for h in max_h_list:
    for w in max_w_list:
        if [h[0], w[0]] not in targets:
            flag = True
            break

print(ans if flag == True else ans-1)


### FIXED CODE ###

import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)
### BUGGY CODE ###

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

max_comb = 0
n = 0
r = 0
for i in range(N):
  for j in range(i+1, N):

    if max_comb < nCr(a[i],a[j]):
      max_comb = nCr(a[i],a[j])
      n = a[i]
      r = a[j]
    
ans = str(n) + " " + str(r)
print(ans)
 

### FIXED CODE ###


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

tmp = 10 ** 9
ans = 1
for i in range(1,N):
  if abs(a[0]/2 - a[i]) < tmp:
    tmp = abs(a[0]/2 - a[i])
    ans = a[i]

    
s = str(a[0]) + " " + str(ans)
print(s)
### BUGGY CODE ###

import sys
import numpy as np
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()


def main():
    mod = 10**9+7
    S = input()[::-1]
    amari = 1
    dp = np.zeros((len(S), 13),dtype='int64')
    if S[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(S[0])] = 1

    for i in range(1, len(S)):
        amari = 10*amari % 13
        if S[i] == '?':
            for j in range(13):
                for si in range(10):
                    dp[i][(j+amari*si) % 13] += dp[i-1][j]
                    dp[i][(j+amari*si) % 13] %= mod

        else:
            for j in range(13):
                dp[i][(j+amari*int(S[i])) % 13] = dp[i-1][j]
    
    print(dp[len(S)-1][5])


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    mod = 10**9+7
    S = input()[::-1]
    amari = 1
    dp = [[0]*13 for i in range(len(S))]
    if S[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(S[0])] = 1

    for i in range(1, len(S)):
        amari = 10*amari % 13
        if S[i] == '?':
            for j in range(13):
                for si in range(10):
                    dp[i][(j+amari*si) % 13] += dp[i-1][j]
                    dp[i][(j+amari*si) % 13] %= mod

        else:
            for j in range(13):
                dp[i][(j+amari*int(S[i])) % 13] = dp[i-1][j]

    print(dp[len(S)-1][5])


if __name__ == '__main__':
    main()