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):
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  
  r = 0
  c = a[-1] / 2
  for i in range(n-1):
    if abs(c-r) > abs(c-a[i]):
      r = a[i]
  ans = "{} {}".format(a[-1], r)
  print(ans)

  
if __name__ == "__main__":
  main()

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def main():
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

Solution (Python):
import sys, math
sys.setrecursionlimit(10 ** 6)
from collections import deque, defaultdict, Counter
from operator import itemgetter

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

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

a.sort()
ans = 114514191981036436433-4
s = 0
nn = a[n]/2
for i in range(n+1):
    if ans > abs(nn-a[i]):
        ans = abs(nn-a[i])
        s = i
        
print(a[n],a[s])

Solution (Python):
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    ans = -1
    for a in A:
        if a + 1 <= n / 2:
            ans = a
        else:
            b = n - a
            if b > ans:
                ans = a

    print(n, ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
ma=ma//2
aaa=max(a)
ans=10**10
for i in range(n):
    if abs(ma-a[i])<ans and a[i]!=aaa:
        ans=abs(ma-a[i])
        aaaaaa=a[i]
print(max(a),aaaaaa)

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






maxA = max(A)
mv = float("inf")
aj = None
for a in A:
    if a != maxA:
        value = abs(a - maxA // 2)
        if value < mv:
            mv = value
            aj = a

print(maxA, aj)

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

a.sort()

N,K = a[n-1],a[0]

for i in range(1,n):
    if abs((N+1)//2 - K) > abs((N+1)//2 - a[i]):
        K = a[i]

print(N,K)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans1 = max(a)
diff = min(ans1//2, ans1//2 + 1)
ans2 = ans1
for x in a:
  if x == ans1:
    continue
  d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x))
  if d <= diff:
    diff = d
    ans2 = x
print('{} {}'.format(ans1, ans2))

Solution (Python):
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
a.sort()
ma = a[-1]
mid = ma / 2 

idx = bisect_left(a, mid)

if abs(a[idx] - mid) < abs(a[idx-1] - mid):
	ans_idx = idx
else:
	ans_idx = idx - 1

print(ma, a[ans_idx])

Solution (Python):
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
a.sort()
ma = a[-1]
mid = ma / 2 

idx = bisect_left(a, mid)

if abs(a[idx] - mid) < abs(a[idx-1] - mid):
	ans_idx = idx
else:
	ans_idx = idx - 1

print(ma, a[ans_idx])

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = max(a)
half_idx = bisect.bisect_left(a, m//2)

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p
p=10**9+7 

if n == 2:
    print(a[1], a[0])
    exit()

if 1 <= half_idx < n-1:
    if min(a[half_idx-1], m-(a[half_idx-1])) >= max(min(a[half_idx], m-(a[half_idx])), min(a[half_idx+1], m-(a[half_idx+1]))):
        print(m, a[half_idx-1])
    elif min(a[half_idx], m-(a[half_idx])) >= max(min(a[half_idx-1], m-(a[half_idx-1])), min(a[half_idx+1], m-(a[half_idx+1]))):
        print(m, a[half_idx])
    elif min(a[half_idx+1], m-(a[half_idx+1])) >= max(min(a[half_idx], m-(a[half_idx])), min(a[half_idx-1], m-(a[half_idx-1]))):
        print(m, a[half_idx+1])
elif half_idx == 0:
    if min(a[half_idx], m-(a[half_idx])) >= min(a[half_idx+1], m-(a[half_idx+1])):
        print(m, a[half_idx])
    elif min(a[half_idx+1], m-(a[half_idx+1])) >= min(a[half_idx], m-(a[half_idx])):
        print(m, a[half_idx+1])
elif half_idx == n-1:
    if min(a[half_idx], m-(a[half_idx])) >= min(a[half_idx-1], m-(a[half_idx-1])):
        print(m, a[half_idx])
    elif min(a[half_idx-1], m-(a[half_idx-1])) >= min(a[half_idx], m-(a[half_idx])):
        print(m, a[half_idx-1])

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

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == n-1:
    index -= 1
    
print(a[-1],a[index])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 



N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

if (N%2==0 and A[ind]!=half) or (N%2==1 and A[ind]-half > 1):
    if ind > 0 and half - A[ind-1] <= A[ind] - half:
        ind -= 1

print(A[-1], A[ind])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 



N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1
if ind == N-1:
    ind -= 1

print(A[-1], A[ind])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 



N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

    
if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1
if ind == N-1:
    ind -= 1
print(A[-1], A[ind])

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

def closest(x):
    res = None
    min_diff = None
    for k in a:
        if k == m:
            continue
        diff = abs(k - x)
        if res is None or min_diff > diff:
            min_diff = diff
            res = k
    return res

print(m, closest(m // 2))

Solution (Python):
n,*a=map(int,open(0).read().split())
a=sorted(a)
m=a[-1]
r=max(a[:-1],key=lambda x:min(x,m-x))
print(m,r)

Solution (Python):
def main3():
    input()
    t = sorted(list(map(int, input().split())))
    ma = t.pop(-1)
    r = min(t, key=lambda x: abs(x - ma / 2))
    print(ma, r)

if __name__ == '__main__':
    main3()

Solution (Python):
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
s=a[n-1]
a[n-1]=s*10
k=bisect.bisect_left(a,s//2)
b=a[k-1]
c=a[k]
if abs(b*2-s)<abs(c*2-s):
  ans=b
else:
  ans=c
print(s,ans)

Solution (Python):
from math import factorial
N = int(input())
A = list(map(int,input().split()))
t, j = float("INF"), -1
max_A = max(A)
A.remove(max_A)
for i in range(N-1):
  if abs(max_A//2 - A[i]) < t:
    t = abs(max_A//2 - A[i])
    j = i
print(max_A, A[j])

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left
from operator import lt, le
def findNearstValue(lst, val, left=True):
    """ソート済のリストから，valに最も近い要素を返す.
    @param lst: ソート済のリスト
    @param left:
        lv < val < rv，val-lv == rv-val のとき，
        Trueならばlvを，Falseならばrvを選択する
    @return もっともvalに値が近いlstの要素
    """
    pos = bisect_left(lst, val)
    if pos == 0: return lst[0]
    if pos == len(lst): return lst[-1]
    lv, rv = lst[pos-1:pos+1]
    op = le if left else lt
    return lv if op(val-lv, rv-val) else rv

def main():
    n = II()
    aa = MII()
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    ans_r = findNearstValue(aa, m)
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
ListA = list(map(int,input().split()))
ListA.sort()
Minj = 10e8
Maxj = ListA[-1]

for j in range(N-1):
    if abs(ListA[j]*2-ListA[-1])<Minj:
        Maxj = ListA[j]
        Minj = min(abs(ListA[j]*2-ListA[-1]),Minj)

    else:
        continue


print(ListA[-1],Maxj)

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left

def getNearstValue(lst, num):
    idx = bisect_left(lst, num+1)
    if abs(lst[idx]-num) > abs(lst[idx-1]-num):
        idx -= 1
    return idx

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    idx = getNearstValue(aa, m)
    ans_r = aa[idx]
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    idx = bisect_left(aa, m+1)
    ans_r = aa[idx] if idx!=n-1 else aa[idx-1]
    if abs(aa[idx]-m) > abs(aa[idx-1]-m):
        ans_r = aa[idx-1]
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    maxa = aa[-1]
    m = maxa/2
    a = getNearestValue(aa, m)
    print(maxa, a, end= ' ')

if __name__ == '__main__':
    main()

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

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

alist.sort(reverse=True)

n=alist[0]
min_func=10**9
r=0
for i in range(1,N):
  if abs(n-2*alist[i])<min_func:
    min_func=abs(n-2*alist[i])
    r=alist[i]

print(n,r)

Solution (Python):

n=int(input())
A=sorted(list(map(int, input().split())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now and a<amax:
    now=abs(a-half)
    ans=a
print(amax, ans)

Solution (Python):
n = int(input())
A = sorted(map(int, input().split()))
ans_n = A[-1]
ans_r = -1
for a in A:
  if ans_r < min(a, ans_n - a):
    ans_r = a
print(ans_n, ans_r)

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

from bisect import bisect_left
ans_n = a[-1]

p = bisect_left(a, (ans_n+1)//2)
ans_r = a[p] if p != n-1 else a[p-1]
if abs(a[p] - ans_n/2) > abs(a[p-1] - ans_n/2):
  ans_r = a[p-1]

print(ans_n, ans_r)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
n=a[-1]
r=a[0]
r_max=a[0]
if n//2<r:
    r_max=n-a[0]
for i in range(N-1):
    r_kari=a[i]
    r_=r_kari
    if n//2<r_:
        r_=n-r_
    if r_max<r_:
        r_max=r_
        r=r_kari
    
print(str(n)+" "+str(r))

Solution (Python):
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

n = numbers.pop()
r = min(numbers, key=lambda x: abs(x - n / 2))  

print(n, r)

Solution (Python):
from math import factorial

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


max_num = A[-1]
medium = max_num / 2

diff = []
for a in A:
    diff.append(abs(medium-a))

min_index = diff.index(min(diff))
print(max_num, A[min_index])

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

def obj_func(v, base):
  return abs(v - base)

ai = aj = max(A)
base = ai / 2
min_obj = 10**10
for a in A:
  if a == ai:
    continue
  obj = obj_func(a, base)
  if obj < min_obj:
    min_obj = obj
    aj = a

print(ai, aj)

Solution (Python):
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort()
max_value = max(list_A)
a = max_value/2
b = pow(10, 10)
c = 0
for num in list_A:
    if abs(a-num) < b:
        b = abs(a-num)
        c = num

print(max_value, c)

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

b=len(a)
Z=a[-1]
X=0
for i in range(1,n-1):
  if abs((Z/2)-a[X])>abs((Z/2)-a[i]):
    X=i



print(a[-1],a[X])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
mi=float("inf")
piv=0
pivid=[0]*n
id=1
cnb=[0]*n
for i in range(n):
    piv=a[i]
    mi=float("inf")
    while id<n:
        
        if abs(piv / 2 - a[id]) < mi:
            mi = abs(piv / 2 - a[id])
            id = id + 1
        else:
            id=id-1
            break

        
    pivid[i]=min(id,n-1)

print(a[0],a[pivid[0]])

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

m = max(a)

if m % 2 == 0:
  h = m // 2
  
  c = sys.maxsize
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h-a[i]):
      c = abs(h-a[i])
      ans = a[i]
    
  print(m, ans)
  
else:
  h1 = m // 2
  h2 = h1 + 1
  c = sys.maxsize
  
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h1-a[i]):
      c = abs(h1-a[i])
      ans = a[i]    
      
    if c > abs(h2-a[i]):
      c = abs(h2-a[i])
      ans = a[i]
      
  print(m,ans)

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

diff = 10 ** 9
r = None
for i in range(n):
    if a[i] == M:
        continue
    else:
        if abs(m - a[i]) < diff:
            diff = abs(m - a[i])
            r = a[i]

print(M, r)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
num = a[-1]
ans = a[0]
diff = abs(num/2-a[0])
for i in range(1,n-1):
    comp = abs(num/2-a[i])
    if diff >= comp:
        diff = comp
        ans = a[i]
print(num, ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ma = max(a)
    ma2 = ma/2
    a.remove(ma)
    ans = 0
    diff = 10**10
    for i in a:
        if diff > abs(ma2-i):
            ans = i
            diff = abs(ma2-i)
    print(ma, ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
ai = max(A)
ai_idx = A.index(ai)
half_maxA = ai // 2 if ai % 2 == 0 else ai // 2 + 1
for idx, a in enumerate(A):
    if ai_idx == idx:
        continue
    if idx == 0:
        aj = a
    else:
        if abs(a - half_maxA) < abs(aj - half_maxA):
            aj = a
print(ai, aj)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
y=a[-1]
diff=10**9+2
for i in a[:-1]:
    diff=min(diff,max(i,y-i))
x=-1
for i in a[:-1]:
    if max(i,y-i)==diff:
        x=i
        break
print(y,x)

Solution (Python):
def sq(a, b, mod):  
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


n = int(input())
alist = sorted(map(int, input().split()))
aset = set(alist)
ai = alist[-1]
aset.remove(ai)
target = ai // 2
sbn = [abs(alist[i] - target) for i in range(n - 1)]
j = min(sbn)
aj = (target + j) if (target + j) in aset else target - j
print(ai, aj)

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

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

Solution (Python):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n=int(input())
a=sorted(list(map(int,input().split())))
b=a[n-1]
a.pop(n-1)
ans=0
for i in range(n-1):
    if abs(b/2-a[ans])>abs(b/2-a[i]):
        ans=i
print(str(b)+" "+str(a[ans]))

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

ans1 = max(a)
ans2 = 0

dif = ans1
for i in a:
  if dif > abs(i-ans1/2) and i != ans1:
    dif = abs(i-ans1/2)
    ans2 = i
    
print(ans1, ans2)

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

Solution (Python):
import numpy as np

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

max_n = a[-1]
del a[-1]

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
    
half_n = max_n/2

print(max_n,getNearestValue(a,half_n))

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

a = max(A)
b = None
used = False
for i in A:
    if i == a and not used:
        used = True
    elif not b or abs(a // 2 - b) > abs(a // 2 - i):
        b = i

print(a, b)

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

if n==2:
    print(max(a), min(a))
else:
    left=max(a)
    ideal_right=left/2
    right=min(a, key=lambda x:abs(x-ideal_right))
    print(left, right)

Solution (Python):
n,*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):
n,*a=map(int,open(0).read().split())
a.sort()
b=a[-1]
c=a[0]
d=b/2-c
for i in a:
    if d>abs(b/2-i):
        c=i
        d=abs(b/2-i)
print(b,c)

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

b=max(a)
d=b/2

c=abs(d-a[0])

if a[0]==b:
  c=99999
ans=a[0]
for i in a:
  
  if i==b:
    continue
  if abs(i-d)<c:
    ans=i
    c=abs(i-d)
    
print(b,end=" ")
print(ans)

Solution (Python):
def d_binomial_coefficients():
    from bisect import bisect_left
    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 '{0} {1}'.format(n, r)

print(d_binomial_coefficients())

Solution (Python):


def submit():
    n = int(input())
    a = list(map(int, input().split()))
    
    a_max = max(a) 
    a.remove(a_max)

    r_best = a_max / 2
    a_diff = [(i, abs(e - r_best)) for i, e in enumerate(a)]
    a_diff.sort(key=lambda x: x[1])
    print(a_max, a[a_diff[0][0]])


submit()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
 
a=max(A)
 
B=[]
 
for i in range(n):
    if A[i]==a:
        B.append(a)
    else:
    	B.append(abs(A[i]-a/2))
 
ind=B.index(min(B))
 
b=A[ind]
 
print(a,b)

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

A.sort()

m=A[-1]
B=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    B[i]=min(A[i],m-A[i])

r=max(B)
if r in A:
    print(m,r)
else:
    print(m,m-r)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
p = max(A)
q = 0
for a in A:
    if abs(p/2-a) < abs(p/2-q): q = a
print(p, q)

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

a.sort(reverse=True)
h = a[0] / 2
m = a[1] - h
ans = 1
for i in range(2, n):
    if (abs(a[i] - h) < m):
        m = abs(a[i] - h)
        ans = i


print(a[0], a[ans])

Solution (Python):


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

A.sort()

ansi=A[-1]

def bin_isOK(index,key):
    if A[index] >= key:
        return True
    else:
        return False


def binary_search(key):
    ng = -1
    ok = len(A)

    while abs(ok - ng) >1:
        mid = (ok + ng)//2

        if bin_isOK(mid,key):
            ok = mid
        else:
            ng = mid
    
    return ok

Index=binary_search(ansi/2)

if abs(A[Index]-(ansi/2))<abs(A[Index-1]-(ansi/2)):
    ansj=A[Index]
else:
    ansj=A[Index-1]

print(ansi,ansj)

Solution (Python):

from math import ceil
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=False)
top = A[-1]
half = ceil(top / 2)
b = float("inf")
for i in range(N-1):
    if abs(half - b) > abs(half - A[i]):
        b = A[i]
print(top, b)

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

    mx = [-1, -1]
    for i in range(N):
        idx = bisect.bisect_left(A,A[i]/2)
        if idx == 0:
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
            continue

        if abs(A[i]/2 - A[idx]) < abs(A[i]/2 - A[idx-1]):
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
        else:
            mx = [max(A[i],A[idx-1]), min(A[i],A[idx-1])]
    
    print(*mx)
    
if __name__ == '__main__':
    solve()

Solution (Python):
N=int(input())
A=sorted(list(map(int,input().split())))
n,r=A.pop(),0
index=0
for i,j in enumerate(A):
    num=min(n-j,j)
    if num>r:
        index=i
        r=num
print(n,A[index])

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

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

A = list(sorted(A))

a = A[-1]
b = a//2
ans = 0
if n == 2:
    print(a, A[0])
else:
    m = A[-1]
    for i in A[:-1]:
        if m >= abs(b - i):
            m = abs(b - i)
            ans = i

    print(a, ans)

Solution (Python):
N = int(input())
A = [int(i)*2 for i in input().split()]

maxa = 0
ai = 0
for i in range(N):
    if A[i] > maxa:
        ai = i
        maxa = A[i]
maxa //= 2

res = 0
mind = 10**18
for i in range(N):
    if i==ai: continue
    d = abs(A[i]-maxa)
    if d < mind:
        mind = d
        res = i

print(maxa, A[res]//2)

Solution (Python):
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if A[-1]%2 == 0:
        if abs(A[k-1]-M) <= abs(M-A[k]) and abs(A[k-1]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    else:
        if abs(A[k-1]-M) < abs(M-A[k]) and abs(A[k-1]-M) < abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mx=max(a)
hf=0
for x in a:
  if abs(mx-2*hf)>abs(mx-2*x):
    hf=x
print(mx,hf)

Solution (Python):
N=int(input())
a=sorted(list(map(int,input().split())))
n=a[-1]
tmp=0
if n%2==0:
  ideal=n//2
  for i in range(N-1):
    if abs(ideal-tmp)>abs(ideal-a[i]):
      tmp=a[i]
else:
  ideal1=(n-1)//2
  ideal2=ideal1+1
  for i in range(N-1):
    if abs(ideal1-tmp)>abs(ideal1-a[i]) or abs(ideal2-tmp)>abs(ideal2-a[i]):
      tmp=a[i]
print(' '.join([str(n),str(tmp)]))

Solution (Python):
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
l=list(map(int,input().split()))
l.sort()
pre=10**9
mm=l[-1];p=0
for i in range(max(0,bl(l,l[-1]//2)-2),min(n,l[-1]//2+3)):
    if abs(mm/2-l[i])<pre:pre=abs(mm/2-l[i]);p=i
print(mm,l[p])

Solution (Python):
n = int(input())
ax, *A = sorted(map(int, input().split()), reverse=True)
median = ax/2
mid = A[0]
for a in A[1:]:
    if abs(median-mid) > abs(median-a):
        mid = a

print(ax, mid)

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

Solution (Python):

n = int(input())
a = sorted(list(map(int, input().split())))
m = a[-1]
mid = m / 2
l = 10 ** 10
for i in range(n-1):
    if abs(a[i] - mid) < abs(l - mid):
        l = a[i]
print(m, l)

Solution (Python):
n = int(input())
List = list(map(int,input().split()))
List = sorted(List)
a_j = List[-1]
checker = a_j
a_i = a_j
for item in List:
  temp = abs(a_j/2 - item)
  if temp < checker:
    checker = temp
    a_i = item
Answer = [a_j, a_i]
print(*Answer)

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

A.sort()
n = A[-1]

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

print(n, r)

Solution (Python):
def min_dist(n, r):
    max_arg_l = (n - 1) // 2
    max_arg_r = (n + 1) // 2

    return min(abs(max_arg_l - r), abs(max_arg_r - r))

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

    max_a = max(a)

    a = list(filter((max_a).__ne__, a))

    arg_max_a = a[0]

    for _a in a:
        if min_dist(max_a, _a) < min_dist(max_a, arg_max_a):
            arg_max_a = _a
    
    print(max_a, arg_max_a)

if __name__ == "__main__":
    solve()

Solution (Python):
x=int(input())
y=list(map(int, input().split()))
y.sort()
chk=y[len(y)-1]
ans=0
dis=10**10
for i in range(x):
	if abs(y[i]-(chk/2))<dis:
		ans=y[i]
		dis=abs(y[i]-(chk/2))
print(chk,ans)

Solution (Python):
import bisect

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

a.sort()
m = 0
ans = []

for i in a:
    R = i / 2
    p = bisect.bisect_left(a,R)
    if p == 0:
        r = a[p]
    else:
        r = a[p] if abs(a[p] - R) < abs(a[p - 1] - R) else a[p - 1]
    if m < i + min(r,i - r):
        m = i + min(r,i - r)
        ans = [i,r]
print(*ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ma = max(A)
mid = ma / 2
l = 10000000000
f = 0
for i in range(n):
  if ((ma == A[i]) and (f==0)):
    f = 1
    continue
  if abs(l) > abs(A[i]-mid):
    l = A[i]-mid
print(ma, int(mid+l))

Solution (Python):
from bisect import bisect_left

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

a.sort()
half = a[-1]/2

index = bisect_left(a,half)
candi1 = a[index]
if index > 0: candi0 = a[index-1]
else: candi0 = -1

if abs(half-candi0) > abs(half-candi1): ans = candi1
else: ans = candi0

print(a[-1], ans, sep=' ')

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

a.sort()
amax = a.pop()
ans = a[0]
for i in a :
    if abs(amax/2 - ans) > abs(amax/2 - i) :
        ans = i

print(amax, ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
a1 = a[0]
a2 = a[1]
for i in range(2, n-1):
    if min(a1 - a2, a2)  < min(a1 - a[i], a[i]):
        a2 = a[i]
print(a1, a2)

Solution (Python):

from collections import Counter, deque







import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    a.sort()
    p = a[-1]
    k = 0
    min_cur = INF

    for i in range(n-1):
        temp = abs(a[i] - (p/2))
        if temp < min_cur:
            min_cur = temp
            k = a[i]

    print(p, k)





if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    x = max(a)
    y = 0
    min_d = 10 ** 9
    if x % 2 == 0:
        for ai in a:
            if x == ai:
                continue
            d = abs(x // 2 - ai)
            if d < min_d:
                y = ai
                min_d = d
    else:
        for ai in a:
            d = min(abs(x // 2 - ai), abs(x // 2 + 1 - ai))
            if d < min_d:
                y = ai
                min_d = d
    print(x, y)


if __name__ == '__main__':
    solve()

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

A.sort()
ans = [0,0]
ans[0]=A[-1]
import bisect

mid = ans[0]/2
ind = bisect.bisect(A,mid)
ans[1]=A[ind-1] if mid-A[ind-1]<=A[ind]-mid else A[ind]

print(*ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort()
lmax=l[-1]
mini=abs(2*l[0]-lmax)
tmp=0
for i in range(1,n-1):
  if mini>abs(2*l[i]-lmax):
    tmp=i
    mini=abs(2*l[i]-lmax)
print(lmax,l[tmp])

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

a_i = max(a)
half = a_i/2

best = a_i*2
for j in a:
    if j==a_i:
        continue

    diff = abs(j-half)
    if diff < best:
        best = diff
        a_j = j

print(a_i, a_j)

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

a.sort()

candi = a[-1]
middle = (candi - 1) / 2

tmp = float("inf")
ans = 0

for i in range(len(a) - 1):
    if tmp >= abs(a[i] - middle):
        tmp = abs(a[i] - middle)
        ans = i
print(candi, a[ans])