Problem:
 Score : 400 points    Problem Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n , select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.      Constraints  2 \leq n \leq 10^5  0 \leq a_i \leq 10^9  a_1,a_2,...,a_n are pairwise distinct.  All values in input are integers.         Input Input is given from Standard Input in the following format:  n  a_1  a_2  ...  a_n       Output Print a_i and a_j that you selected, with a space in between.        Sample Input 1 5
6 9 4 2 11      Sample Output 1 11 6  \rm{comb}(a_i,a_j) for each possible selection is as follows:   \rm{comb}(4,2)=6   \rm{comb}(6,2)=15   \rm{comb}(6,4)=15   \rm{comb}(9,2)=36   \rm{comb}(9,4)=126   \rm{comb}(9,6)=84   \rm{comb}(11,2)=55   \rm{comb}(11,4)=330   \rm{comb}(11,6)=462   \rm{comb}(11,9)=55   Thus, we should print 11 and 6 .       Sample Input 2 2
100 0      Sample Output 2 100 0

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

A.sort()

n = A.pop()

MIN = (INF,INF)
for a in A:
  if MIN[0] > (abs(n/2-a)):
    MIN = (abs(n/2-a),a)
  
print(n,MIN[1])

Solution (Python):
import bisect

n,*a = map(int, open(0).read().split())
if n == 2:
    print(*a)
else:
    a.sort()
    f = a[-1]
    h = f / 2
    bs = bisect.bisect_left(a,h)
    if abs(a[bs-1]-h) >= abs(a[bs]-h):
        s = a[bs]
    else:
        s = a[bs-1]
    print(f,s)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort()

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N-1)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    aj = A.pop()
    A.sort(key=lambda x: abs(aj / 2 - x))
    print(aj, A[0]) 
main()

Solution (Python):
_, *a = map(int, open(0).read().split())
n = max(a)
print(n, min((abs(n/2 - i), i) for i in a)[1])

Solution (Python):
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
s2 = abs(k2-a)

if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
n = max(a)
tmp = n / 2
r = n + 1
d = n + 1
for num in a:
    if num == n:
        continue
    d_tmp = abs(num - tmp)
    if d_tmp < d:
        d = d_tmp
        r = num
print(n, r)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    def combinations_count(n, r):
        if n > 1:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        else:
            return 0

    n = ni()
    a = na()

    a.sort()

    max_ai = max(a)
    idx = bisect.bisect_left(a, max_ai // 2)

    r = -1

    r = a[max(0, idx - 1)]
    if a[idx] != max_ai:
        r = a[idx] if abs(a[idx] - max_ai / 2) < abs(r - max_ai / 2) else r

    print(max_ai, r)


if __name__ == '__main__':
    main()

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

A.sort()

m = A[-1]
M = [abs((m / 2) - a) for a in A[: -1]]
r = A[M.index(min(M))]

print(m, r)

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

A.sort()

m = A[-1]
M = [abs((m / 2) - a) for a in A[: -1]]
r = A[M.index(min(M))]

print(m, r)

Solution (Python):
import sys
import bisect
n = int(input())
A = list(map(int,input().split()))
A.sort()
m = A[-1]
if n == 2:
    print(A[-1],A[0])
    sys.exit()
i = bisect.bisect_left(A,m//2)
if i == 0:
    print(m,A[0])
else:
    if m - A[i] < A[i-1]:
        print(m,A[i-1])
    else:
        print(m,A[i])

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *





































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()
	A = inputList()
	A.sort()
	AA = A[::-1]

	ans1 = AA[0]
	ans2 = AA[-1]
	ki = ans1 / 2

	for i in AA:
		if i == ans1:
			continue
		if abs(i-ki) < abs(ans2-ki):
			ans2 = i

	print("{} {}".format(ans1,ans2))






def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok





def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None




def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)




def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y




def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv



def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)



if __name__ == "__main__":
	main()

