AtCoder Beginner Contest 094 - Binomial Coefficients

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-----
5
6 9 4 2 11

-----Sample Output-----
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.

Difficulty: MEDIUM

Starter code:

Solutions:
n = int(input())
As = [int(a) for a in input().split()]
N = max(As)
Bs = [(abs(a - N / 2), a) for a in As]
(_, r) = min(Bs)
print(N, r)


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])


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


n = int(input())
a = list(map(int, input().split()))
p = max(a)
r = p / 2
print(p, int(min([i - r for i in a if i != p], key=abs) + r))


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)


N = int(input())
a = list(map(int, input().split()))
n = max(a)
r = 0
for i in range(N):
	if abs(a[i] - n / 2) < abs(r - n / 2):
		r = a[i]
print(n, r)


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)


n = int(input())
a = [int(i) for i in input().split()]
a1 = max(a)
half = a1 / 2
a2 = 0
for t in a:
	if abs(a2 - half) > abs(t - half):
		a2 = t
print('{} {}'.format(a1, a2))


(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)


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)


N = input()
a = sorted(list(map(int, input().split())))
ma = max(a)
s = [abs(i * 2 - ma) for i in a]
print(ma, a[s.index(min(s))])


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)))


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])


n = int(input())
l = sorted(map(int, input().split()))
m = l.pop()
h = m / 2
(t, r) = (h, 0)
for i in l:
	if (s := abs(i - h)) < t:
		(t, r) = (s, i)
print(m, r)


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)


n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
a.remove(max_a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))
print(max_a, a[med_i])


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
print(max_a, min(a, key=lambda x: abs(max_a - 2 * x)))


n = int(input())
A = sorted([int(i) for i in input().split()])
A_max = A.pop()
print(A_max, min(A, key=lambda x: abs(A_max - x * 2)))


N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
tmp = min(A)
d = maxA / 2
for a in A:
	if abs(d - a) < abs(d - tmp):
		tmp = a
print(maxA, tmp)


input()
arr = sorted((int(x) for x in input().split()))
m = arr[-1]
print(m, min(arr, key=lambda x: abs(m - x * 2)))


N = int(input())
A_arr = [int(x) for x in input().split()]
A_arr.sort()
Ai = A_arr[-1]
Aj = sorted(A_arr[:-1], key=lambda x: abs(2 * x - Ai))[0]
print(Ai, Aj)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = max(a) // 2
res = 0
c = max(a)
for i in range(n - 1):
	if abs(m - a[i]) <= c:
		res = a[i]
		c = abs(m - a[i])
print(max(a), res)


import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
n = max(A)
mid = n / 2
r = float('inf')
for a in A:
	if a == n:
		continue
	if abs(mid - r) > abs(mid - a):
		r = a
print(n, r)


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


n = int(input())
a = list(map(int, input().split()))
n = max(a)
a.remove(n)
t = n
for i in a:
	if t > abs(n / 2 - i):
		t = abs(n / 2 - i)
		r = i
