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 copy

n=int(input())
a=list(map(int,input().split()))
ma=max(a)
a2=copy.copy(a)
a2.remove(ma)
ma2 = ma/2
a3 = [(abs(v-ma2),v) for v in a2]
print(ma,min(a3)[1])

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

m = max(Ai)
idx = Ai.index(m)
del Ai[idx]

target = m // 2
nearest = 1000000000
use_value = -1
for a in Ai:
    d = abs(a - target)
    if nearest > d:
        nearest = d
        use_value = a

print(m, use_value)

Solution (Python):


import sys
import itertools as itr


input()
An = list(map(int, sys.stdin.readline().rstrip().split()))

n = max(An)
r = 0
for a in An:
  if a == n:
    continue

  if abs(2*a-n) < abs(2*r-n):
    r = a
print(n,r)

Solution (Python):
c = int(input())
l = list(map(int, input().split()))
n = max(l)
r = 0
for i in l:
  if abs(n/2 - i) < abs(n/2 - r):
    r = i
from math import factorial
print(n,r)

Solution (Python):
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_right(lst,n/2)
if n/2 - lst[m-1] <= lst[m] -n/2:
  print(n,lst[m-1])
else:
  print(n,lst[m])

Solution (Python):
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(int(m))+" "+str(int(t)))

Solution (Python):
def binomial_coefficients(n: int, A: list) -> tuple:
    max_A = max(A)
    max_r, max_a = 0, 0
    for a in A:
        if a == max_A:
            continue
        r = min(a, max_A - a)
        if max_r < r:
            max_r = r
            max_a = a

    return max_A, max_a


if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    ai, aj = binomial_coefficients(n, A)
    print(ai, aj)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(sorted(a), key=lambda x: min(x, m - x)))
))
print(ans)

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

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


import bisect

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

print(p,q)

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    n = max(A)
    tmp = float("inf")
    r = 0
    for x in A:
        if abs(n-x*2) < tmp and x != n:
            tmp = abs(n-x*2)
            r = x
    print(n, r)


if __name__ == "__main__":
    main()

Solution (Python):


