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

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)


import bisect




INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    
    A = sorted(A)
    
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    elif idx == n-1:
        print(f'{A[-1]} {A[-2]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1] / 2) > abs(val2 - A[-1] / 2):
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Solution (Python):
N=int(input())
*A,=map(int,input().split())
A.sort()
M=A[-1]
A=[-10**9]+A+[10**11]
from bisect import*
P=bisect_right(A,M/2)
if abs(A[P-1]-M/2)>abs(A[P]-M/2):
    m=A[P]
else:
    m=A[P-1]
print(M,m)

Solution (Python):
import bisect

n = int(input())
A = [int(_) for _ in input().split()]

A.sort()
x = A[-1]
y = bisect.bisect(A, x / 2)

if abs(A[y] - x / 2) < abs(A[y-1] - x / 2):
    print(x, A[y])
else:
    print(x, A[y-1])

Solution (Python):
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
x = a[-1]
N = a[-1]//2

a = a[:-1]
y = bisect.bisect_left(a,N)
if len(a) <= y: ans = a[y-1]
else:
    ans = a[y]
    if 0 < y and abs(N-ans) > abs(N-a[y-1]): ans = a[y-1]
    if y < len(a)-1 and abs(N-ans) > abs(N-a[y+1]): ans = a[y+1]
print(x,ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(10**12)
MAX = A[N-1]
ans = N
for i in range(N):
    if abs(A[i] - MAX/2) < abs(A[ans] - MAX/2):
        ans = i
print(MAX,A[ans])

Solution (Python):
n = int(input())
A = sorted(list(map(int,input().split())))
for i in range(n):
    if A[i]*2>A[-1]:
        ind = i
        break
ind -= 1
a = A[ind]
b = A[-1]-A[ind+1]
if a>=b:
    print(A[-1],a)
else:
    print(A[-1],A[ind+1])

Solution (Python):
import bisect
n = int(input())
A = list(map(int,input().split()))
A.sort()
if n == 2:
  ans = [A[1],A[0]]
  print(*ans)
  exit()
MAX = A[-1]
target = MAX//2
ok = 0
ng = n
while abs(ok-ng)>1:
  mid = (ok+ng)//2
  if A[mid] <= target:
    ok = mid
  else:
    ng = mid
ans = [MAX,A[ok]]

nxt = ok+1

if nxt < n:
  dif0 = min(MAX-A[ok],A[ok])
  dif1 = min(MAX-A[nxt],A[nxt])
  if dif0 < dif1:
    ans[1] = A[nxt]
print(*ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


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



n = a_int()
A = ints()
if len(A) == 2:
    A.sort()
    exit(*A[::-1])
ma = max(A)
ans = -1
d = 10**10
for a in A:
    if abs(a - ma / 2) < d:
        d = abs(a - ma / 2)
        ans = a


print(ma, ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A[-1]

d = n
r = -1
for a in A[:-1]:
    if n%2==0:
        t = abs(a - n//2)
        if t < d:
            d = t
            r = a
    else:
        t = min(abs(a - n//2), abs(a - (n//2+1)))
        if t < d:
            d = t
            r = a
print(n,r)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()
M = As.pop()

diff = 10**18
for a in As:
    if abs(M/2-a)<diff:
        diff = abs(M/2-a)
        ans = a

print(M, ans)

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
l = [ai for ai in a[:-1]]
l.sort(key=lambda x: abs(a[-1]/2-x))
print(a[-1], l[0])

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

i = A.pop()
j = None
best = float('inf')

for a in A:
    v = abs(a - i / 2)
    if v < best:
        best = v
        j = a

print(i, j)

Solution (Python):






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





a.sort()
ai = max(a)
diff = ai
old = diff
for x in a[:-1]:
    tmp = abs(x-ai/2)
    if tmp <= diff:
        aj = x
        diff = tmp
    if diff == old:
        break
    else:
        old = diff
print(ai,aj)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
a.remove(ma)
num = 0
ind = 0
a.sort()
for i in range(N-1):
    if a[i] < ma//2:
        ind += 1

if ind == 0:
    print(ma,a[0])
    exit()
elif ind == N-1:
    print(ma,a[-1])
    exit()

if abs(ma//2 - a[ind-1]) < abs(ma//2 - a[ind]):
    print(ma,a[ind-1])
else:
    print(ma,a[ind])

Solution (Python):
import bisect

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

A.sort()


n = A[-1]



mid = bisect.bisect(A, n/2)


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

Solution (Python):
import bisect

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

A.sort()
n = A[-1]
mid = bisect.bisect(A, n/2)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
s=a[-1]/2
b=[[i,abs(i-s)] for i in a]
b.sort(key=lambda z:z[1])
print(a[-1],b[0][0])

Solution (Python):
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
m=a[-1]
for i in a:
  if m>abs(i-x/2):
    y=i
    m=abs(i-x/2)
print(x,y)

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

ai, aj = a[-1], a[-2]
for i in a[:-1]:
    if abs(ai - 2 * aj) > abs(ai - 2 * i):
        aj = i
print(ai, aj)

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

ai, aj = a[-1], a[-2]
for i in a[:-1]:
    aj = (i if abs(ai - 2 * aj) > abs(ai - 2 * i) else aj)
print(ai, aj)

Solution (Python):
n = int(input())
aa = list(sorted(map(int, input().split())))
x = max(aa)
y = aa[0]
for i in range(1, n - 1):
    if abs(x / 2 - y) > abs(x / 2 - aa[i]):
        y = aa[i]
print("{} {}".format(x, y))

Solution (Python):
from bisect import bisect_left, bisect_right
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
n = a[-1]
mid = a[-1] // 2
i = bisect_left(a[:-1], mid)

if i >= len(a) - 1:
    r = a[i - 1]
elif i == 0 or a[i] == mid:
    r = a[i]
elif a[i] - mid <= mid - a[i - 1]:
    r = a[i]
else:
    r = a[i - 1]

print(n, r)

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

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Solution (Python):
def solve():
  N = int(input())
  A = [-float('inf')]+list(map(int, input().split()))
  A.sort()
  ans = [A[-1]]
  n = A[-1]//2
  for i in range(1,N+1):
    if A[i]>n or i==N-1:
      if A[i]-n>n-A[i-1]:
        ans.append(A[i-1])
      else:
        ans.append(A[i])
      break
  return ans
print(*solve())

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort(reverse=True)

i = lst1[0]
lst1 = lst1[1:]

res = i/2
res2 = -1
minimum = 10**18
for j in lst1:
    if abs(j-res) < minimum:
        res2 = j
        minimum = abs(j-res)

print(i,res2)

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

if N == 2:
  print(*(max(A),min(A)))
  exit()
  
m = max(A)/2
nearest=-1
for i in range(N):
  if abs(A[i]-m)<abs(nearest-m):
    nearest = A[i]

print(*(max(A),nearest))

Solution (Python):
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

_ = input()
an = list(map(int,input().split()))

an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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 power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort()
nn = a[-1]
ind = bisect.bisect_left(a,nn//2)
kouho1 = -inf
if ind > 0:
    kouho1 = a[ind-1]
kouho2 = a[ind]
if abs(nn/2 - kouho1) <= abs(nn/2 - kouho2):
    print(nn, kouho1)
else:
    print(nn, kouho2)

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

l.sort()
ans1 = l[-1]
ans2 = -1
diff = 1000000000
for i in range(n-1):
    if diff >= abs(l[i] - ans1//2):
        ans2 = l[i]
        diff = abs(l[i] - ans1//2)
print(ans1, ans2)

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

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

if n == 2:
    am = a[-1]
    amm = a[0]
else:
    am = max(a)
    ind = bisect.bisect_left(a,am//2)
    am1 = a[ind]
    am2 = a[ind-1]

    am1abs = abs(am/2-am1)
    am2abs = abs(am/2-am2)

    if am1abs <= am2abs:
        amm = am1
    else:
        amm = am2
    
print(am,amm)

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]
i = bisect.bisect_left(A, m/2)
if i == 0:
  print(m, A[0])
  exit()
if i == N-1:
  print(m, A[-2])
  exit()
a, b = A[i-1], A[i]
if abs(a*2-m) > abs(b*2-m):
  print(m, b)
else:
  print(m, a)

Solution (Python):
import bisect

def main():
    n=int(input())
    a=sorted(map(int,input().split()))
    if len(a) < 3:
        print(a[1], a[0])
        return
    N = a[-1]
    a = a[:-1]
    r = bisect.bisect(a, N/2)
    if r == 0:
        R = a[0]
    if r == len(a):
        R = a[r-1]
    else:
        R = a[r] if abs(a[r-1] - N/2) > abs(a[r] - N/2) else a[r-1]
    print(N, R)
        
if __name__ == "__main__":
    main()

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

num = a[0]
tmp = a[1]
for j in range(1, n):
  if abs(tmp-num/2) >= abs(a[j]-num/2):
    tmp = a[j]
  else:
    break
ans = [num, tmp]
print(*ans)

Solution (Python):
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-1]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()

from bisect import bisect_right
maxA = As[-1]
idx = bisect_right(As, maxA/2)

if abs(As[idx]-(maxA/2))>=abs(As[idx-1]-(maxA/2)):
    print(maxA, As[idx-1])
else:
    print(maxA, As[idx])

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
MaxA = max(A)
A = sorted(A,key=lambda x: abs(MaxA/2-x))
if A[0] == MaxA:
  print(MaxA,A[1])
else:
  print(MaxA,A[0])

Solution (Python):
import numpy as np

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

a.sort()


def get_nearest_value(arr, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(arr) - num).argmin()

    return arr[idx]


first = a[-1]
second = get_nearest_value(a, first / 2)

print(first, second)

Solution (Python):
def main():
    import sys

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

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    mdl = a[0]//2
    if a[0]%2 == 0:
        dist = [abs(x-mdl) for x in a[1:]]
    else:
        dist = [abs(x-mdl) if x <= mdl else abs(x - mdl - 1) for x in a[1:]]
    idx = min(range(1,n), key=lambda i: dist[i-1])
    print(a[0], a[idx])
    
        
    
    
if __name__ == '__main__':
    main()

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

t2 = a[0]
x = a[0]//2
ans = 1
for i in range(1,n):
  t = abs(x - a[i])
  if t < t2:
    t2 = t
    ans = i
print(a[0],a[ans])

Solution (Python):
n, *A = map(int, open(0).read().split())
A.sort()
print(A[-1], min(A, key=lambda x:abs(2*x-A[-1])))

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

x = max(a)
m = x/2
a.remove(x)
a.sort()
ans = x

for i in a:
    y = abs(i - m)
    if ans >= y:
        ans = y
    else:
        break    
    z = i
      
print(x, z)

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

h=a[0]/2
dif=10**18
tmp=None
for i in range(1,n):
    if dif>abs(a[i]-h):
        dif=abs(a[i]-h)
        tmp=a[i]
print(a[0],tmp)

Solution (Python):
import bisect
n = int(input())
aas = list(map(int, input().split()))
aas.sort()
l = aas[-1]
a = l // 2
b = l // 2 + 1
idx_a = bisect.bisect_left(aas,a)
idx_b = bisect.bisect_left(aas,a)
res = []
if aas[idx_a] != l:
    res.append(idx_a)
if aas[idx_b] != l:
    res.append(idx_b)
if idx_a > 0:
    if aas[idx_a-1] != l:
        res.append(idx_a-1)
if idx_b > 0:
    if aas[idx_b-1] != l:
        res.append(idx_b-1)
if idx_a < n - 1:
    if aas[idx_a+1] != l:
        res.append(idx_a+1)
if idx_b < n - 1:
    if aas[idx_b+1] != l:
        res.append(idx_b+1)
best = l // 2
res_f = n - 1
for i in set(res):
    if abs(best-aas[i]) <= abs(best-aas[res_f]):
        res_f = i
    if l%2 != 0:
        if abs(best+1 - aas[i]) <= abs(best+1 - aas[res_f]):
            res_f = i
print(str(l)+" "+str(aas[res_f]))

Solution (Python):
N = int(input())

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

a_max = max(a)

half_a = a_max//2

comb = 1000000000
for i in range(N):
    if a[i]==a_max:
        continue
    if comb>abs(half_a-a[i]):
        idx =i
        comb = abs(half_a-a[i])

print(str(a_max) + ' ' + str(a[idx]))

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

a.sort()
k = a[n-1]
r = a[0]
dis = abs(a[n-1]/2-a[0])
for i in range(n-1):
    if dis > abs(a[n-1]/2-a[i]):
        dis = abs(a[n-1]/2-a[i])
        r = a[i]
print(k,r)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    x = a[-1]
    y = a[0]
    t = x
    d = float('inf')
    for e in a:
        if abs(t - (x - e) * 2) < d:
            y = e
            d = abs(t - (x - e) * 2)
    print(x, y)
        

t = 1

for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = [str((m := A.pop())), ]
    m /= 2
    A = [(a, abs(a - m)) for a in A]
    A.sort(key = lambda x: x[1])
    ans.append(str(A[0][0]))
    print(' '.join(ans))

if __name__ == '__main__':
    main()

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

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
for i in range(N - 1):
    if A[i] == min_:
        ans = B[i]
print(n, ans)

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

import math
import bisect
max = L[-1]
maxdiv2 = max//2
posleft = bisect.bisect_left(L, maxdiv2)
posright = bisect.bisect_right(L, maxdiv2)

if len(L) == 2:
	print(L[1], L[0])
	exit()

if posleft!= posright:
	print(max, L[posleft])
	exit()

if abs(max/2 - L[posleft]) > abs(max/2 - L[posleft-1]):
	print(max, L[posleft-1])
else:
	print(max, L[posleft])

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

x = max(A)
A = list(filter(lambda a: a != x, A))
med = x / 2

num = INF
y = 0
for a in A:
    if abs(med - a) < num:
        num = abs(med - a)
        y = a
print(x, y)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = LI()

"""
nCr = n!/(r! * (n-r)!)
なのでnは最大値をとりつつrはnの中間の値を撮るのが良さそう．
"""

a.sort()
o = a[-1]
diff = mod
for i in range(n):
    if diff > abs(a[i] - o / 2):
        p = a[i]
        diff = abs(a[i] - o / 2)
print(o,p)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
num1=a[-1]
num2=a[-1]/2
num3=a[-1]
ans=-1
for i in range(n-1):
    if abs(a[i]-num2)<num3:
        ans=a[i]
        num3=abs(a[i]-num2)
print(num1,ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')





from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A = sorted(A)

    a = A[-1]
    mid = a / 2
    diff = INF
    b = -1
    for j in A[:-1]:
        d = abs(j - mid)
        if d < diff:
            b = j
            diff = d
    print(a, b)



if __name__ == '__main__':
    solve()

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

a.sort()
m = a[-1]
br = m/2
tmp = m
for i in range(n):
    if tmp > abs(a[i]-br):
        r = a[i]
        tmp = abs(a[i]-br)

print(m,r)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    MAX_V = A[-1]
    target = MAX_V // 2 if MAX_V % 2 == 0 else (MAX_V + 1) // 2

    diff = f_inf
    res = A[0]
    for i in range(n - 1):
        if abs(target - A[i]) < diff:
            diff = abs(target - A[i])
            res = A[i]
    print(MAX_V, res)


if __name__ == '__main__':
    resolve()

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

als =list(sorted(al))
m = als[n-1]

import bisect
x = bisect.bisect(als,m/2)

if abs(m/2 - als[x-1]) > abs(m/2 - als[x]):
    print(m,als[x])
else:
    print(m,als[x-1])

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

import bisect
import numpy as np
amax = a[-1]
cent = amax // 2

idx = bisect.bisect_left(a, cent)
if idx == len(a)-1:
    print(amax, a[-2])
else:
    max_idx = np.argmin([abs(a[idx]-cent), abs(a[idx-1]-cent)])
    if max_idx:
        print(amax, a[idx-1])
    else:
        print(amax, a[idx])

Solution (Python):
n=int(input())
lst=sorted(map(int,input().split()))
m=lst[-1]/2
anslst=[]
for i in range(n-1):
    anslst.append([abs(m-lst[i]),lst[i]])
anslst.sort()
print(int(m*2),anslst[0][1])

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
L=sorted(list(set(L)))
M=L[-1]
K=M//2+M%2
S=[abs(i-K) for i in L]
print(M,L[S.index(min(S))])

Solution (Python):
from bisect import bisect
n=int(input())
lst=sorted(map(int,input().split()))
m=lst[-1]
index=bisect(lst,m/2)
if m!=lst[index]:
    q=lst[index]
    if 0<=index-1:
        p=lst[index-1]
        if abs(m/2-p)>=abs(m/2-q):
            print(m,q)
        else:
            print(m,p)
    else:
        print(m,q)
else:
    print(m,lst[index-1])

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
amax = max(A)
AA = sorted(A,key=lambda x: abs(amax/2-x))
if AA[0] == amax:
    print(amax,AA[1])
else:
    print(amax,AA[0])

Solution (Python):
def d_binomial_coefficients():
    N = int(input())
    A = sorted([int(i) for i in input().split()])  

    n = A[-1]  
    r = min(A[:-1], key=lambda x: abs(n / 2 - x))
    return f'{n} {r}'

print(d_binomial_coefficients())

Solution (Python):
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Solution (Python):
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

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

n = A.pop()
m = getNearestValue(A, n/2)
print(n, m)

Solution (Python):
n, *a = map(int, open(0).read().split())
a.sort(reverse=True)
max_a = a[0]
min_diff = float('inf')
for v in a[1:]:
    if abs(max_a/2 - v) <= min_diff:
        ans = v
        min_diff = abs(max_a/2 - v)
print(max_a, ans)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
ai=a[-1]
aa=ai/2
ans=float("inf")
for i in range(n-1):
    tmp=abs(a[i]-aa)
    if tmp<ans:
        ans=tmp
        aj=a[i]
print(ai,aj)

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())
i = bisect_left(a[:-1], a[-1]/2)
if abs( a[-1]/2 - a[max(0,i-1)] ) <= abs( a[i] - a[-1]/2 ):
    print(a[-1], a[max(0,i-1)])
else:
    print(a[-1], a[i])

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

tmp = a[0]//2
s = 10**18
num = 0
for i in range(1, n):
    if(abs(tmp-a[i]) < s):
        s = abs(tmp-a[i])
        num = a[i]

print(a[0], num)

Solution (Python):
from bisect import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
mid = ai / 2
i = bisect(a, mid) - 1
j = i + 1
if j == n - 1:
    j = i
if abs(a[i] - mid) < abs(a[j] - mid):
    aj = a[i]
else:
    aj = a[j]
print(ai, aj)

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A[1:]:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)

Solution (Python):
from bisect import bisect_left

n = int(input())
A = list(int(x) for x in input().split())
m = max(A)
A.remove(m)
A.sort()
index = bisect_left(A, m//2)
tmp = 10**18
ans = -1
for a in A[index-1:index+2]:
    if abs(a - m/2) < tmp:
        tmp = abs(a - m/2)
        ans = a
print(m, ans)

Solution (Python):
from bisect import bisect_right

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

pos = bisect_right(a, a[-1]/2)
if pos == 0 or abs(a[-1]/2 - a[pos-1]) > abs(a[-1]/2 - a[pos]):
    print(a[-1], a[pos])
else:
    print(a[-1], a[pos-1])

Solution (Python):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    """
    nをmax(A)にしていい理由が腑に落ちなかったので厳密証明。
    とはいえ証明は簡単で、M=max(A), m=(AのM以外の元), R=(M/2に一番近いAの元), r=(m/2に一番近いAの元)
    とすると
        comb(M, R) >= comb(M, r) >= comb(m, r)
    てだけでした。。。
    """
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx > 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx > 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()

Solution (Python):
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    
    
    
    s=sorted(a)
    ai=s[n-1]

    aj0=ai/2
    j=bisect_right(s, aj0)-1
    
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1<=aj2-aj0:
            aj=aj1
        else:
            aj=aj2
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = st_r*(st_n-st_r)
for r in range(2,N):
    cn = a[r]*(st_n-a[r])
    if m < cn:
        st_r = a[r]
        m = cn
print(st_n,st_r)

Solution (Python):
import numpy as np


n = int(input())
A = np.array(sorted(map(int, input().split())))

a = A[-1]
A = A[:-1]
i = np.argsort(np.abs(A - a / 2))[0]
b = A[i]

print(a, b)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    n = in_n()
    a = sorted(in_nl())

    a_max = a[-1]
    diff = 10**9 + 7
    for i in range(n - 1):
        t = abs(a_max / 2 - a[i])
        if t < diff:
            a_mid = a[i]
            diff = t

    print(a_max, a_mid)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
b=[abs(i-l/2) for i in a]
c=float("inf")
for i in range(n-1):
  c=min(c,b[i])
print(l,a[b.index(c)])

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
b=[abs(i-l/2) for i in a]
c=float("inf")
for i in range(n-1):
  c=min(c,b[i])
print(l,a[b.index(c)])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
n1=max(a)
n2=-n1
nc=n1/2
for m in a:
  if abs(m-nc)<abs(n2-nc) and m!=n1:
    n2=m
print (n1,n2)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
n1=max(a)
n2=-n1
nc=n1/2
a.pop(a.index(max(a)))
for m in a:
  if abs(m-nc)<abs(n2-nc):
    n2=m
print (n1,n2)

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
A=max(l)
mid=(A//2)+1 if A%2!=0 else A//2
dis_min=float("Inf")
l.sort()
ans=1
for i in l:
   if dis_min>abs(i-mid):
      dis_min=abs(i-mid)
      ans=i
print(A,ans)