print(n, r)


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(filter(lambda x: x != ai, a), key=lambda x: abs(x - ai // 2))
print('{} {}'.format(ai, aj))


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


n = int(input())
a = set(map(int, input().split()))
x = max(a)
z = 10 ** 9
for i in a:
	if abs(i - x / 2) < z:
		y = i
		z = abs(i - x / 2)
print(x, y)


n = int(input())
list_A = list(map(int, input().split()))
m = max(list_A)
(r, k) = (0, 0)
for a in list_A:
	if min(m - a, a) > k:
		r = a
		k = min(m - a, a)
print(m, r)


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


N = int(input())
A = sorted(list(map(int, input().split())))
import math
n = A.pop()
P_dif_A = sorted([(abs(a - n / 2), a) for a in A])
r = P_dif_A[0][1]
print(n, r)


n = int(input())
l = list(map(int, input().split()))
mx = max(l)
rmx = 0
for i in l:
	x = min(i, mx - i)
	if rmx < x:
		rmx = x
if l.count(rmx) > 0:
	print(mx, rmx)
else:
	print(mx, mx - rmx)


import bisect
_ = int(input())
a = sorted(map(int, input().split()))
n = a[-1]
m = n / 2
b = bisect.bisect(a, m)
s = a[b - 1]
t = a[b]
if m - s <= t - m:
	print(n, s)
else:
	print(n, t)


n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
i = max(a_sorted)
j = min(a_sorted, key=lambda x: abs(i - 2 * x))
print(i, j)


N = int(input())
A = list(map(int, input().split()))
(*else_A, max_A) = sorted(A)
print(max_A, min(else_A, key=lambda a: abs(max_A / 2 - a)))


from bisect import bisect_left, bisect_right
n = int(input())
al = list(map(int, input().split()))
al.sort()
ai = al[-1]
if ai % 2 == 0:
	aj_best = ai // 2
	ind = bisect_right(al, aj_best) - 1
	ind = ind if 0 <= ind < n else None
	val1 = al[ind] if ind is not None else 0
	ind = bisect_left(al, aj_best)
	ind = ind if 0 <= ind < n else None
	val2 = al[ind] if ind is not None else ai
	if abs(aj_best - val1) <= abs(aj_best - val2):
		aj = val1
	else:
		aj = val2
else:
	aj_best = ai // 2
	ind = bisect_right(al, aj_best) - 1
	ind = ind if 0 <= ind < n else None
	val1 = al[ind] if ind is not None else 0
	ind = bisect_left(al, aj_best)
	ind = ind if 0 <= ind < n else None
	val2 = al[ind] if ind is not None else ai
	if abs(aj_best - val1) <= abs(aj_best + 1 - val2):
		aj = val1
	else:
		aj = val2
print(ai, aj)


(n, *a) = map(int, open(0).read().split())
m = max(a)
b = m // 2
o = min(a)
for A in a:
	if abs(A - b) < abs(o - b):
		o = A
print(m, o)


n = int(input())
an = [int(i) for i in input().split()]
ans_a = max(an)
ans_b = 0
for i in an:
	if min(ans_a - ans_b, ans_b) < min(ans_a - i, i):
		ans_b = i
print(ans_a, ans_b)


n = int(input())
a = list(map(int, input().split()))
m = max(a)
a.remove(m)
d = m
for i in a:
	if abs(m / 2 - i) < d:
		c = i
		d = abs(m / 2 - i)
print(m, c)


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


n = int(input())
a = list(map(int, input().split()))
N = max(a)
a.remove(N)
li = [abs(N / 2 - k) for k in a]
index = li.index(min(li))
print('{0} {1}'.format(N, a[index]))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = max(a)
b = [abs(i - m / 2) for i in a]
print(m, a[b.index(min(b))])


n = int(input())
a = list(map(int, input().split()))
m = max(a)
t = m / 2
ta = 10 ** 10
c = 0
for i in a:
	if i != m:
		if abs(i - t) < ta:
			ta = abs(i - t)
			c = i
print(m, c)


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


_ = int(input())
A = list(map(int, input().split()))
A.sort()
N = A.pop()
K = -1
d = -1
for a in A:
	r = min(a, N - a)
	if r > d:
		d = r
		K = a
print(N, K)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
r = a.pop(0)
s = r
temp = 0
for i in range(n - 1):
	if abs(r - 2 * a[i]) < s:
		s = abs(r - 2 * a[i])
		temp = a[i]
print(r, temp)


n = int(input())
a = list(map(int, input().split()))
maxA = max(a)
midA = 0
for ai in a:
	if abs(midA - maxA / 2) > abs(ai - maxA / 2):
		midA = ai
print(maxA, midA)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans_n = a[-1]
del a[-1]
ans_r = a[0]
dif = 1001001000
for i in range(n - 1):
	if dif > abs(ans_n / 2 - a[i]):
		ans_r = a[i]
		dif = abs(ans_n / 2 - a[i])
print('%d %d' % (ans_n, ans_r))


n = int(input())
l = list(map(int, input().split()))
m = max(l)
del l[l.index(m)]
m1 = l[0]
for i in l:
	if abs(m / 2 - i) < abs(m1 - m / 2):
		m1 = i
print(m, m1)


n = int(input())
a = list(map(int, input().split()))
b = max(a)
a.remove(b)
l = []
for i in range(n - 1):
	l.append([abs(b / 2 - a[i]), a[i]])
l.sort()
print(b, l[0][1])


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
n = A[0]
r = A[1]
for a in A[1:]:
	if abs(n / 2 - r) > abs(n / 2 - a):
		r = a
print(n, r)


n = int(input())
a = list(map(int, input().split()))
x = max(a)
a.remove(x)
b = [abs(i - x / 2) for i in a]
y = a[b.index(min(b))]
print(x, y)


N = int(input())
A = list(map(int, input().split()))
A.sort()
n = A.pop()
A.sort(key=lambda a: abs(a - n / 2))
r = A[0]
print(n, r)


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])


N = int(input().strip())
A = list(map(int, input().strip().split(' ')))
n = max(A)
r = A[max([(min(a, n - a), i) for (i, a) in enumerate(A)])[1]]
print(n, r)


n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
c = 0
for i in range(n - 1):
	if abs(a[i + 1] - p / 2) < abs(a[i] - p / 2):
		c = a[i + 1]
	else:
		break
print(p, c)


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


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1]

def bigger(ind):
	nonlocal a, n, l
	if a[ind] > l / 2:
		return True
	else:
		return False
top = n
bottom = -1
while top - bottom > 1:
	mid = (top + bottom) // 2
	if bigger(mid):
		top = mid
	else:
		bottom = mid
if a[top] + a[bottom] > l or a[top] == l:
	print(l, a[bottom])