Solution (Python):
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b/2 - a[c]) < abs(b/2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Solution (Python):
import bisect
n = int(input())
lis = list(map(int, input().split()))
lis.sort()

mid = (lis[-1] + 1) // 2
p = bisect.bisect_left(lis, mid)
x = abs(lis[p] - mid)
y = abs(lis[p-1] - mid)

if x >= y:
    print(lis[-1], lis[p-1])
else:
    print(lis[-1], lis[p])

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L.sort()
    a = L[-1]
    b = -1
    min_diff_between_half_a = inf
    for elm in L:
        if min_diff_between_half_a > abs(elm - a/2):
            min_diff_between_half_a = abs(elm - a/2)
            b = elm
    print("{} {}".format(a, b))

if __name__ == "__main__":
    main()

Solution (Python):
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

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


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)

Solution (Python):
from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] / 2
i = bisect_left(a_list, base)
if i > 0:
    i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
    temp = abs(a_list[i] - base)
    if temp >= ans[2]:
        break
    ans[1] = a_list[i]
    ans[2] = temp
print(ans[0], ans[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

a.sort()
mx = a[-1]

half = mx / 2
dist = abs(half - a[0])
ans = 0
for i in range(1,n):
    if dist > abs(half - a[i]):
        dist = min(dist,abs(half - a[i]))
        ans = a[i]
print(mx,ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

m=max(a)
r=0
for i in range(n):
    if abs(m/2-a[i])<abs(m/2-r):
        r=a[i]

print(m,r)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

base = max(a)
tmp = 10**9
tmp_i = 0
for x in a:
    if x == base:
        pass
    elif abs(base - 2*x) < tmp:
        tmp = abs(base - 2*x)
        tmp_i = x

print(base, tmp_i)

Solution (Python):

import sys
input = sys.stdin.readline









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


maxA = max(A)
half = maxA/2

t = 10**10
for i in range(N):
    
    if A[i] != maxA and abs(A[i]-half) < abs(t-half):
        t = A[i]

print(maxA,t)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
ma = max(li)
li.remove(ma)
diff = []
for l in li:

    diff.append(abs(ma/2-l))
mi = min(diff)
ind = diff.index(mi)
print(ma,li[ind])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()

m = a[-1]
res = m
temp = 0
for i in range(n):
    if res > abs(m - 2*a[i]):
        res = abs(m - 2*a[i])
        temp = a[i]

print(m, temp)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
v=sorted(lis)
u=sorted(lis)[-1]
dis=[]
if u%2==0:
    k=u//2
    for i in range(n-1):
        dis.append(abs(v[i]-k))
    l=sorted(dis)[0]
    for i in range(n-1):
        if dis[i]==l:
            print(u,v[i])
            sys.exit()
else:
    k=(u-1)//2
    m=(u+1)//2
    for i in range(n-1):
        dis.append(abs(v[i]-k))
        dis.append(abs(v[i]-m))
    l=sorted(dis)[0]
    
    for i in range(len(dis)):
        if l==dis[i]:
            print(u,v[i//2])
            sys.exit()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    max_a = A[-1]
    A = A[:-1]
    A.sort(key=lambda a: abs(a - max_a / 2))
    print('{} {}'.format(max_a, A[0]))


if __name__ == '__main__':
    main()

Solution (Python):
n = input()
a = [int(A) for A in input().split()]

max_ele = 0
for i in range(len(a)):
    if a[i] > max_ele:
        max_ele = a[i]

mid = 0
mid_val = max_ele / 2

for j in range(len(a)):
    if abs(mid_val - a[j]) < abs(mid_val - mid):
        mid = a[j]

print(str(max_ele) + " " + str(mid))

Solution (Python):
n = int(input())
A = [int(a) for a in input().split()]

max_val = max(A)
mid_val = max_val - max_val//2



m = 0
for a in A:
    
    
    if abs(a - mid_val) < abs(m - mid_val):
        m = a
    

print("{} {}".format(max_val, m))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a = sorted(a)
ans = 0
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
print(m, ans)

Solution (Python):
import sys
import bisect

readline = sys.stdin.readline

def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    if len(a) == 2:
        a.sort(reverse=True)
        print(*a)
        return
    amax = a.pop()
    mid = amax//2
    mididx = bisect.bisect_left(a, mid)
    am1 = a[mididx]; am2 = a[mididx-1]
    if abs(am1-mid) <= abs(am2-mid):
        am = am1
    else:
        am = am2
    print(amax, am)


if __name__ == "__main__":
    main()

Solution (Python):
import math
n = int(input())
a = list(map(int,input().split()))

a = sorted(a, reverse = True)
mid = a[0]//2
diff = abs(mid - a[0])

if n == 2:
    print(max(a[0],a[1]),min(a[0],a[1]))
else:
    for i in range(n):
        if abs(a[i] - mid) < diff:
            diff = abs(a[i] - mid)
            ans = i
    print(a[0], a[ans])

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

if N > 2:
    A.sort()
    num_total = A[-1]
    A.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    
    def meguru_search(l,key): 
        left = -1
        right = len(l)

        while (right - left) > 1: 
            mid = left + (right - left)//2
            if isOK(mid,key,l):
                right = mid
            else:
                left = mid
        
        return right
    
    if num_total%2 == 0:
        Max = num_total//2 
    else:
        Max = num_total//2 + 1
    
    Maxind1 = meguru_search(A,Max) 
    Maxind2 = Maxind1 - 1 
    abs_1 = abs(Max - A[Maxind1])
    abs_2 = abs(Max - A[Maxind2])
    if abs_1 > abs_2: 
        r = A[Maxind2]
    else:
        r = A[Maxind1]
    print(num_total,r)

else:
    print(max(A),min(A))

Solution (Python):
n = int(input())
a_ls = list(map(int, input().split()))
if n > 2:
    a_ls.sort()
    num_total = a_ls[-1]
    a_ls.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    def meguru_search(l, key):
        '''
        key以上の値を持つ最小のインデックスを返す
        '''
        left = -1
        right = len(l)

        while (right - left) > 1:
            mid = left + (right - left) // 2
            
                
                    
                
            if isOK(mid, key, l):
                right = mid
            else:
                left = mid
        
        
        return right

    if num_total % 2 == 0:
        Max = num_total // 2
    else:
        Max = num_total // 2 + 1
    Maxind1 = meguru_search(a_ls, Max)
    Maxind2 = Maxind1 - 1
    abs_1 = abs(Max - a_ls[Maxind1])
    abs_2 = abs(Max - a_ls[Maxind2])
    if abs_1 > abs_2:
        r = a_ls[Maxind2]
    else:
        r = a_ls[Maxind1]
    print(num_total, r)
else:
    print(max(a_ls), min(a_ls))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
an = max(a)
mi = -1
ms = 10**10
an2 = an/2
for i in a:
    if ms > abs(i-an2) and not an == i:
        mi = i
        ms = abs(i-an2)

print(an,mi)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
c = a[0]
ch = -(-a[0]//2)
minD = 10**9
x = -1
for i in range(n):
    dif = abs(a[i]-ch)
    if minD>=dif:
        minD=dif
        x = a[i]
print(c,x)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    valind=A.index(val)
    minabs=10**18
    for i in range(n):
        if i==valind: continue
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
 
m = max(a)
a = sorted(a)
 
ans = 0
 
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
 
print(m, ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
 
m = max(a)
a = sorted(a)
 
ans = 0
 
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
 
print(m, ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a.pop()
r = m/2

def isOK(index, key):
    return a[index] >= key

def bsearch(key):
    left = -1
    right = n-1

    while right-left > 1:
        mid = left+(right-left)//2
        if isOK(mid, key):
            right = mid
        else:
            left = mid

    if right == n-1:
        return -1
    else:
        return right

index = bsearch(r)

if index > 0 and 2*r < a[index-1]+a[index]:
    index -= 1

print(m, a[index])

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()
A.sort()

max = max(A)
index = bisect_left(A, max / 2)
if abs((max / 2) - A[index]) < abs((max / 2) - A[index - 1]):
    ans = [max, A[index]]
else:
    ans = [max, A[index - 1]]
print(*ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ma = max(a)
a.sort(key=lambda x:abs(x-ma/2))
r = a[0] if a[0]!=ma else a[1]
print(ma, r)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
r = -1
for i in a:
  if i != m and abs(m - 2 * i) < abs(m - 2 * r):
    r = i
print(m, r)

Solution (Python):
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = max(A)
    A = A[:-1]
    target = MAX / 2
    idx = bisect_left(A, target)

    if idx == 0:
        print(MAX, A[0])
    elif idx == N - 1:
        print(MAX, A[-1])
    else:
        if abs(target - A[idx]) < abs(target - A[idx - 1]):
            print(MAX, A[idx])
        else:
            print(MAX, A[idx - 1])


if __name__ == "__main__":
    main()

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

max_a = max(a)
diff = inf
ans = 0
for i in range(n):
    if a[i] != max_a:
        d = abs(a[i] - max_a // 2)
        if diff > d:
            diff = d
            ans = a[i]

print(max_a, ans)

Solution (Python):
from operator import mul
from functools import reduce
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))

big_num = A[-1]
near_mid_pointer = bisect.bisect_left(A, big_num / 2)
dif1 = 10**9 + 1
if near_mid_pointer != 0:
        dif1 = big_num / 2 - A[near_mid_pointer - 1]
dif2 = A[near_mid_pointer] - big_num / 2
if dif1 <= dif2:
    num1 = big_num
    num2 = A[near_mid_pointer - 1]

else:
    num1 = big_num
    num2 = A[near_mid_pointer]

print(num1, num2)

Solution (Python):
import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
ama = A[-1]
print(ama, end=' ')
ama2 = (ama + 1)//2
w = bisect.bisect_left(A, ama2)

a = A[w-1]
b = A[w]
if abs(a-ama2) > abs(b-ama2):
    print(b)
else:
    print(a)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
a.sort(key=lambda x: abs(ai//2 - x))
aj = a[0]
for i in a:
    if ai==i: continue
    else:
        aj = i
        break

print('{} {}'.format(ai, aj))

Solution (Python):
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a = sorted(a)
  a_i = a[-1]
  a_j = 0
  dist = a_i
  for i in range(len(a)-1):
    if abs(a_i/2-a[i]) < dist:
      a_j = a[i]
      dist = abs(a_i/2-a[i])
  print(a_i, a_j)

if __name__ == "__main__":
  main()

Solution (Python):
import sys

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

if n==2:
    print(A[1],A[0])
    sys.exit()

p=A[-1]
h=p/2
for i in range(n-1):
    if A[i]>=h:
        break
if abs(A[i-1]-h)<=abs(A[i]-h):
    q=A[i-1]
else:
    q=A[i]
print(p,q)

Solution (Python):
import bisect
def main():
    N = int(input())
    A = sorted([int(_) for _ in input().split()])
    r = A[-1]//2
    B = A[:-1]
    x = bisect.bisect_left(B, r)
    if x == 0:
        return A[-1], B[x]
    elif x == N-1:
        return A[-1], B[x-1]
    else:
        if abs(B[x]-r) <= abs(B[x-1]-r): return A[-1], B[x]
        else: return A[-1], B[x-1]
if __name__ == '__main__':
    print(*main())

Solution (Python):

import sys


def solve(n: int, a: "List[int]"):
    b = sorted(a)
    n = b[-1]
    c = [(min(bb, n-bb), bb) for bb in b[:-1]]
    return n, max(c)[1]



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(n)]  
    print(*solve(n, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = min(a)

for i in a:
    if min(aj, ai -aj) < min(i, ai - i):
        aj = i
    
print(ai, aj)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

m = max(a)
a = sorted(a)

ans = 0

for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i

print(m, ans)

Solution (Python):
def pow(x, n , mod):
    res = 1
    while n > 0:
        if  bin(n & 1) == bin(1) :
            res = res * x % mod
        x = x*x % mod
        n = n >>1
    return res   

def combination(n,a):
    x = 1
    for i in range(a):
        x = x * (n-i) % mod
    y = 1
    for i in range(a):
        y = y * (a-i) % mod
    y = pow(y, mod-2, mod)
    return (x*y % mod)

n = int(input())
a = list(map(int, input().split()))
mod =1

m = max(a)
a = sorted(a)

ans = 0

for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i

print(m, ans)

Solution (Python):
dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    t = a[0] // 2
    p = a[-1]
    if n == 2:
        print("%d %d" % (a[0], a[1]))
        return
    i = 1
    while a[i] > t:
        i += 1
        if i >= n:
            i -= 1
            break
    if abs(a[i - 1] - t) > abs(a[i] - t):
        p = a[i]
    else:
        p = a[i - 1]
    print("%d %d" % (a[0], p))


def main1():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
for i in a[:-1]:
    if abs(ai/2-i) < abs(ai/2-aj):
        aj = i
print(ai, aj)