import itertools
import collections
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    pos = bisect.bisect(A, n//2)
    if n == A[pos]:
        r = A[pos-1]
    elif pos == 0:
        r = A[pos]
    else:
        r = A[pos] if abs(n/2-A[pos]) < abs(n/2-A[pos-1]) else A[pos-1]

    print("{} {}".format(n, r))


if __name__ == '__main__':
    main()

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


ans_n = max(A)
A.remove(ans_n)

ans_r = -1
diff_min = float('inf')

for a in A:
    diff = abs(ans_n / 2 - a)
    if diff < diff_min:
        diff_min = diff
        ans_r = a

print(ans_n, ans_r)

Solution (Python):
import sys
from math import factorial

def comb(a, b):
  return factorial(a) / (factorial(b) * factorial(a-b))


def f(A, a):
  if len(A) == 1:
    return A[0]
  
  if len(A) == 2:
    b1, b2 = A[0], A[1]
    if min(b1, a-b1) >= min(b2, a-b2):
      return b1
    else:
      return b2
  
  m = len(A) // 2
  b1, b2, b3 = A[m-1], A[m], A[m+1]
  c1, c2, c3 = min(b1, a-b1), min(b2, a-b2), min(b3, a-b3)
  c = max(c1, c2, c3)  
  
  if c2 == c:
    return b2
  elif c1 == c:
    return f(A[:m], a)
  else:
    return f(A[m+1:], a)


def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  ai = A[-1]
  A = A[:-1]
  aj = f(A, ai)
  print(ai, aj)


if __name__ == '__main__':
  main()

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

L.sort()
res1 = L[-1]

tmp = res1 / 2

res2 = 10 ** 10
for i in range(N-1):
    if abs(tmp - L[i]) < abs(tmp - res2):
        res2 = L[i]

    
print(res1, res2)

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
n = A[-1]
x = bisect.bisect_left(A, n / 2)
if x == 0:
    print(n, A[0])
elif x == N:
    print(n, A[-1])
else:
    if n / 2 - A[x - 1] <= A[x] - n / 2:
        print(n, A[x - 1])
    else:
        print(n, A[x])

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
inf = 10 ** 10
m = a[n-1]
a = [-inf] + a[0:n-1] + [inf]
left = bisect.bisect_left(a, m//2)
if m//2 - a[left-1] < a[left] - m//2:
    print(m, a[left-1])
else:
    print(m, a[left])

Solution (Python):
import math
import bisect

N = int(input())

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

mINF = -1e18
INF = 1e18

mx = A[-1]
A = [mINF] + A[:-1] + [INF]
idx = bisect.bisect_left(A, (mx+1) // 2)

ans = A[idx] if A[idx] - (mx+1) // 2 < (mx+1) // 2 - A[idx-1] else A[idx - 1]

print(mx, ans)

Solution (Python):
import bisect as bi

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

A.sort()

n=A[nn-1]

ki=bi.bisect_right(A[:nn-1],float(n/2))

if abs(float(n/2)-A[:nn-1][min(ki,nn-2)]) <= abs(float(n/2)-A[:nn-1][max(ki-1,0)]) :
    k=A[min(ki,nn-2)]
else :
    k=A[max(ki-1,0)]

print("{} {}".format(n,k))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = []
c = max(a)
d = -100
for i in range(n):

    if a[i] != c:

        if d == -100:

            d = abs((c/2)-a[i])
            e = i 

        else:

            if abs((c/2)-a[i]) < d:

                d = abs((c/2)-a[i]) 
                e = i 
        
        
print('{} {}'.format(c,a[e]))

Solution (Python):


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

ans_a = max(a)
min_b = max(a)
for i in range(n):
    if a[i] != ans_a:
        if min_b > abs(a[i] - ans_a/2):
            ans_b = a[i]
            min_b = abs(a[i] - ans_a/2)
print("{} {}".format(ans_a, ans_b))

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

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

b = bisect.bisect(a,ma//2)
koho = []
if b-1 >= 0:
    koho.append([abs(ma//2-a[b-1]),a[b-1]])
if b < n-1:
    koho.append([abs(ma//2-a[b]),a[b]])

if ma % 2 == 1:
    b2 = bisect.bisect(a,ma//2+1)
    if b2-1 >= 0:
        koho.append([abs(ma//2+1-a[b2-1]),a[b2-1]])
    if b2 < n-1:
        koho.append([abs(ma//2+1-a[b2]),a[b2]])

koho.sort()
print(ma,koho[0][1])

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
p=A[0]
c=p/2
q=0
for i in A[1:]:
    if abs(q-c)>=abs(i-c):
        q=i
print(p,q)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
k = 0
j = 0
v = L[N-1]
if N % 2 == 0:
  if L[0]-v/2 >= 0:
    k = L[0]
  elif L[N-1]-v/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= v/2:
        j = i
        break
    if L[j] == v/2:
      k = L[j]
    else:
      if abs(v/2-L[j-1]) <= abs(v/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
else:
  if L[0]-(v+1)/2 >= 0:
    k = L[0]
  elif L[N-1]-(v+1)/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= (v+1)/2:
        j = i
        break
    if L[j] == (v+1)/2:
      k = L[j]
    else:
      if abs((v+1)/2-L[j-1]) <= abs((v+1)/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
print(v,k)

Solution (Python):
N = int(input())
a = tuple(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0]) if n != a[0] else (n, a[1])
for i in a:
 if n == i: continue
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

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

k =  a[0]
d_min = float('inf')
for i in range(1,n):
    d = abs(a[i] - k/2)
    if d < d_min:
        d_min = d
        r = a[i]

print(k,r)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(max(a), min(a))
    else:
        ma = max(a)
        sa = sorted([(i, abs(ma // 2 - a[i]))
                     for i in range(n)], key=lambda x: x[1])
        print(ma, a[sa[0][0]])


main()

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

m = a[-1]

r = 10**10
for i in range(n):
    if abs(a[i]-(m-a[i])) < r:
        r = abs(a[i]-(m-a[i]))
        idx = i

print(m, a[idx])

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
m = a[-1]
print(m, min(a, key=lambda x:abs(m-x-x)))

Solution (Python):
from bisect import bisect_left
n = int(input())
a = sorted(list(map(int, input().split())))
if n == 2:
    print(a[1], a[0])
    exit()
m = a.pop()
idx = bisect_left(a, m//2)
if idx == 0:
    print(m, a[0])
    exit()
else: 
    r1 = a[idx-1]
    r2 = a[idx]

    if r1 > m-r2:
        r = r1
    else:
        r = r2

print(m, r)

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

a.sort()
x = a.pop()
hx = x / 2

ma = a.pop()
for i in a:
  if abs(hx - i) < abs(hx - ma):
    ma = i
    
print(x, ma)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
y = A.pop(-1)
print(y, min(A, key=lambda x: abs(y - 2 * x)))

Solution (Python):
def check(a, b, target):
    if abs(target - a) < abs(target - b):
        return a
    else:
        return b


n, a = int(input()), list(map(int, input().split()))
if n == 2:
    a.sort(reverse = True)
    print(a[0], a[1])
    exit()
a.sort()
l, r = 0, n
target = a[-1] >> 1
while l < r:
    mid = (l + r) >> 1
    if a[mid] > target:
        r = mid
    else:
        l = mid + 1
if a[l] <= target:  
    print(a[-1], check(a[l], a[l + 1], target))
else:  
    print(a[-1], check(a[l - 1], a[l], target))

Solution (Python):
n = int(input())
a = list(int(i) for i in input().split())
ans1 = max(a)
tmp1 = ans1/2
ans2 = 10**11
if len(set(a)) > 2:
 for i in a:
  ans2 = min(ans2,abs(tmp1-i))
 if  int(tmp1+ans2) in a:
  ans3 = tmp1+ans2
 else:
  ans3 = tmp1-ans2
 print(ans1,int(ans3))
else:
  a.remove(ans1)
  print(ans1,min(a))

Solution (Python):
def near_num(x,nodes):
    temp = []
    for i in range(len(nodes)):
        temp.append(abs(x-nodes[i]))
        if i != 0:
            if temp[i] >= temp[i-1]:
                return nodes[i-1]
    else:
        return nodes[len(nodes)-1]
        

N = int(input())
s = list(map(int,input().split()))
s.sort()

M = s[N-1]

if M % 2 == 0:
    m = near_num(M//2,s)
elif abs(near_num(M//2+1,s)-(M//2+1)) >= abs(near_num(M//2,s)-M//2):
    m = near_num(M//2,s)
else:
    m = near_num(M//2+1,s)

print(M,m)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
maximum = max(l)
a = 10 ** 10
r = (maximum - 1) / 2

for x in l:
    if abs(x-r) <= a:
        a = abs(x-r)
        tmp = x
print(maximum,tmp)

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

maxA = max(A)
half = maxA/2
diff = 10**10
ans = 0
for i in range(N):
    if A[i] != maxA and abs(A[i]-half) < diff:
        diff = abs(A[i]-half)
        ans = A[i]

print(maxA, ans)

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

sort_a = sorted(a,reverse=True)
max_a = sort_a[0]

ans=0
for i in range(n):
  if min(abs(max_a/2-sort_a[i]),abs(max_a/2-ans)) == abs(max_a/2-sort_a[i]):
    ans = sort_a[i]
print(max_a,ans)

Solution (Python):

import bisect

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

    a.sort()
    i = bisect.bisect_left(a, a[n - 1] / 2)

    r = 0
    if a[i] * 2 == a[n - 1]:
        r = a[i]
    elif i == 0:
        r = a[0]
    elif i == n - 1:
        r = a[i - 1]
    elif a[n - 1] - a[i - 1] * 2 < a[i] * 2 - a[n - 1]:
        r = a[i - 1]
    else:
        r = a[i]

    print('{} {}'.format(a[n - 1], r))


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
ans=float('inf')
for i in s:
    if i==a:
        continue
    if ans>=abs(i-a//2):
        ans=abs(i-a//2)
        k=i
print(a,k)

Solution (Python):
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
if a==k:
    k=s[0]
print(a,k)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
MIN = a[0]
keep = 0
for i in range(n):
    by = abs((a[0]/2)-a[i])
    if by <= MIN:
        MIN = by
        keep = i
print(a[0],a[keep])

Solution (Python):
import numpy as np
n = int(input())
a = np.zeros(n, dtype=int)
buf = input().split()
for i in range(n):
	a[i] = int(buf[i])

gamma = np.argmax(a)
alpha = a[gamma]
a[gamma] = -1
bata = a[np.argmin(np.abs(a-alpha/2))]
print(alpha, bata)

Solution (Python):


"""
参考：https://img.atcoder.jp/arc095/editorial.pdf
"""

N = int(input())
aN = list(map(int, input().split()))
aN.sort(reverse=True)

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

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

n, r = max(A), None
A.pop(A.index(n))
target, best_score = n / 2, float('inf')
for a in A:
    score = abs(a - target)
    if score < best_score:
        best_score = score
        r = a

print(n, r)

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MAX = max(a)
MAX_HALF = MAX / 2
HALF = 0
for i in a:
  if abs(MAX_HALF - i) < abs(MAX_HALF - HALF):
    HALF = i

print(MAX,HALF)

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
maxn = a.pop(-1)
maxr = a[0]

for i in a:
    if abs(i-maxn/2) < abs(maxr-maxn/2):
        maxr = i

print(maxn,maxr)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
p = abs(a[0]//2-a[1])
q = a[1]
for i in range(2,n):
    if p >= abs(a[0]//2-a[i]):
        q = a[i]
        p = abs(a[0]/2-a[i])
print(a[0],q)

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

Solution (Python):

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

ai = max(an)
tmpdiff = 10**9
aj = 0
for a in an:
    if ai > a and abs(ai/2-a) < tmpdiff:
        tmpdiff = abs(ai/2-a)
        aj = a

print(ai,aj)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
d=10**10
for i in range(N):
  if i<=N-2:
    if d>abs(a[i]-(n/2)):
      d=abs(a[i]-(n/2))
      r=a[i]
print(n,r)

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

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

ai = max(a)
aj = a[0]
for i in a:
    if abs(ai - 2*i) <= abs(ai - 2*aj):
        aj = i

print(ai,aj)

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


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            
    return m


print(a_max, find_nearest(A, a_max/2))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a_max = a[0]
a_med = round(a_max / 2)
min = a[0] - a[n-1]
a_answer = a[n-1]
for i in range(1, n):
    if min > abs(a[i] - a_med):
        min = a[i] - a_med
        a_answer = a[i]
print("{0} {1}".format(a_max, a_answer))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[N - 1]
r = -100
for e in a[:N - 1]:
    if (e - n / 2) ** 2 < (r - n / 2) ** 2:
        r = e
print(n, r)

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

n = A[-1]
A = A[:-1]

r_val = n//2
diff_min = float(n)

for a in A:
    diff = abs(n/2 - float(a))
    if diff_min > diff:
        diff_min = diff
        r = a

print(n,r)

Solution (Python):
from bisect import bisect_left as bl

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

p = L[-1]
q = bl(L,p/2)
if N == 2 :
    r = L[0]
else :
    if abs((p/2)-L[q]) < abs((p/2)-L[q-1]) :
        r = L[q]
    else :
        r = L[q-1]
print(p,r)


from math import factorial as f

Solution (Python):
from bisect import bisect_left as bl

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

p = L[-1]
q = bl(L,p/2)
if N == 2 :
    r = L[0]
else :
    if abs((p/2)-L[q]) < abs((p/2)-L[q-1]) :
        r = L[q]
    else :
        r = L[q-1]
print(p,r)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
p = a[-1]
q = a[0]
m = p
for x in a:
  if abs(p-2*x)<m:
    q = x
    m = abs(p-2*x)
print(p,q)

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

a=A[-1]/2
tmp=A[-1]
ans=0
for i in range(n):
    if(abs(a-A[i]) < tmp):
        tmp=abs(a-A[i])
        ans=A[i]

print("{} {}".format(A[-1],ans))

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

sa = sorted(A)
from bisect import *
hv = sa[-1] / 2
ri = bisect_right(sa, hv)

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if abs(sa[ri - 1] - hv) < abs(sa[ri] - hv) else sa[ri])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] / 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

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

t = max(a)
b = []

for i in range(n):
  if t != a[i]:
    u = abs(t / 2 - a[i])
    b.append(u)
  else:
    b.append(t)

v = a[b.index(min(b))]
print(t, v)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
print(b,min(a,key=lambda x :abs(b-2*x)))

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)
 
t = 7+10**9
m = M/2
p = 0
for k in range(N):
    if abs(m-A[k]) < t:
        t = abs(m-A[k])
        p = k
print(M,A[p])

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

a.sort()
ai = a[n-1]

aj = 10**9


if ai % 2 == 0:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

else:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

    m = ai // 2 + 1
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num


print(ai, aj)

Solution (Python):


import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
b = min(A)
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)

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

mx = max(A)

med = -1
min_dist = mx*999

for a in A:
    if a == mx: continue
    d = abs(a*2 - mx)
    if d < min_dist:
        min_dist = d
        med = a

print(mx, med)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

mx = max(a)
a.remove(mx)

cur = 10**18
ai = 0

for ai in a:
    if abs(ai - mx//2) < cur:
        cur = abs(ai-mx//2)
        ans = ai
        
print(mx, ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
if a[0]==100:
    print(100,0)
    exit()
m = max(a)
res = m
for i in a:
    if abs(m//2-res)>abs(m//2-i):
        res = i
print(m,res)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
X = A[-1]
X2 = (X + 1) // 2
dd = A[-1]
for i in range(N - 1):
    d = abs(X2 - A[i])
    if d < dd:
        dd = d
        Y = A[i]
print(X, Y)

Solution (Python):
def answer(aaa,max):
    half = max / 2
    bbb = []
    for i in range(len(aaa)):
        bbb.append(abs(half - aaa[i]))
    return aaa[bbb.index(min(bbb))]


n = int(input())
a = list(map(int,input().split(" ")))
b = max(a)
a.remove(b)
print(b,answer(a,b))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mxm = max(a)
div = []
for i in range(n):
    div.append(abs(mxm/2.0-a[i]))
mini = min(div)
ind = div.index(mini)

if n == 2:
    print(max(a),min(a))
else:
    print(mxm,a[ind])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
l = m/2
x, v = abs(a[0]-l), 0
for i in range(n):
    s = abs(a[i]-l)
    if x > s:
        x, v = s, i
if a[v] == m:
    print(m, 0)
else:
    print(m, a[v])

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

ans_n = A.pop()
target = ans_n / 2

ans_r = - 1
high_score = 0
for r in A:
    min_r = min(ans_n - r, r)
    if min_r >= high_score:
        high_score = r
        ans_r = r

print(ans_n, ans_r)

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

a = sorted(a)
ai = a[-1]
aj = -1
for j in range(n-1):
    if abs(ai/2-a[j]) < abs(ai/2-aj):
        aj = a[j]
print(ai, aj)

Solution (Python):

n= int(raw_input())
a = map(int,raw_input().split())

M=max(a)
M_f = float(M)
a.sort()
index=0
for i in range(len(a)):
    if a[i]>=M_f/2:
        index = i
        break
if index==0:
    print str(M) + " " +str(a[index])
else:
    if a[index]==M_f/2:
        print str(M) + " " +str(a[index])
    elif M_f/2-a[index-1]<=a[index]-M_f/2:
        print str(M) + " " + str(a[index-1])
    else:
        print str(M) + " " + str(a[index])

Solution (Python):
import math
n, aa = int(input()), list(map(int, input().split()))
l = max(aa)
r = 99999999999999
ar = sorted(aa)
for a in aa:
    if a == l:
        continue
    if abs(a - l/2) < abs(r - l/2):
        r = a
print(l, r)

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
m = max(list_a)
search = m/2
min_a = abs(list_a[0] - search)
min_ind = 0
for i in range(n):
    if min_a > abs(list_a[i] - search):
        min_a = abs(list_a[i] - search)
        min_ind = i
if list_a[min_ind] == m:
    print(m,0)
else:
    print(m, list_a[min_ind])

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
d=b//2
a1=[]
for i in range(len(a)):
    a1.append(abs(d-a[i]))
c=min(a1)
if d+c in a:
    print("{} {}".format(b,d+c))
else:
    print("{} {}".format(b,d-c))

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

n = max(A)
r = max(A)
tmp = 0
for i in range(N):
    a = A[i]
    if a == n: continue
    if a < n - a: a = n - a
    if tmp <= n - a:
        r = A[i]
        tmp = n - a

print(n, r)

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

a_i = max(a)
a2 = sorted(a, key = lambda x: abs(2 * x - a_i))

a_j = float('inf')
j = 0
while a_j >= a_i:
    a_j = a2[j]
    j += 1

print(a_i, a_j)

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


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

c_n = max(a)
c_r = None
c_r_err = float("inf")
for i in a:
    if i == c_n:
        continue
    err = abs((c_n/2) - i)
    if err < c_r_err:
        c_r = i
        c_r_err = err

print("{0} {1}".format(c_n, c_r))

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

ma = max(a)
ma2 = ma/2
mi = 999999999999.0
mii = -1
for i in a:
    if abs(ma2 - i) < mi and i != ma:
        mi = abs(ma2 - i )
        mii = i

print(ma,mii,sep=" ")

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

A.sort()
if n == 2:
    print(A[1],A[0])
else:
    ans_a = A[n-1]

    left = 0
    right = n-1
    while True:
        if left == right:
            ans_b = A[left]
            break
        elif left + 1 == right:
            if abs(A[left]-ans_a/2) < abs(A[right]-ans_a/2):
                ans_b = A[left]
            else:
                ans_b = A[right]
            break
        elif ans_a//2 < A[(left+right)//2]:
            right = (left+right)//2
        else:
            left = (left+right)//2

    print(ans_a,ans_b)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
maxim = 0
for x in a:
    maxim = max(x,maxim)
delta = a
halfFloor = maxim//2
halfCeil = halfFloor
if maxim%2 == 1:
    halfCeil += 1
delta = maxim
for x in a:
    if x == maxim:
        continue
    if x <= halfFloor:
        if halfFloor - x < delta:
            candidate = x        
            delta = halfFloor - x
    else:
        if x - halfCeil < delta:
            candidate = x
            delta = x - halfCeil
print(maxim,candidate)

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

mid = arr[-1]/2
min_ = float('inf')
tmp = 0
for x in arr[:-1]:
    if abs(mid-x) < min_:
        tmp = x
        min_ = abs(mid-x)

print('{0} {1}'.format(arr[-1],tmp))

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

mindist = a[n - 1]

for j in range(n - 1):
    dist = int(abs(a[n - 1] / 2 - a[j]))
    if dist < mindist:
        aj = a[j]
        mindist = dist

print(a[n - 1], aj)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)

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

a.sort()

ans1=max(a)
ans2=0
b=0
c=0
lb=[]
lc=[]

if ans1%2==0:
    b=ans1/2
    c=ans1/2
else:
    b=(ans1+1)/2
    c=b-1

for i in a:
    if abs(i-b)<abs(ans2-b):
        ans2=i
    if abs(i-c)<abs(ans2-c):
        ans2=i

print(str(ans1)+" "+str(ans2))

Solution (Python):
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = int(input())
a = nl()

a_sorted_1 = sorted(a)
ai = a_sorted_1[-1]

a_sorted_2 = sorted(a_sorted_1[:-1], key = lambda x: abs(x - ai / 2))
aj = a_sorted_2[0]
print(ai, aj)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
aa = inpl()
aa.sort()
MAX = aa[-1]
dist = INF
for a in aa:
	tmp = abs(MAX/2-a)
	if tmp < dist:
		dist = tmp
		ans = a

print(MAX,ans)

Solution (Python):
import numpy as np
n = int(input())
a_list = [int(i) for i in input().split()]
res1 = max(a_list)
a_list.remove(res1)
res_med = res1 / 2
res2 = a_list[np.argmin([abs(i - res_med) for i in a_list])]
print(str(res1)+' '+str(res2))

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

A.sort()

if len(A) == 2:
    print(A[1], A[0])
else:
    a = A[-1]
    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])

Solution (Python):
n = int(input())
a_list = [i for i in list(map(int, input().split()))]

a_list.sort()
max_num = a_list.pop(-1)
margin = max_num
r = 0
for a in a_list:
    m = abs(max_num/2 - a)
    if margin >= m:

        margin = m
        r = a

print(str(max_num) + " " + str(r))

Solution (Python):
n = int(input())
ai = 0
aj = 0
nums = list(map(int, input().split()))
nums.sort()
ai = nums[n-1]
i = 0
while nums[0] < ai//2:
    aj = nums[0]
    del nums[0]
else:
    if ai > nums[0] + aj:
        aj = nums[0]
print(str(ai) + " " + str(aj))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
ans2=min(a)
mean=ans1 / 2.0


for i in a:
    if abs(mean-i) < abs(mean-ans2):
        ans2=i

print(ans1,ans2)

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

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

print(a[-1], ans)

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

p = max(A)

As = sorted(A)

q = 0

for x in As:
  if abs(p/2-x) < abs(p/2-q):
    q = x
    
print(p,q)