else:
	print(l, a[top])


(n, *a) = map(int, open(0).read().split())
nn = max(a)
a.remove(nn)
nr = min(a, key=lambda x: abs(x - nn / 2))
print(nn, nr)


def main():
	_ = int(input())
	a = [int(an) for an in input().split()]
	a.sort()
	half_val = -(-a[-1] // 2)
	dist_list = [abs(half_val - an) for an in a[:-1]]
	min_index = dist_list.index(min(dist_list))
	print(f'{a[-1]} {a[min_index]}')

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
A.sort()
X = A[-1]
m = X
p = A[0]
for a in A[:-1]:
	if abs(a - X / 2) < m:
		m = abs(a - X / 2)
		p = a
	else:
		break
print(X, p)


n = int(input())
A = sorted(list(map(float, input().split())))
a = A[-1]
b = a / 2
c = a
for i in range(n):
	d = abs(A[i] - b)
	if d < c:
		c = d
		e = A[i]
print(int(a), end=' ')
print(int(e))


n = int(input())
a = list(map(int, input().split()))
a.sort()
am = a.pop(-1)
a2 = a[0]
for i in a:
	if abs(am / 2 - a2) > abs(am / 2 - i):
		a2 = i
print(am, a2)


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)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(a)
for i in a:
	if min(aj, ai - aj) < min(i, ai - i):
		aj = i
