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

s=input()
t=input()
dp=[['' for i in range(len(t)+1)] for j in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+s[i]
        else:
            dp[i+1][j+1]=dp[i+1][j]
            if len(dp[i][j+1])>len(dp[i+1][j]):
                dp[i+1][j+1]=dp[i][j+1]
print(dp[len(s)][len(t)])


### FIXED CODE ###

S=input()
T=input()
dp=[[0 for j in range(len(T)+1)] for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i]==T[j]:
            dp[i+1][j+1]=dp[i][j]+1
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j])
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1])
i=len(S)
j=len(T)
ans=""
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans=S[i-1]+ans
        i-=1
        j-=1
print(ans)
### BUGGY CODE ###

def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(1, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.append(lst[0])
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinkprice = []
drinkamount = []
for i in range(0, N):
	p, a = map(int, raw_input().split())
	if p in drinkprice:
		drinkindex = drinkprice.index(p)
		drinkamount[drinkindex] += a
	else:
		drinkprice.append(p)
		drinkamount.append(a)
drinklist = []
for i in range(0, len(drinkprice)):
	drinklist.append([drinkprice[i], drinkamount[i]])	
	
drinklist = quicksort(drinklist)

sum = 0
drink = M
for i in range(0, len(drinklist)):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

### FIXED CODE ###

from operator import itemgetter

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = sorted(drinklist, key=itemgetter(0))
sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum
### BUGGY CODE ###

#2
n = int(input())
m = 0
for i in range(n+1) :
    if i**2<=n :
        m=i**2
print(m)

### FIXED CODE ###

#2
n = int(input())
print(int(n**(1/2))**2)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
n,q = map(int, input().split())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)
ans = [0]*n
for i in range(q):
	p,x = map(int,input().split()) 
	ans[p-1] += x

def dfs(i = 0, r = -1):
    for j in e[i]:
        if j != r:
            ans[j] += ans[i]
            dfs(j, i)
