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):
n = int(input())
list_a = list(map(int, input().split()))
max_a = max(list_a)

max_k = max_a / 2
min_diff = [-1, max_a]
for i, one_a in enumerate(list_a):
  if one_a != max_a:
    temp_diff = abs(one_a - max_k)
    if temp_diff < min_diff[1]:
      min_diff = [i, temp_diff]

print("{} {}".format(max_a, list_a[min_diff[0]]))

Solution (Python):

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

candidates = [(a[i], min(a[-1] - a[i], a[i])) for i in range(n-1)]
candidates.sort(key=lambda x: x[1])


print(a[-1], candidates[-1][0])

Solution (Python):
n = int(input())
a = list(int(x) for x in input().split())
a.sort()

a_i = a[-1]

key_small, key_large = 0, n-1
border = a_i//2
while key_small < key_large-1:
    key = (key_small+key_large)//2
    if a[key] <= border:
        key_small = key
    else:
        key_large = key

p, q = a[key_small], a[key_large]

judge = a_i / 2
if abs(p-judge) < abs(q-judge):
    a_j = p
else:
    a_j = q
if a_i == a_j:
    a_j = 0
print(a_i, a_j)

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

a.sort()
x = a[-1]
b = [(min(e, x - e), e) for e in a[:-1]]
b.sort()
print(x, b[-1][1])

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

a.sort()
maxa = a.pop(-1)