print(ai, aj)


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


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = max(a)
m = float('inf')
for i in a:
	if abs(b // 2 - i) <= abs(b // 2 - m) and i != b:
		m = i
print(b, m)


n = int(input())
arr = [int(a) for a in input().split()]
i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: min(abs(i // 2 - a), abs((i + 1) // 2 - a)))
print(i, j)


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)


import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
(t, r) = divmod(A[-1], 2)
idx = bisect.bisect_left(A, t)
if r == 1:
	if idx != 0:
		if abs(A[idx - 1] - t) < abs(A[idx] - t):
			idx = idx - 1
elif idx != 0:
	if abs(A[idx - 1] - t) <= abs(A[idx] - t):
		idx = idx - 1
print(' '.join([str(A[-1]), str(A[idx])]))


from bisect import bisect_right
n = int(input())
a = sorted(list(map(int, input().split())))
x = a[-1]
c = bisect_right(a, x // 2)
if x % 2 == 0:
	if x // 2 in a:
		print('{} {}'.format(x, x // 2))
	elif a[c] - x // 2 >= x // 2 - a[c - 1]:
		print('{} {}'.format(x, a[c - 1]))
	else:
		print('{} {}'.format(x, a[c]))
elif x // 2 in a:
	print('{} {}'.format(x, x // 2))
elif x // 2 + 1 in a:
	print('{} {}'.format(x, x // 2 + 1))
elif a[c] - (x // 2 + 1) >= x // 2 - a[c - 1]:
	print('{} {}'.format(x, a[c - 1]))
else:
	print('{} {}'.format(x, a[c]))


n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
ans = 0
for i in range(n):
	if abs(ans - max_a / 2) > abs(a[i] - max_a / 2):
		ans = a[i]
print(max_a, ans)


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


n = int(input())
aa = sorted(list(map(int, input().split())))
list1 = []
ma = aa[-1]
for i in range(n):
	d = abs(aa[i] - (ma + 1) // 2)
	list1.append([d, i])
md = min(list1, key=lambda x: x[0])
print(ma, aa[md[1]])


n = int(input())
a = list(map(int, input().split()))
a.sort()
maxa = max(a)
ans = 0
ch = 0
for i in range(n - 1):
	b = maxa - a[i]
	c = min(b, a[i])
	if c >= ch:
		ans = a[i]
		ch = c
print(str(maxa) + ' ' + str(ans))


N = int(input())
A = list(map(int, input().split()))
A.sort()
x = A[-1]
A.pop()
z = x * 10
for a in A:
	if abs(x - a * 2) < abs(x - z * 2):
		z = a
print(x, z)


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))


n = int(input())
a = sorted(list(map(int, input().split())))
c = a[-1]
d = max(a[:-1], key=lambda x: min(x, c - x))
print(c, d)


n = int(input())
v = list(map(int, input().split()))
a = max(v)
b = 0
for i in v:
	if abs(i - a / 2) < abs(b - a / 2):
		b = i
print(a, b)


input()
a = sorted(list(map(int, input().split())))
print(a[-1], sorted(a, key=lambda x: abs(a[-1] - 2 * x))[0])


n = int(input())
A = list(map(int, input().split()))
A.sort()
m = A[-1]
M = [abs(m / 2 - a) for a in A[:-1]]
r = A[M.index(min(M))]
print(m, r)


n = int(input())
ls = sorted(map(int, input().split()))
ds = [abs(x - ls[-1] / 2) for x in ls[:-1]]
print(ls[-1], ls[ds.index(min(ds))])


n = int(input())
A = list(map(int, input().split()))
a_i = max(A)
r = a_i / 2
a_j = 0
for a in A:
	if abs(a - r) < abs(a_j - r):
		a_j = a
print(a_i, a_j)


n = int(input())
A = sorted(map(int, input().split()))
n = A[-1]
mi = 10 ** 9
for a in A[:-1]:
	if mi > abs(n / 2 - a):
		mi = abs(n / 2 - a)
		r = a
print(n, r)


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)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = l[-1] / 2
ans = 0
for i in range(n - 1):
	if abs(l[i] - c) < abs(ans - c):
		ans = l[i]
print(l[-1], ans)


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)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[1]
for i in range(1, n - 1):
	if abs(a[0] / 2 - a[i]) > abs(a[0] / 2 - a[i + 1]):
		ans = a[i + 1]
	else:
		break
print(a[0], ans)


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)


import bisect
n = input()
a = sorted(map(int, input().split()))
m = a[-1]
q = bisect.bisect_right(a, m / 2)
p = q - 1
if abs(m / 2 - a[p]) > abs(m / 2 - a[q]):
	print(m, a[q])
else:
	print(m, a[p])


import bisect
n = int(input())
A = list(map(int, input().split()))
A.sort()
if n == 2:
	ans = [A[1], A[0]]
	print(*ans)
	return
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)


n = int(input())
L = list(map(int, input().split()))
a = max(L)
b = a
c = 0
for i in range(n):
	if b >= abs(L[i] - a / 2) and L[i] != a:
		b = abs(L[i] - a / 2)
		c = L[i]
print(a, c)


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


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


N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
r = 0
for i in range(N - 1):
	if min(a[i], n - a[i]) > min(r, n - r):
		r = a[i]
print(n, r)


N = int(input())
A = list(map(int, input().split()))
A.sort()
max_el = A[-1]
median = max_el // 2
import bisect
median_ind = bisect.bisect_left(A, median)
if median_ind == 0:
	print(A[-1], A[0])
	return
if median_ind == N - 1:
	print(A[-1], A[-2])
	return
abs_right = abs(A[median_ind] - median)
abs_left = abs(A[median_ind - 1] - median)
if abs_right > abs_left:
	print(A[-1], A[median_ind - 1])
	return
print(A[-1], A[median_ind])


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


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = a[0]
del a[0]
r = min(a, key=lambda x: abs(l / 2 - x))
print(l, r)


from bisect import bisect_left
N = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
i = bisect_left(a, x / 2, hi=N - 2)
for j in [i - 1, i, i + 1]:
	if 0 <= j < N and abs(a[j] - x / 2) < abs(a[i] - x / 2):
		i = j
print(x, a[i])


import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
num = a[-1] / 2
b = bisect.bisect_left(a, num)
if abs(num - a[b]) < abs(num - a[b - 1]):
	print(a[-1], a[b])
else:
	print(a[-1], a[b - 1])


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)


n = int(input())
a = list(map(int, input().split()))
ma = max(a)
cnt = 10 ** 9
mid = ma / 2
for i in range(n):
	if abs(cnt - mid) >= abs(mid - a[i]):
		cnt = a[i]
print(max(ma, cnt), min(ma, cnt))


n = int(input())
A = [int(i) for i in input().split()]
A_max = max(A)
A.remove(A_max)
print(A_max, min(A, key=lambda x: abs(A_max - x * 2)))


N = int(input())
A = list(map(int, input().split()))
P = max(A)
I = A.index(P)
del A[I]
Q = min(A, key=lambda x: abs(2 * x - P))
print(P, Q)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1]
x = l // 2
y = 10 ** 12
z = 0
for i in range(n - 1):
	if y >= abs(x - a[i]):
		y = abs(x - a[i])
		z = i
print(l, a[z])


n = int(input())
A = [int(i) for i in input().split()]
A_max = max(A)
A.remove(A_max)
A_sub = [abs(A_max - i * 2) for i in A]
print(A_max, A[A_sub.index(min(A_sub))])


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)


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


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)


n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = a.pop(-1)
b = [min(i, abs(max_a - i)) for i in a]
print(max_a, a[b.index(max(b))])


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
a2 = sorted(a, key=lambda x: abs(ai / 2 - x))
aj = a2[0] if a2[0] != ai else a2[1]
print('{} {}'.format(ai, aj))


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)))


n = int(input())
a = list(map(int, input().split()))
m = max(a)
mi = 0
I = 0
for i in a:
	if min([i, m - i]) >= mi:
		mi = min([i, m - i])
		I = i
print(m, I)


n = int(input())
a = list(map(int, input().split()))
mx = max(a)
d = mx
ans = 0
if n == 2:
	print(100, 0)
	exit()
for i in a:
	if abs(i - mx / 2) < d:
		d = abs(i - mx / 2)
		ans = i