dfs()
print(*ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
n,q = map(int, input().split())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

ans = [0]*n

for i in range(q):
    p,x = map(int,input().split()) 
    ans[p-1] += x

def dfs(i = 0, r = -1):
    for j in e[i]:
        if j != r:
            ans[j] += ans[i]
            dfs(j, i)

dfs()

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

s = input()
t = input()

def Z(S):
    A = [0]*len(S)
    i = 1; j = 0
    A[0] = len(S)
    while i < len(S):
        while i+j < len(S) and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while len(S)-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

z = Z(t+'?'+s*(len(t)//len(s) + 2))
z = z[len(t)+1:]

g = [-1]*len(s)
c = [0]*len(s)

for i in range(len(s)):
    if z[i] == len(t):
        g[i] = (i+len(t))%len(s)

for i in range(len(s)):
    if c[i] > 0 or g[i] < 0:
        continue
    q = g[i]
    tmp = 0
    while q >= 0:
        tmp += 1

        if c[q] > 0:
            c[i] = tmp + c[q]
            break
        
        if tmp != 0 and q == i:
            print(-1)
            exit()
        
        q = g[q]

    c[i] = max(c[i],tmp)

print(max(c))

### FIXED CODE ###

s = input()
t = input()

def Z(S):
    A = [0]*len(S)
    i = 1; j = 0
    A[0] = len(S)
    while i < len(S):
        while i+j < len(S) and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while len(S)-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

z = Z(t+'?'+s*(len(t)//len(s)+2))
z = z[len(t)+1:]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 

        elif(self.rank[x] > self.rank[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y

            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def card(self, x):
        return -self.root[self.find(x)]

u = UnionFind(len(s))

for i in range(len(s)):
    if z[i] == len(t):
        if u.same(i,(i+len(t))%len(s)):
            print(-1)
            exit()
        u.unite(i,(i+len(t))%len(s))


print(-1+max(map(lambda x:-x,u.root)))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
l=len(A)
x=[]
for i in range(l):
    m=A.index(min(A))
    x.append(m+1)
    A[m]=10**5+1
x=[str(a) for a in x]
L=' '.join(x)
print(L)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
L=[0]*N
for i in range(N):
    L[A[i]-1]=i+1
L=[str(a) for a in L]
print(' '.join(L))
### BUGGY CODE ###

#coding:utf-8
#import numpy as np
def argsort_p1(ls):
    return [sorted(ls).index(t)+1 for t in ls]

N,M = list(map(int,input().split()))
P = []
Y = []

for m in range(M):
    p,y = list(map(int,input().split()))
    P.append(p)
    Y.append(y)
#print (P,Y)
ls = [ [] for _ in range(max(P))]
temp = [ [] for _ in range(max(P))]
ls_idx = []
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
    ls_idx.append(len(temp[p-1]))
    temp[p-1].append(len(temp[p-1]))
#print (ls_idx)
#ls_dict = []
# ls_arg_line = []
# for line in ls:
#
#     ls_arg_line.append(argsort_p1(line))
ls_arg_line = [argsort_p1(line) for line in ls]
for i,(p,y) in enumerate(zip(P,Y)):
    #print (i,p,y)
    print (str(p).zfill(6)+str(ls_arg_line[p-1][ls_idx[i]]).zfill(6))


### FIXED CODE ###

N, M = map(int,input().split())
ls = []
for m in range(M):
    p, y = map(int,input().split())
    ls.append([p,y])
sorted_ls = sorted(ls,key=lambda x:x[1])
counter = [0 for i in range(N+1)]
d = {}
for p,y in sorted_ls:
    counter[p]+=1
    num = counter[p]
    d[y] = num
for p,y in ls:
    #print (p,d[y])
    print (str(p).zfill(6)+str(d[y]).zfill(6))
### BUGGY CODE ###

from itertools import permutations 
n,m=map(int,input().split())
cost=[]
for i in range(m):
    cost.append([int(i) for i in input().split()])
clr=[]
for i in range(n):
    clr.append([int(i) for i in input().split()])
l=[i for i in range(m)]
ind=[[] for i in range(4)]
for i in range(n):
    for j in range(n):
        curr=(i+1+j+1)%3 
        ind[curr].append(clr[i][j]-1)
mini=10**9 
for i in permutations(l,3): 
    curr=0 
    for j in range(3):
        for x in ind[j]: 
            curr+=cost[x][i[j]]
    mini=min(mini,curr)
print(mini)


### FIXED CODE ###

from itertools import permutations 
n,m=map(int,input().split())
cost=[]
for i in range(m):
    cost.append([int(i) for i in input().split()])
clr=[]
for i in range(n):
    clr.append([int(i) for i in input().split()])
l=[i for i in range(m)]
ind=[[0 for j in range(m)] for i in range(4)]
for i in range(n):
    for j in range(n):
        curr=(i+1+j+1)%3 
        ind[curr][clr[i][j]-1]+=1 
mini=10**9 
for i in range(m):
    for j in range(m):
        for k in range(m):
            if i==j or i==k or j==k:
                continue 
            curr=0 
            for it in range(3): 
                for it1 in range(m): 
                    if it==0:
                        k1=i 
                    elif it==1:
                        k1=j 
                    else:
                        k1=k 
                    curr+=ind[it][it1]*cost[it1][k1] 
            mini=min(mini,curr)
print(mini)
### BUGGY CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
# sort_A = sorted(A)

C = collections.Counter(A)

for a in A:
    s = 0
    for c in C:
        if c == a:
            s += (C[c] - 1) * (C[c] - 2) // 2
        else:
            s += C[c] * (C[c] - 1) // 2
    print(s)


### FIXED CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
# sort_A = sorted(A)

C = collections.Counter(A)

s_all = 0
for c in C:
    s_all += C[c] * (C[c] - 1) // 2

for a in A:
    s = 0
    s += s_all - (C[a] - 1)
    print(s)
### BUGGY CODE ###

N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    elif S[i] == 'B':
        B.append(i)
ans = 0
for i in R:
    for j in G:
        for k in B:
            if i < j < k and j-i != k-j:
                ans += 1
for i in R:
    for j in B:
        for k in G:
            if i < j < k and j-i != k-j:
                ans += 1
for i in G:
    for j in R:
        for k in B:
            if i < j < k and j-i != k-j:
                ans += 1
for i in G:
    for j in B:
        for k in R:
            if i < j < k and j-i != k-j:
                ans += 1
for i in B:
    for j in G:
        for k in R:
            if i < j < k and j-i != k-j:
                ans += 1
for i in B:
    for j in R:
        for k in G:
            if i < j < k and j-i != k-j:
                ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    elif S[i] == 'B':
        B.append(i)
ans = len(R)*len(G)*len(B)
for i in range(1,(N+1)//2):
    for j in range(i,N-i):
        if S[j] != S[j-i] and S[j] != S[j+i] and S[j-i] != S[j+i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、再帰、重みなし) """

    cnt = [0] * N
    def rec(u, prev):
        cnt[u] = len(nodes[u])
        res = []
        for v in nodes[u]:
            if v != prev:
                res.append(rec(v, u) + 1)
        S = set()
        for x in res:
            while x in S:
                x += 1
            S.add(x)
        if S:
            return max(S)
        else:
            return 0

    return rec(src, -1)

N = INT()
nodes = [[] for i in range(N)]
for a in range(1, N):
    b = INT()
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

print(dfs(N, nodes, 0))


### FIXED CODE ###

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def get_sum(a, b, c):
    """ 等差数列の和：(初項a, 末項b, 項数c) """
    return (a+b) * c // 2

def dfs(N, nodes, src):
    """ DFS(木、再帰、重みなし) """

    def rec(u, prev):
        C = Counter()
        for v in nodes[u]:
            if v != prev:
                C[rec(v, u) + 1] += 1
        if not C:
            return 0
        C = sorted(C.items(), reverse=1)
        mx = C[0][0]
        add = C[0][1] - 1
        vacant = 0
        for i, (k, v) in enumerate(C[1:], 1):
            k2, _ = C[i-1]
            vacant += k2 - k - 1
            vacant -= v - 1
            if vacant < 0:
                add += abs(vacant)
                vacant = 0
        return mx + add

    return rec(src, -1)

N = INT()
nodes = [[] for i in range(N)]
for a in range(1, N):
    b = INT()
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

print(dfs(N, nodes, 0))
### BUGGY CODE ###

n= int(input())
s = input()
ans = set()
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      tmp = s[i]+s[j]+s[k]
      ans.add(tmp)
print(len(ans))

### FIXED CODE ###

n= int(input())
s = input()
ans = 0
h = set()
for i in range(n-2):
  ten = set()
  if s[i] not in h:
    h.add(s[i])
    for j in range(i+1,n-1):
      if s[j] not in ten:
        ten.add(s[j])
        ans += len(set(s[j+1:]))
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

red = 0
r,g,b = 0,0,0
for i in range(N):
  if(S[i] == 'R'): 
    r += 1
    # i     j    j+(j-i) : R  G  B  (or)  R  B  G (or) ... である場合 ans -= 1   
    for j in range(i+1,N-1):
     i1,i2,i3 = i,j,j+(j-i)
     if(i3 <= N-1):
       tmp = S[i1]+S[i2]+S[i3]
       if((tmp == 'RBG')or(tmp == 'RGB')):
         red += 1

  elif(S[i] == 'G'): 
     g += 1
     # i     j    j+(j-i) : R  G  B  (or)  R  B  G (or) ... である場合 ans -= 1   
     for j in range(i+1,N-1):
       i1,i2,i3 = i,j,j+(j-i)
       if(i3 <= N-1):
         tmp = S[i1]+S[i2]+S[i3]
         if((tmp == 'GBR')or(tmp == 'GRB')):
           red += 1
        
  elif(S[i] == 'B'): 
    b += 1 
    for j in range(i+1,N-1):
     i1,i2,i3 = i,j,j+(j-i)
     if(i3 <= N-1):
       tmp = S[i1]+S[i2]+S[i3]
       if((tmp == 'BGR')or(tmp == 'BRG')):
         red += 1
        
ans = r*g*b - red
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

ans = 0
r,g,b = 0,0,0
for i in range(N):
  if(S[i] == 'R'): r += 1
  elif(S[i] == 'G'): g += 1  
  elif(S[i] == 'B'): b += 1 
  
  # i     j    j+(j-i) : R  G  B  (or)  R  B  G (or) ... である場合 ans -= 1   
  for j in range(i+1,N-1):
     i1,i2,i3 = i,j,j+(j-i)
     if(i3 <= N-1):
       tmp = [S[i1],S[i2],S[i3]]
       tmp.sort()
       tmp = tmp[0]+tmp[1]+tmp[2]
       if(tmp == 'BGR'):
         ans -= 1

ans += r*g*b
print(ans)
### BUGGY CODE ###

n=int(input())
s = []
max = 0

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

for i in range(n):
    if max < s.count(str(s[i])):
        max = s.count(str(s[i]))
        s2 = []
        s2.append(s[i])
    elif max == s.count(str(s[i])):
        s2.append(s[i])

s2.sort()

for i in range(len(s2)):
    if i == 0:
        print(s2[i])
    elif s2[i] != s2[i-1]:
        print(s2[i])

### FIXED CODE ###

import collections

n=int(input())
s = []
max = 0

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

c = collections.Counter(s)

for i in c.items():
    if i[1] > max:
        max = i[1]

s2 = [i[0] for i in c.items() if i[1] == max]

s2.sort()

for j in range(len(s2)):
    print(s2[j])
### BUGGY CODE ###

K,S = (int(x) for x in input().split())

count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if(i + j + k) == S:
                count += 1
print(count)

### FIXED CODE ###

K,S = (int(x) for x in input().split())

count = 0
for x in range(K+1):
    for y in range(K+1):
            if  0 <= S - (x + y) <= K:
                count += 1
print(count)
### BUGGY CODE ###

n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]

t = 0
s = [0 for _ in range(len(a)+1)]
for i in range(len(a)):
    s[i+1] = a[i] + t
    t += a[i]

counter = 0
for i in range(1, len(s)+1):
    for j in range(n-i+1):
        if (s[j+i] - s[j]) % m == 0:
            counter += 1

print(counter)


### FIXED CODE ###

def main():
    n, m = [int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]

    ans = 0
    d = {}

    cumsum = [0]
    c_sum = 0
    for a in A:
        c_sum = (c_sum + a) % m
        cumsum.append(c_sum)

    for c in cumsum:
        if c not in d.keys():
            d[c] = 0
        d[c] += 1

    for v in d.values():
        if v >= 2:
            ans += v * (v - 1) // 2

    print(ans)


main()
### BUGGY CODE ###

import copy

H, W = map(int, input().split())
A = []
black = []
for i in range(H):
    A.append(list(input()))
    for j in range(W):
        if A[i][j] == '#':
            black.append([i,j])

counter = len(black)
dist = 0
while True:
    if counter == W * H:
        break
    dist += 1
    next_black = []
    for b in black:
        cur_black = black + next_black
        if b[0] != 0 and [b[0] - 1, b[1]] not in cur_black:
            next_black.append([b[0] - 1, b[1]])
            counter += 1
        if b[1] != 0 and [b[0], b[1] - 1] not in cur_black:
            next_black.append([b[0], b[1] - 1])
            counter += 1
        if b[0] != H - 1 and [b[0] + 1, b[1]] not in cur_black:
            next_black.append([b[0] + 1, b[1]])
            counter += 1
        if b[1] != W - 1 and [b[0], b[1] + 1] not in cur_black:
            next_black.append([b[0], b[1] + 1])
            counter += 1            
    black += next_black
print(dist)

### FIXED CODE ###

H, W = map(int, input().split())
INF = H * W
A = [input() for x in range(H)]
used = [[False] * W for x in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append([i, j])
            used[i][j] = True

max_dist = 0
counter = 0
depth = -1
while counter != INF:
    # print(q)
    # print(counter)
    for i in range(len(q) - counter):
        item = q[counter]

        if item[0] > 0 and not used[item[0]-1][item[1]]:
            q.append([item[0] - 1, item[1]])
            used[item[0] - 1][item[1]] = True
        if item[1] > 0 and not used[item[0]][item[1] - 1]:
            q.append([item[0], item[1] - 1])
            used[item[0]][item[1] - 1] = True
        if item[0] < H - 1 and not used[item[0] + 1][item[1]]:
            q.append([item[0] + 1, item[1]])
            used[item[0] + 1][item[1]] = True
        if item[1] < W - 1 and not used[item[0]][item[1] + 1]:
            q.append([item[0], item[1] + 1])
            used[item[0]][item[1] + 1] = True
        counter += 1
    depth += 1

print(depth)
### BUGGY CODE ###

#!/usr/bin/env python3
import itertools
import random

def is_prime(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

A =[0] * 10**5
for i in range(10**5):
    if i%2 == 1:
        if is_prime(i) == True and is_prime((i+1)//2) == True:
            A[i] = 1
B = list(itertools.accumulate(A))
B = [0] + B

Q = int(input())
for i in range(Q):
    a, b = map(int,input().split())
    print(B[b+1]-B[a])

### FIXED CODE ###

from itertools import accumulate
# エラトステネスの篩
# is_prime := 1~nが素数か否か
# table := 2~nのうち素数
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


Q = int(input())
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

max_R = max(R)
is_prime, table = sieve(max_R)

check = [0]*(max_R + 1)
for i in range(0, max_R + 1):
    if (i % 2 == 1):
        if (is_prime[i-1] and is_prime[(i+1)//2-1]):
            check[i] = 1

# 累積和
check = [0] + check
check = list(accumulate(check))

for i in range(Q):
    print(check[R[i] + 1] - check[L[i]])
### BUGGY CODE ###

n=int(input())
sl=list([input() for i in range(n)])
def sort_str(s):
    cl = list(s)
    cl.sort()
    return ''.join(cl)
sum=0
al=['']*n
for i in range(n):
    al[i] = sort_str(sl[i])
    for j in range(i+1,n):
        if al[j]=='':
            al[j] = sort_str(sl[j])
        if al[i]==al[j]:
            sum+=1
print(sum)

### FIXED CODE ###

n=int(input())
sl=list([input() for i in range(n)])
def sort_str(s):
    cl = list(s)
    cl.sort()
    return ''.join(cl)
m={}
sum=0
for i in range(n):
    s = sort_str(sl[i])
    if not s in m:
        m[s]=0
    else:
        m[s]+=1
        sum+=m[s]
print(sum)
### BUGGY CODE ###

N = int(input())
A, B = [], []
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
count = 0
for i in range(N-1, -1, -1):
    A[i] += count
    while True:
        if A[i] % B[i] == 0:
            break
        else:
            count += 1
            A[i] += 1
print(count)

### FIXED CODE ###

N = int(input())
A, B = [], []
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
count = 0
for i in range(N-1, -1, -1):
    if (A[i] + count) % B[i] == 0:
        continue
    count += (B[i] - ((A[i] + count) % B[i]))
print(count)
### BUGGY CODE ###

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

from operator import mul, xor
from functools import reduce

def grow(arr):
    return reduce(mul, arr)

res = grow(A)
print(res) if res <= 10 ** 18 else print(-1)

### FIXED CODE ###

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

if 0 in A:
    print(0)
    exit()

dp = [1] * (n + 1)
for i in range(n):
    dp[i + 1] = dp[i] * A[i]
    if dp[i + 1] > 10 ** 18:
        print(-1)
        exit()

print(dp[n])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
a_i = a[-1]
a_i_2 = a_i / 2.0
b = a[0]
max0 = 0

for i in a:
    if i < a_i_2:
        b = i
    elif i != a_i:
        c = i
        break
    else:
        c = b
        break
from scipy.misc import comb
if comb(a_i, b) > comb(a_i,c):
    max0 = comb(a_i, b)
    a_j = b
else:
    max0 = comb(a_i, c)
    a_j = c

for i in range(1,n-1): 
    b_i = a[i]
    b_i_2 = b_i / 2.0
    b = a[0]
    for i in a:
        if i < b_i_2:
            b = i
        elif i != b_i:
            c = i
            break
        else:
            c = b
            break
    if comb(a_i, b) > comb(a_i,c): 
        max1 = comb(b_i, b)
        b_j = b
    else:
        max1 = comb(b_i, c)
        b_j = c
    if max1 > max0:
        max0 = max1
        a_i = b_i
        a_j = b_j
print("{} {}".format(a_i, a_j))

### FIXED CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)