import bisect
if maxa % 2 == 0:
    i = bisect.bisect_right(a,maxa//2)
    if a[i-1] == maxa//2:
        print(maxa, maxa//2)
    else:
        if i == 0:
            print(maxa, a[0])
        elif i == len(a):
            print(maxa, a[-1])
        else:
            if abs(a[i-1] - maxa//2) < abs(a[i] - maxa//2):
                print(maxa,a[i-1])
            else:
                print(maxa,a[i])
else:
    i = bisect.bisect_right(a,maxa//2)
    if a[i] == maxa//2 + 1:
        print(maxa, a[i])
    elif a[i-1] == maxa//2:
        print(maxa, a[i-1])
    else:
        if i == 0:
            print(maxa,a[0])
        elif i == len(a):
            print(maxa,a[-1])
        else:
            if abs(a[i-1] - maxa//2) < abs(a[i] - maxa//2 + 1):
                print(maxa, a[i-1])
            else:
                print(maxa, a[i])

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



m = max(a)
a.sort()
a.pop()



dif = 10**9
ans = 0
for num in a:
  d = min(abs(m//2 - num),abs(m//2 + num - m))
  if dif > d:
    dif = d
    ans = num
print(m,ans)

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

A.sort()
num=float('inf')
for i in range(n-1):
  if abs(num-A[-1]/2)>abs(A[i]-A[-1]/2):
    num=A[i]
print(A[-1],num)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
n=max(a)
a.remove(n)
ans=float("inf")
for i in range(N-1):
  if abs(ans-n/2)>abs(a[i]-n/2):
    ans=a[i]
print(n,ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
flag = n-2
for i in range(n-1):
  if 2*a[i] > a[n-1]:
    if a[i]-a[n-1]/2 > a[n-1]/2 - a[i-1]:
      flag = i-1
    else:
      flag = i
    break

print(a[n-1],a[flag])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
m = max(a)
del a[a.index(m)]
dis = [abs(m/2 - a[i]) for i in range(n-1)]
r = a[dis.index(min(dis))]
print(m,r)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
dis = [abs(a[-1]/2 - a[i]) for i in range(n-1)]
r = a[dis.index(min(dis))]
print(a[-1],r)

Solution (Python):

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

a.sort()

max_a = a[-1]

now = 10**18

half_a = max_a * 0.5
num = 0

for i in range(n):
    tmp = abs(half_a - a[i])
    if now > tmp:
        now = tmp
        num = a[i]

print(max_a,num)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
if len(a)==2:
  print(*a[::-1])
else:
  m=a[n-1]
  a=a[:n-1]
  h=m/2
  import bisect as bi
  x=bi.bisect_left(a,h)
  print(m,a[x-(a[x]-h>h-a[x-1])])

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    A.sort()
    A_max = A[-1]
    B = min(A,key=lambda x:abs(x-A_max/2))
    print(A_max, B)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ma = max(A)
cur = ma
mid = 0
A.pop()
for a in A:
    if abs(a-(ma/2)) < cur:
        mid = a
        cur = abs(a-(ma/2))
print(ma, mid)

Solution (Python):
N = int(input())
A = sorted([int(a) for a in input().split()])
X = A[-1]
Y = 0
mi = 1<<99
for i in range(N-1):
    if abs(X - A[i]*2) < mi:
        mi = X - A[i]*2
        Y = A[i]

print(X, Y)

Solution (Python):
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
maxa = a[-1]
m = maxa / 2
d = bisect.bisect_left(a, m)
if a[d] == maxa:
  print(maxa, a[-2])
elif d == 0:
  print(maxa, a[0])
else:
  if abs(a[d] - m) <= abs(a[d-1] - m):
    print(maxa, a[d])
  else:
    print(maxa, a[d-1])

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

X = A[-1]
key = bisect.bisect_left(A,A[-1] // 2)
if key + 1 == N:
  Y = key - 1
elif key - 1 == -1:
  Y = key + 1
else:
  if (A[-1] / 2) - A[key-1]  <= A[key] - (A[-1] / 2):
    Y = A[key-1]
  else:
    Y = A[key]
print(X,Y)

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

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2

ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(bi))

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    x=a[n-1]
    m=x
    y=0
    for i in range(n-1):
        if abs(a[i]-x//2) < m:
            m=abs(a[i]-x/2)
            y=a[i]
    print(x,y)

    
if __name__ == "__main__":
    main()

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

n = a[-1]
d = n/2
r = n

dist = n
for i in a:
    s = abs(i-d)
    if s < dist:
        dist = s
        r = i

print(n,r)

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

l=bisect.bisect_left(A,A[-1]/2)

if l==n:
    print(A[-1],A[-2])
else:
    if abs(A[-1]/2-A[l])>=abs(A[-1]/2-A[l-1]):
        print(A[-1],A[l-1])
    else:
        print(A[-1],A[l])

Solution (Python):
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
a.sort()
half=float(a[-1])/2
len=float("inf")
ans=a[0]
for i in range(n-1):
    if len>abs(half-a[i]):
        ans=a[i]
        len=abs(half-a[i])
print(a[-1])
print(ans)

Solution (Python):
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)

if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
    print(maxA,A[idx-1])
  else:
    print(maxA,A[idx])

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(0)
    exit()
m=max(l)
ans=0 
denomaxi=0 
for  i in l: 
    if i*(m-i)>denomaxi:
        ans=i 
        denomaxi=i*(m-i)
print(m,ans)

Solution (Python):
import bisect
n = int(input())
a = list(map(int,input().split()))
if n == 2:
  print(a[0],a[1])
  exit()
a.sort()
m = a.pop()
index = bisect.bisect_right(a,m//2)
if m % 2 == 0:
  if a[index] == m//2:
    print(m,a[index])
  else:
    if m//2-a[index-1] < a[index]-m//2:
      print(m,a[index-1])
    else:
      print(m,a[index])
else:
  if m//2-a[index-1] < a[index]-m//2-1:
    print(m,a[index-1])
  else:
    print(m,a[index])

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

ai=a[-1]
am=sorted(map(lambda x:min(x,ai-x),a))
aj=am[-1]

if aj in a:
  print(ai,aj)
else:
  print(ai,ai-aj)

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

if N == 2:
	print(A[0], A[1])
else:
	q = max(A)
	B = list(map(lambda x : abs(q // 2 - x),  A))
	print(q, A[B.index(min(B))])

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
halfA = maxA // 2
tmp = 10 ** 9
r = 0
for a in A:
    if a == maxA:
        continue
    half = abs(halfA - a)
    if tmp > half:
        tmp = half
        r = a

print(maxA, r)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=max(a)
d=0
ans=0
for i in range(n):
    if d<min(b-a[i],a[i]):
        d=min(b-a[i],a[i])
        ans=a[i]
print(str(b)+" "+str(ans))

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

alist.sort()
an = alist[-1]
alist = alist[:-1]

front = 0
back = 0
a_pre = alist[0]
for a in alist:
    if a > an / 2:
        front = a_pre
        back = a
        break
    else:
        a_pre = a

if front >= an - back:
    print("{:d} {:d}".format(an, front))
else:
    print("{:d} {:d}".format(an, back))

Solution (Python):
import bisect

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

a.sort()
ai = a.pop()
i = bisect.bisect_left(a, ai / 2)
if i == 0:
    aj = a[0]
elif i == n - 1:
    aj = a[n - 2]
else:
    aj = a[i - 1] if ai / 2 - a[i - 1] <= a[i] - ai / 2 else a[i]

print(ai, aj)

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

m = lst[-1]
line = m / 2
r = 10**10

for i in range(n):
    if abs(r-line) > abs(lst[i]-line):
        r = lst[i]
print(m,r)

Solution (Python):


import math
import bisect
import numpy as np

n = int(input().split()[0])
a_list = list(map(int, input().split()))


def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


a_list = sorted(a_list)
max_comb = -float("inf")
a_list = sorted(a_list, reverse=True)
ai = a_list[0]
w_list = a_list[1:]
w_list = sorted(w_list)


if ai % 2 == 0:
    idx = np.abs(np.asarray(w_list) - ai // 2).argmin()
    aj = w_list[idx]
else:
    t_1 = (ai - 1) // 2
    idx_1 = np.abs(np.asarray(w_list) - t_1).argmin()
    aj_1 = w_list[idx_1]

    t_2 = (ai + 1) // 2
    idx_2 = np.abs(np.asarray(w_list) - t_2).argmin()
    aj_2 = w_list[idx_2]

    if abs(t_1 - aj_1) < abs(t_2 - aj_2):
        aj = aj_1
    else:
        aj = aj_2

ans = "{} {}".format(ai, aj)
print(ans)

Solution (Python):
import sys


def slove():
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    mt = 0
    ans = 0
    for i in range(n):
        t = min(a[i], a[-1]-a[i])
        if mt < t:
            ans = a[i]
            mt = t
    print(a[-1], ans)


if __name__ == '__main__':
    slove()

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

Solution (Python):
n = int(input())
k = [int(i) for i in input().split()]
ans1 = max(k)
k.remove(ans1)
c = ans1
ans2 = 0
for i in k:
  if abs(i-ans1/2) <= c:
    ans2 = i
    c = abs(i-ans1/2)
print(ans1,ans2)

Solution (Python):
import sys
from bisect import bisect_left
input = sys.stdin.readline


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ai = a[-1]
    j = bisect_left(a, ai//2)
    aj = a[j]
    tmp = a[j-1]
    if aj == ai:
        aj = tmp
    elif ai // 2 - tmp < aj - ai // 2:
        aj = tmp
    print(ai, aj)


if __name__ == '__main__': main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
n_ = max(a)
r = a[0] if a[0] != n else a[1]
cur = r * (n - r)
for i in a:
    if i != n_:
        x = i * (n_ - i)
        if x > cur:
            r, cur = i, x
print(n_, r)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
A = max(a)
B = A / 2
a.sort()

for i, v in enumerate(a):
  if v >= B:
    idx = i
    break
    

if abs(B - a[idx]) < abs(B - a[idx - 1]):
  print(A, a[idx])
else:
  print(A, a[idx - 1])

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

if n == 2:
    print(a[1], a[0])
elif abs(a[-1] / 2 - a[bisect_left(a, a[-1] / 2)]) < abs(a[-1] / 2 - a[bisect_left(a, a[-1] / 2) - 1]):
    print(a[-1], a[bisect_left(a, a[-1] / 2)])
else:
    print(a[-1], a[bisect_left(a, a[-1] / 2) - 1])

Solution (Python):
from bisect import bisect_left

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

A.sort()
for i in reversed(range(N)):
    a = A[i]
    ia = bisect_left(A, a/2)
    a1, a2 = A[ia-1], A[ia]
    if a2 == a:
        b = a1
    elif min(a1, a-a1) > min(a2, a-a2):
        b = a1
    else:
        b = a2
    break
    
print(a, b)

Solution (Python):
import math
def com(x, y):
    k = math.factorial(x)
    s = math.factorial(y)
    l = math.factorial(x - y)
    return k // (s * l)
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[-1]
target = max / 2
min = a[0]
for i in range(n - 1):
    if abs(a[i] - target) < abs(min - target):
        min = a[i]
print("{} {}".format(max, min))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
x = max(a)
r = 0
num = x//2
diff = float("inf")
for i in range(n):
    dif = abs(num - a[i])
    if dif < diff and a[i] != x:
        diff = dif
        r = a[i]
print(x, r)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ans1 = max(A)
ans2 = 0
minid = 10**9+1
for a in A:
    if abs(ans1/2-a) <= minid:
        minid = abs(ans1/2-a)
        ans2 = a
print(ans1, ans2)

Solution (Python):
n=int(input())
a=tuple(map(int,input().split()))
M=max(a)
b,m=0,M
for i in a:
    if m>abs(M/2-i) and M!=i:
        b,m=i,abs(M/2-i)
print(M,b)

Solution (Python):

import math

N = int(input()) 
a_list = list(int(e) for e in input().split())
a_tuple = tuple(a_list)

comb_n = max(a_tuple)

a_list.remove(comb_n)
diff = min([abs(comb_n/2 - a) for a in a_list])
a_tuple = tuple(a_list)
if int(comb_n/2 + diff) in a_tuple:
    comb_r = comb_n/2 + diff
elif int(comb_n/2 - diff) in a_tuple:
    comb_r = comb_n/2 - diff  
    
print(int(comb_n),int(comb_r))

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
ans1 = max(a)
a.remove(ans1)
b = sorted(a, reverse=True)
ans2 = b[0]
for i in range(N - 2):
    if abs((ans1 / 2) - b[i]) > abs((ans1 / 2) - b[i+1]):
        ans2 = b[i + 1]
    else:
        break


print(ans1, ans2)

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

A=sorted(A)
maxA=max(A)
limit=maxA/2
tmp=10**9
for i in range(N):
    if(abs(limit-A[i])<tmp):
        tmp=abs(limit-A[i])
        comb=A[i]
    else:
        break

print(maxA,comb)

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

A=sorted(A)
maxA=max(A)
limit=maxA/2
tmp=10**9
for i in range(N):
    if(abs(limit-A[i])<tmp):
        tmp=abs(limit-A[i])
        comb=A[i]
    else:
        break

print(maxA,comb)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    c = 0
    for i in range(n):
        if c < min(a[i], abs(a[-1] - a[i])):
            c = a[i]
    print(a[-1], c)


if __name__ == '__main__':
    slove()

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

a.sort()
output = 0
tmp = a[-1] // 2 if a[-1] % 2 == 0 else a[-1] // 2 + 1

for i in a[0:n:]:
    if abs(tmp - i) < abs(tmp - output):
        output = i

print(a[-1], output)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = a[-1]
ans =min(a,key=lambda x:abs(max_a-x*2))
print(max_a,ans)

Solution (Python):
import bisect
n=int(input())
a=[int(i) for i in input().split()]
a.sort()

maxi=a[-1]
midi=-(-maxi//2)
idx=bisect.bisect_left(a,midi)

ans=-1
check=float('inf')
for i in range(-1,2):
    if 0<=(idx+i)<n-1:
        check2=abs(midi-a[idx+i])
        if check >check2:
            ans=a[idx+i]
            check=check2
    
print(maxi,ans)

Solution (Python):
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    m = a[-1] / 2
    i = bisect(a, m)
    d0 = m - a[i - 1]
    d1 = a[i] - m
    if d0 < d1 or i == n - 1:
        print(a[-1], a[i - 1])
    else:
        print(a[-1], a[i])

main()

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

ans1 = A[-1]
ans2 = -1
if(A[-1]%2 == 1): tmp1,tmp2 = A[-1]//2,A[-1]//2 + 1
else: tmp1,tmp2 = A[-1]//2,A[-1]//2
min_dif = float('inf')

for i in range(n):
 if(min_dif > abs(A[i]-tmp1)):
  min_dif = abs(A[i]-tmp1)
  ans2 = A[i]
 if(min_dif > abs(A[i]-tmp2)):
  min_dif = abs(A[i]-tmp2)
  ans2 = A[i]   
  
print(ans1,ans2)

Solution (Python):
from math import factorial
n = int(input())
a = list(map(int,input().split()))
a.sort()
ave = a[-1]/2
nearest_ave = min(a, key=lambda x:abs(x-ave))
print(a[-1], nearest_ave)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
a1 = a.pop(0)

if a[0] <= a1 / 2:
    res = a[0]
elif a[-1] >= a1 / 2:
    res = a[-1]
else:
    left = 0
    right = n-2
    while True:
        j = (left + right) // 2
        if left == right:
            res = a[left]
            break
        elif a1/2 >= a[j+1] and a1/2 <= a[j]:
            if abs(a[j+1]-a1/2) >= abs(a[j]-a1/2):
                res = a[j]
            else:
                res = a[j+1]
            break
        elif a1/2 > a[j]:
            right = j
        else:
            left = j

print(a1, res)

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    m = max(a)
    a.remove(m)
    m2 = min(a, key=lambda x: abs(x - m / 2))
    print(m, m2)


if __name__ == "__main__":
    resolve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[10**10]
a.sort(reverse=True)
c=a[0]
e=c//2
for i in range(1,n):
    b.append(abs(a[i]-e))
d=a[b.index(min(b))]
print(c,d)

Solution (Python):
import bisect
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)
if n==2:
    cur = [A[1],A[0]]
else:
    a = A[-1]
    ind = bisect.bisect_right(A,a//2)
    b = a-A[ind]
    c = A[ind-1]
    if c>=b:
        cur = [a,c]
    else:
        cur = [a,a-b]
print(cur[0],cur[1])

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

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr = sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

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

seta = sorted(list(set(a)))

resn = max(seta)
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

Solution (Python):
n = int(input())
a_list = sorted(list(map(int, input().split())))
 
a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None
 
nobori = True
 
tmp = a_list[0]
koeta = None
for j_index in range(n):
    if a_list[j_index] * 2 > a_i:
        koeta = j_index
        break
    else:
        tmp = j_index
 
comb2 = 0
if n == 2:
    print(*[a_list[1], a_list[0]])
elif koeta == 0:
    print(*[a_i, a_list[koeta]])
elif (a_list[koeta]- a_i/2) > (a_i/2 - a_list[koeta-1]):
    print(*[a_i,a_list[koeta-1]])
else:
    print(*[a_i, a_list[koeta]])

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

if n%2==0:
    c=a[-1]//2
else:
    c=a[-1]//2+0.5

b=[]
for i in range(n):
    b.append(abs(c-a[i]))

c=min(b)
for i in range(n):
    if b[i]==c:
        print(a[-1],a[i])
        break

Solution (Python):

from math import factorial
import bisect


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    
    
    
    """
    C(n,r) を毎回計算するのは計算が重い。なので計算させずに済む方法を考える。
    C(n,r) = n! / r!(n-r)! である。今、nはAsの最大値と決まっているので、定数とみなして良い。
    よって、C(n,r)が大きいとは、分子の r!(n-r)!ができるだけ小さいものである。
    r!(n-r)!を全探索で計算するのも処理が重いのでしたくない。
    ところで、n=10のとき、r!(n-r)!を、r = 1 ~ 10まで手書きで書いてみるとわかるが、

    1) 1* 9*8*7*6*5*4*3*2*1
    2) 1*2* 8*7*6*5*4*3*2*1
    3) 1*2*3* 7*6*5*4*3*2*1
    4) 1*2*3*4* 6*5*4*3*2*1
    5) 1*2*3*4*5* 5*4*3*2*1  <-これが一番小さい
    6) 1*2*3*4*5*6* 4*3*2*1  <-これは4)と同じ

    r = n//2のときが一番小さくなるっぽいことがわかる。

    そのようなrを、Asの中から探せば良い。これは二分探索で高速に探せる。
    """

    As.sort()
    n = As[-1]
    i = bisect.bisect_left(As[:-1], n//2)
    if i == 0:
        r = As[0]
    elif i == N-1:
        r = As[N-2]
    else:
        if abs(As[i-1] - n//2) < abs(As[i] - n//2):
            r = As[i-1]
        else:
            r = As[i]

    print(n, r)


if __name__ == "__main__":
    solve()

Solution (Python):
n=int(input())
box=sorted(list(map(int,input().split())))
right=box.pop()
point=right//2

ans=0
left=10**9
for i in box:
    if abs(i-point)<=left:
        left=abs(i-point)
        ans=i
        if ans==point or ans==point+1:
            print(right,ans)
            exit()
print(right,ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
ans=[max(A)]

k=ans[0]
n=-1
for i in range(N):
    if abs(A[i]-ans[0]/2) < k and A[i] != ans[0]:
        k=abs(A[i]-ans[0]/2)
        n=i
ans.append(A[n])
        
print(*ans)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
a.remove(max(a))
y=x/2
b=10**10
d=10**10

for i in range(n-1):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)

Solution (Python):
n = int(input())
an = list(map(int, input().split()))
if n == 2:
  print(' '.join( map(str, [max(an), min(an)]) ))
  exit()

maxi = max(an)
v = maxi
for a in an:
  if a == maxi:
    continue
  if abs(a-maxi/2) < abs(v-maxi/2):
    v = a
print(' '.join( map(str, [maxi, v]) ))

Solution (Python):
from bisect import bisect_left

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

def combination(n, r): 
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp


j = bisect_left(a, a[-1]//2)

tmp = abs(a[j]/a[-1] - 1/2)
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp >= abs(a[j - 1]/a[-1] - 1/2):
        ans2 = a[j - 1]

print (ans1, ans2)

Solution (Python):
from bisect import bisect_left

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

def combination(n, r): 
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp


j = bisect_left(a, a[-1]//2)

tmp = abs(a[j]/a[-1] - 1/2)
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp >= abs(a[j - 1]/a[-1] - 1/2):
        ans2 = a[j - 1]

print (ans1, ans2)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
mi = max(A)
an = 10000000000000
b = 0
for i in range(N):
  if an>abs(mi//2-(mi-A[i])) and A[i]!=mi:
    an = abs(mi//2-(mi-A[i]))
    b = A[i]
print(mi,b)

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
listuse=sorted(lis)
maximum=max(listuse)
if maximum%2==0:
    index=0
    for i in range(n-1):
        if abs(listuse[i]-maximum/2)>abs(listuse[i+1]-maximum/2):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    print(*anslist)
if maximum%2!=0:
    
    index=0
    for i in range(n-1):
        if min(abs(listuse[i]-((maximum+1)/2)),abs(listuse[i]-(maximum-1)/2))>min(abs(listuse[i+1]-((maximum+1)/2)),abs(listuse[i+1]-(maximum-1)/2)):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    
    print(*anslist)

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

A.sort()


n = A[-1]

standard = n/2
dif = 1e+9
r = 1e+9  
for i in range(N-1):
    if abs(A[i] - standard) < dif:
        r = A[i]
        dif = abs(A[i] - standard)

print(n, r)

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

a.sort()
M1, M2 = 0, 0
for i in range(n) :
    m = min(a[i], a[-1] - a[i])
    if m > M2 :
        M1, M2 = a[i], m
    
print(a[-1], M1)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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

left = max(A)
center = left // 2

right = 0
diff = INF
for i in range(N):
    if A[i] == left:
        continue

    x = abs(center-A[i])
    if diff > x:
        diff = x
        right = A[i]

print(left, right)

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

big = -float('inf')
number = 0

for a in A:
    big = max(big, a)


ans = -float('inf')
ans_num = 0
for a in A:
    if a == big:
        continue
    number = min(a, big - a)
    if ans < number:
        ans = number
        ans_num = a
print(big, ans_num)

Solution (Python):
n = int(input())
import heapq
A = list(map(int, input().split()))
a = max(A)
b = a//2
C = []
for i in range(n):
  heapq.heappush(C, abs(A[i]-b))
c = heapq.heappop(C)
print(a)
if c+b != a and A.count(c+b) == 1:
  print(c+b)
else:
  print(b-c)

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

x = max(A)

num = x/2
for i in range(n):
    A[i] = [abs(A[i]-num), A[i]]
    
A.sort()
y = A[0][1]

print(x, y)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
ma = a.pop()
mi = -1
dif = mod
for i in range(n-1):
    if abs(ma/2-a[i]) < dif:
        mi = i
        dif = abs(ma/2-a[i])
print(ma,a[mi])

Solution (Python):

import sys
from math import factorial

def comb(n: int, r: int):
    return factorial(n) // (factorial(r)*factorial(n-r))

def solve(n: int, a: "List[int]"):
    a.sort()

    m = a[-1]
    print(m, min(a, key=lambda x:abs(m/2-x)))
    
    return



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)]  
    solve(n, a)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]


def comb(n: int, r: int):
    
    return factorial(n) // (factorial(r)*factorial(n-r))




def solve(n: int, a: "List[int]"):
    a.sort()

    m = a[-1]
    print(m, min(a, key=lambda x:abs(m/2-x)))
    
    return



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)]  
    solve(n, a)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]


def comb(n: int, r: int):
    
    return factorial(n) // (factorial(r)*factorial(n-r))




def solve(n: int, a: "List[int]"):
    a.sort()

    m = a[-1]
    print(m, min(a, key=lambda x:abs(m-x*2)))
    
    return



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)]  
    solve(n, a)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ai = max(A)
A.pop(A.index(ai))
dif = list(map(lambda a:abs(ai/2-a),A))
print(ai,A[dif.index(min(dif))])

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = max(data)
ans2 = 0
sa = 10**9
for i in data:
    if (abs((ans1//2)-i) < sa) and (i < ans1):
        ans2 = i
        sa = abs((ans1//2)-i)
print(ans1,ans2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
A_ = []
A_ = A[:]
A_max = max(A)

A = [abs(float(x) - float(A_max/2)) for x in A]


ans = 10**10
idx = 0
for i in range(len(A)):
    t = A[i]
    if t <= ans:
        ans = t
        idx = i

print(A_max,A_[idx])