print(mx, ans)


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


n = int(input())
x = [int(i) for i in input().split()]
t = sorted(x)
m = t.pop()
a = [(i, abs(m / 2 - i)) for i in t]
a = sorted(a, key=lambda x: x[1])
print(m, a[0][0])


N = int(input())
lsa = list(map(int, input().split()))
n = max(lsa)
r = 0
for i in range(N):
	r1 = lsa[i]
	if min(r1, n - r1) >= min(r, n - r):
		r = r1
print(n, r)


n = int(input())
a = list(map(int, input().split()))
nmax = max(a)
target = nmax / 2
cur = a[0] if a[0] != nmax else a[1]
curdiff = abs(cur - target)
for i in range(n):
	if a[i] == nmax:
		continue
	diff = abs(a[i] - target)
	if diff < curdiff:
		curdiff = diff
		cur = a[i]
print(nmax, cur)


N = int(input())
X = list(map(int, input().split()))
M = max(X)
X.remove(M)
m = min([abs(2 * x - M) for x in X])
if (M + m) // 2 in X:
	m = (M + m) // 2
else:
	m = (M - m) // 2
print(M, m)


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)


n = int(input())
x = list(map(int, input().split()))
a = max(x)
b = a
for i in x:
	if abs(a / 2 - i) <= abs(a / 2 - b):
		b = i
print(a, b)


N = int(input())
X = [int(i) for i in input().split()]
M = max(X)
S = 10 ** 10
j = 0
for i in range(N):
	if abs(2 * X[i] - M) <= S:
		j = i
		S = abs(2 * X[i] - M)
print(M, X[j])


n = int(input())
A = list(map(int, input().split()))
A.sort()
N = A[-1]
R = A[0]
for i in A:
	if abs(N / 2 - R) > abs(N / 2 - i):
		R = i
print(N, R)


n = int(input())
A = list(map(int, input().split()))
a = max(A)
A.remove(a)
A.sort(key=lambda x: abs(x - a / 2))
b = A[0]
print(' '.join([str(a), str(b)]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
mid = m / 2
d = 10 ** 9
for ai in a[:-1]:
	x = abs(mid - ai)
	if x < d:
		ans = ai
		d = x
print(m, ans)


N = int(input())
A = sorted(list(map(int, input().split())))
a1 = A[-1]
med = (a1 + 1) // 2
B = [abs(a - med) for a in A]
idx = B.index(min(B))
a2 = A[idx]
print(a1, a2)


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])
	return
elif ind == N - 1:
	print(ma, a[-1])
	return
if abs(ma // 2 - a[ind - 1]) < abs(ma // 2 - a[ind]):
	print(ma, a[ind - 1])
else:
	print(ma, a[ind])


N = int(input())
A = sorted(list(map(int, input().split())))
B = A[-1]
print(B, min(A, key=lambda x: abs(B - 2 * x)))


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)


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


N = int(input())
a = list(map(int, input().split()))
n = max(a)
a.remove(n)
d = list(map(lambda ai: abs(n / 2 - ai), a))
i = d.index(min(d))
r = a[i]
print(n, r)


_ = int(input())
a = list(map(int, input().split()))
a.sort()
n = max(a)
a = a[:-1]
rc = float('inf')
rd = 0
r = 0
for i in a:
	if rc > abs(i - n / 2):
		r = i
	rc = min(rc, abs(i - n / 2))
print(n, r)


_ = input()
axs = list(map(int, input().split()))
i = max(axs)
j = min(axs, key=lambda j: abs(i / 2 - j) + (i == j))
print('{} {}'.format(i, j))


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


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


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)


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

def main(n, a):
	a.sort()
	c = a[n - 1]
	R = c / 2
	r = 0
	for i in a:
		if abs(R - i) < abs(R - r):
			r = i
	print('{x} {y}'.format(x=c, y=r))

def __starting_point():
	(n, a) = getval()
	main(n, a)
__starting_point()


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[-1] / 2
tmp = a[-1]
for i in range(n):
	if tmp > abs(b - a[i]):
		ans = a[i]
		tmp = abs(b - a[i])
print(a[-1], ans)


n = int(input())
a = list(map(int, input().split()))
x = max(a)
half = x / 2
y = sorted([ai for ai in a if ai < x], key=lambda x: abs(half - x))[0]
print('{} {}'.format(x, y))


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


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)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
b = [(min(e, x - e), e) for e in a[:-1]]
b.sort()
print(x, b[-1][1])


import bisect
(n, *A) = map(int, open(0).read().split())
A.sort()
m = A[-1]
i = bisect.bisect_right(A, m / 2)
print(m, [A[i - 1], A[i]][abs(A[i - 1] - m / 2) > abs(A[i] - m / 2)])


n = int(input())
a = list(map(int, input().split()))
m = max(a)
q = 0
for i in range(n):
	if abs(m // 2 - a[i]) < abs(m // 2 - q):
		q = a[i]
print(m, q)


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def get_primenumber(number):
	prime_list = []
	search_list = list(range(2, number + 1))
	while search_list[0] <= math.sqrt(number):
		head_num = search_list.pop(0)
		prime_list.append(head_num)
		search_list = [num for num in search_list if num % head_num != 0]
	prime_list.extend(search_list)
	return prime_list

def factrization_prime(number):
	factor = {}
	div = 2
	s = math.sqrt(number)
	while div < s:
		div_cnt = 0
		while number % div == 0:
			div_cnt += 1
			number //= div
		if div_cnt != 0:
			factor[div] = div_cnt
		div += 1
	if number > 1:
		factor[number] = 1
	return factor

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

def I():
	return map(int, input().split())

def X():
	return list(input())

def L():
	return list(input().split())

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
num = []
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
n = k()
a = l()
a.sort()
a = a[::-1]
A = a[0]
del a[0]
b = inf
c = 0
for i in a:
	if b > abs(A // 2 - i):
		b = min(b, abs(A // 2 - i))
		c = i
print(f'{A} {c}')


n = int(input())
aa = sorted(list(map(int, input().split())))
nn = aa[-1]
aa = aa[0:-1]
ds = sorted([(abs(a - nn / 2), a) for a in aa])
r = ds[0][1]
print(nn, r)


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])


n = int(input())
ls = list(map(int, input().split()))
m = max(ls)
ls.remove(m)
ds = [abs(x - m / 2) for x in ls]
print(m, ls[ds.index(min(ds))])


n = int(input())
a = list(map(int, input().split()))
m = max(a)
a.remove(m)
p = m / 2
a_m = [abs(a[i] - p) for i in range(n - 1)]
print(m, a[a_m.index(min(a_m))])


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)])


n = int(input())
a = list(map(int, input().split()))
b = max(a)
(_, c) = min([(abs(b / 2 - x), x) for x in a])
print('%d %d' % (b, c))


n = int(input())
l = sorted(list(map(int, input().split())))
n1 = l[-1]
n2 = 0
for i in l[:n]:
	tmp = min(i, n1 - i)
	if tmp > n2:
		n2 = i
print(n1, n2)


from math import ceil
n = int(input())
data = list(map(int, input().split()))
n = max(data)
nn = n / 2.0
r = min((d for d in data if d != n), key=lambda x: abs(nn - x))
print(n, r)


import math
n = int(input())
a = list(map(int, input().split()))
m = max(a)
k = 0
for x in a:
	if abs(k * 2 - m) > abs(x * 2 - m):
		k = x
print(m, k)


n = int(input())
a = sorted((int(a) for a in input().split()))
m = a[-1]
print(m, min(a, key=lambda x: abs(m - x * 2)))


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


n = int(input())
ali = list(map(int, input().split()))
amax = max(ali)
ali.remove(amax)
b = min(ali, key=lambda x: abs(2 * x - amax))
print(amax, end=' ')
print(b)


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


n = int(input())
ns = list(map(int, input().split()))
a = max(ns)
ns.remove(a)
b = a / 2
c = min((abs(j - b) for j in ns))
d = [i for i in ns if abs(i - b) == c][0]
print(a, d)


n = int(input())
A = list(map(int, input().split()))
x = max(A)
A.remove(x)
B = [abs(x / 2 - a) for a in A]
y = A[B.index(min(B))]
print(x, y)


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)


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


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])
	return
if i == N - 1:
	print(m, A[-2])
	return
(a, b) = (A[i - 1], A[i])
if abs(a * 2 - m) > abs(b * 2 - m):
	print(m, b)
else:
	print(m, a)


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)


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))])


N = int(input())
A = list(map(int, input().split()))
if N == 2:
	print(*(max(A), min(A)))
	return
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))


(N, *A) = map(int, open(0).read().split())
A.sort()
x = [abs(A[-1] - 2 * A[i]) for i in range(N - 1)]
y = sorted(((v, i) for (i, v) in enumerate(x)))
print(A[-1], A[y[0][1]])


N = int(input())
s = list(map(int, input().split()))
n = max(s)
s.remove(n)
q = n
for i in s:
	t = abs(n / 2 - i)
	if q >= t:
		q = t
		w = str(n) + ' ' + str(i)
print(w)


N = int(input())
A = list(map(int, input().split()))
M = max(A)
A.sort()
X = 0
for i in range(N - 1):
	if abs(2 * A[X] - M) > abs(2 * A[i] - M):
		X = i
print(M, A[X])


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
half = a[0] / 2
ans1 = a[0]
flag = 10 ** 9 + 10
for i in range(1, N):
	if flag > abs(a[i] - half):
		ans2 = a[i]
		flag = abs(a[i] - half)
print(ans1, ans2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = 0
ma = 0
for i in a:
	t = min(i, a[-1] - i)
	if m < t:
		m = t
		ma = i
print(a[-1], ma)


import itertools
n = int(input())
a = list(map(int, input().split()))
m = max(a)
t = 10 ** 9 + 1
for i in a:
	if abs(i - m // 2) < t and i != m:
		t = abs(i - m // 2)
		s = i
print(m, s)


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)


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a, reverse=True)
x = a[0]
a = a[1:]
y = min([(i, x - i) for i in a], key=max)[0]
print('{} {}'.format(x, y))


n = int(input())
A = sorted(list(map(int, input().split())))
r = A[0]
for i in range(1, n - 1):
	if abs(A[i] * 2 - A[-1]) < abs(r * 2 - A[-1]):
		r = A[i]
print(A[-1], r)


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min((item for item in a if item != ai), key=lambda x: abs(x - ai // 2))
print('{} {}'.format(ai, aj))


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)


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))


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)


def main():
	n = int(input())
	A = [int(a) for a in input().split(' ')]
	A.sort(reverse=True)
	ans = []
	f = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800]
	if A[0] <= 10:
		for i in range(n):
			for j in range(i + 1, n):
				ans.append({'max': A[i], 'min': A[j], 'comb': int(f[A[i]] / (f[A[j]] * f[A[i] - A[j]]))})
		ans.sort(key=lambda s: -s['comb'])
		print(ans[0]['max'], ans[0]['min'])
		return 0
	i = 0
	j = 1
	while i < n and j < n:
		M = A[i]
		m = A[j]
		if abs(A[i] / 2 - A[j]) <= 0.5:
			ans.append({'max': A[i], 'min': A[j], 'dif': abs(A[i] / 2 - A[j]), 'k': min([A[j], A[i] - A[j]])})
			i += 1
		elif A[i] / 2 < A[j]:
			if j < n - 1:
				j += 1
			else:
				ans.append({'max': A[i], 'min': A[j], 'dif': abs(A[i] / 2 - A[j]), 'k': min([A[j], A[i] - A[j]])})
				j += 1
		elif A[i] / 2 > A[j]:
			if abs(A[i] / 2 - A[j - 1]) > abs(A[i] / 2 - A[j]) or j == i + 1:
				ans.append({'max': A[i], 'min': A[j], 'dif': abs(A[i] / 2 - A[j]), 'k': min([A[j], A[i] - A[j]])})
			else:
				ans.append({'max': A[i], 'min': A[j - 1], 'dif': abs(A[i] / 2 - A[j - 1]), 'k': min([A[j - 1], A[i] - A[j - 1]])})
			i += 1
		if i == j:
			j += 1
	ans.sort(key=lambda s: (-s['k'], -s['max']))
	k_cand1 = ans[0]['k']
	ans2_idx = 0
	for i in range(len(ans)):
		if ans[i]['k'] == k_cand1 - 1:
			ans2_idx = i
	if ans2_idx and ans[0]['max'] < ans[i]['max']:
		print(ans[i]['max'], ans[i]['min'])
	else:
		print(ans[0]['max'], ans[0]['min'])
main()


n = int(input())
a = sorted(list(map(int, input().split())))
m = max(a)
print(m, min(a, key=lambda x: abs(m - x * 2)))


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)


N = int(input())
A = list(map(int, input().split()))
mx = max(A)
A = [a for a in A if a < mx]
A.sort(key=lambda a: abs(mx / 2 - a))
print(mx, A[0])


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


n = int(input())
a = list(map(int, input().split()))
b = max(a)
c = []
h = b / 2
for i in range(n):
	c.append([abs(a[i] - h), a[i]])
d = min(c)[1]
print(b, d)


N = int(input())
A = sorted(map(int, input().split()), reverse=True)
n = A[0]
m = n / 2
c = 1e+100
for a in A[1:]:
	if abs(m - a) < abs(m - c):
		c = a
print(n, c)


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])


n = int(input())
A = list(map(int, input().split()))
ai = max(A)
A.remove(ai)
Asub = [abs(ai / 2 - a) for a in A]
aj = A[Asub.index(min(Asub))]
print('{} {}'.format(ai, aj))


N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
A.remove(A_max)
X = [abs(a - A_max // 2) for a in A]
X_min_id = X.index(min(X))
print(A_max, A[X_min_id])


n = int(input())
a = list(map(int, input().split()))
ma = max(a)
a = a[:a.index(ma)] + a[a.index(ma) + 1:]
l = []
for i in range(n - 1):
	l.append([abs(ma - 2 * a[i]), '-' if ma - 2 * a[i] >= 0 else '+'])
l.sort()
print(ma, end=' ')
print((ma - l[0][0]) // 2) if l[0][1] == '-' else print((ma + l[0][0]) // 2)


N = int(input())
A = sorted(map(int, input().split()))
ai = A[-1]
aj = min(A, key=lambda a: max(a, ai - a))
print(ai, aj)


n = int(input())
a = [int(i) for i in input().split()]
ai = max(a)
b = [abs(int(i - ai / 2)) if i != ai else 10000000000.0 for i in a]
aj = a[b.index(min(b))]
print(str(ai) + ' ' + str(aj))


n = int(input())
A = list(map(int, input().split()))
A.sort()
T = {}
for i in range(n - 1):
	T[abs(A[i] - (A[-1] - A[i]))] = A[i]
T_min = min(T.items())
print(A[-1], T_min[1])


n = int(input()) - 1
a = sorted(list(map(int, input().split())))
k = a[-1]
kk = k // 2
(x, b) = (10 ** 9, 10 ** 9)
for i in range(n):
	if abs(a[i] - kk) <= x:
		x = abs(a[i] - kk)
		b = a[i]
print(k, b)


n = int(input())
a = sorted(map(int, input().split()))
ans = a[-1]
m = float('inf')
k = 0
for i in range(n):
	if abs(ans / 2 - a[i]) < m:
		m = abs(ans / 2 - a[i])
		k = i
print(ans, a[k])


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
n = A[0]
ds = [(abs(n / 2 - A[i]), i) for i in range(1, N)]
ds.sort()
print(n, A[ds[0][1]])


(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)


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())


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


n = int(input())
A = sorted(list(map(int, input().split())))
A_max = A.pop()
n = A_max / 2
n = min([(abs(n - i), i) for i in A], key=lambda x: x[0])[1]
print(A_max, n)


n = int(input())
a = [int(i) for i in input().split()]
m = max(a)
m2 = m / 2
f = m
ans = -m
for i in a:
	if i != m and abs(m2 - i) <= f:
		f = abs(m2 - i)
		ans = i
print(m, ans)


n = int(input())
a = sorted(map(int, input().split()))
ai = a[-1]
am = sorted(map(lambda x: min(x, ai - x), a))
aj = am[-1]
if aj in a:
	print(ai, aj)
else:
	print(ai, ai - aj)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(x, a) = (a[-1], a[:-1])
temp = []
for i in a:
	temp.append(abs(x / 2 - i))
y = a[temp.index(min(temp))]
print(x, y)


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)


n = int(input())
an = [int(i) for i in input().split()]
an.sort()
ai = an[-1]
print('%d %d' % (ai, min(an, key=lambda i: abs(ai - i * 2))))


n = int(input())
A = list(map(int, input().split()))
M = max(A)
l = 0
for i in range(n):
	if abs(M / 2 - A[i]) < abs(M / 2 - l):
		l = A[i]
print(M, l)


(n, *a) = map(int, open(0).read().split())
a.sort(reverse=True)
ai = a[0]
aj = ai
for i in range(1, n):
	if abs(aj - ai / 2) >= abs(a[i] - ai / 2):
		aj = a[i]
print(ai, aj)


n = int(input())
s = list(map(int, input().split()))
s.sort()
c = float('inf')
a = max(s)
for i in s[0:n]:
	x = abs(a / 2 - i)
	if x < c:
		c = x
		b = i
print(a, b)


n = int(input())
L = list(map(int, input().split()))
L.sort()
maxL = L[-1]
li = [abs(x - maxL / 2) for x in L]
a = li.index(min(li))
print(maxL, L[a])


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


def solve(n, a):
	a = list(sorted(a, reverse=True))
	first = a[0]
	b = a[1:]
	delta = [abs(x - first // 2) for x in b]
	second = b[delta.index(min(delta))]
	return (first, second)

def main():
	N = int(input())
	a = list(map(int, input().split()))
	print(*solve(N, a))

def __starting_point():
	main()
__starting_point()


import bisect
_ = input()
a = [int(i) for i in input().split()]
a.sort()
n = a[-1]
m = n / 2
b = bisect.bisect(a, m)
s = a[b - 1]
t = a[b]
if m - s <= t - m:
	print(n, s)
else:
	print(n, t)


(n, *a) = map(int, open(0).read().split())
a = sorted(a)
l = max(a)
b = a
b = sorted(b, key=lambda t: abs(t - l / 2))
r = b[0]
print(l, r)


n = int(input())
As = list(map(int, input().split()))
As.sort()
m = As[-1]
k = min(As[:-1], key=lambda A: abs(m / 2 - A))
print(m, k)


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)))


import bisect
import math
N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
harf = n / 2
ri = bisect.bisect_left(a, harf)
r = a[ri]
if ri > 0 and abs(harf - r) >= abs(harf - a[ri - 1]):
	r = a[ri - 1]
print(n, r)


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


n = int(input())
A = list(map(int, input().split()))
A.sort()
y = max(A)
x = A[0]
for a in A:
	if abs(y / 2 - a) < abs(y / 2 - x):
		x = a
print(y, x)