Problem:
 Score : 400 points    Problem Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n , select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.      Constraints  2 \leq n \leq 10^5  0 \leq a_i \leq 10^9  a_1,a_2,...,a_n are pairwise distinct.  All values in input are integers.         Input Input is given from Standard Input in the following format:  n  a_1  a_2  ...  a_n       Output Print a_i and a_j that you selected, with a space in between.        Sample Input 1 5
6 9 4 2 11      Sample Output 1 11 6  \rm{comb}(a_i,a_j) for each possible selection is as follows:   \rm{comb}(4,2)=6   \rm{comb}(6,2)=15   \rm{comb}(6,4)=15   \rm{comb}(9,2)=36   \rm{comb}(9,4)=126   \rm{comb}(9,6)=84   \rm{comb}(11,2)=55   \rm{comb}(11,4)=330   \rm{comb}(11,6)=462   \rm{comb}(11,9)=55   Thus, we should print 11 and 6 .       Sample Input 2 2
100 0      Sample Output 2 100 0

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
N = a[-1]
ans = float('inf')
r = a[0]
for i in range(len(a)-1):
    if ans > abs(a[i]-N/2):
        ans = abs(a[i]-N/2)
        r = a[i]
print(str(N) +' '+ str(r))

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

sorted_a = sorted(a)
a_max = sorted_a[-1]

dif = []
for i,ai in enumerate(sorted_a[:n-1]):
    dif.append((i,abs(ai-(a_max/2))))

min_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = sorted_a[min_i]

print(a_max, dif_min)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
amax = a[0]
na = a[1:]
d = {}
for el in na:
    d[el] = abs(el - amax//2)
ds = sorted(d.items(), key=lambda x:x[1])
print(amax, ds[0][0])

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

import bisect

mid = (a[-1]+1)//2
mid_idx = bisect.bisect_left(a, mid)

if abs(mid - a[mid_idx-1]) <= abs(a[mid_idx] - mid):
    print(a[-1], a[mid_idx-1])
else:
    print(a[-1], a[mid_idx])

Solution (Python):
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
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**9)
INF = 10**9
mod = 10**9+7

def gnv(list, num):

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

N = i()
a = l()
m = max(a)
if N == 2:
    print(m,min(a))
else:
    print(m,gnv(a,m/2))

Solution (Python):
import bisect
import sys

def main(args):
    
    n = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    
    ans = [max(A), 0]
    ind = bisect.bisect_left(A ,ans[0]//2)
    if A[ind] == ans[0]//2:
        ans[1] = ans[0]//2
    else:
        r1 = min(A[ind],ans[0]-A[ind])
        r2 = min(A[ind-1],ans[0]-A[ind-1])
        if r1 > r2:
            ans[1] = A[ind]
        else:
            ans[1] = A[ind-1]
    
    print(*ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=a[n-1]
if n==2:
  print(a[1],a[0])
  exit()
if c%2==0:
  p=c//2
  o=10**9
  for i in range(n):
    if abs(p-a[i])<=o:
      o=abs(p-a[i])
      ans=a[i]
else:
  p=c//2
  q=c//2+1
  o=10**9
  for i in range(n):
    if abs(p-a[i])<abs(q-a[i]):
      if abs(p-a[i])<o:
        o=abs(p-a[i])
        ans=a[i]
    else:
      if abs(q-a[i])<o:
        o=abs(q-a[i])
        ans=a[i]
print(c,ans)

Solution (Python):
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)

Solution (Python):
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)

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

a=sorted(a)


b=a.pop(-1)
mid=b/2
dist=10**9
for i in range(n-1):

    
    d=abs(mid-a[i])
    if d <dist:
        dist=d
        ans=a[i]

print(b,ans)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
A.sort()
m = A[-1]
x = m / 2
ans = A[0]
for i in range(1, N-1):
    if abs(ans - x) > abs(A[i] - x):
        ans = A[i]
print(m, ans)

Solution (Python):
from bisect import bisect_left

n = int(input())
A=  list(map(int,input().split()))
A.sort()
am = A[-1]
amin = 0
ans = 0
for a in A[:-1]:
  if min(a, am-a) > amin:
    amin = min(a,am-a)
    ans = a
    
print(am , ans)

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

    cost = float("INF")
    mn = 0
    mx = a[-1]
    for aa in a[:-1]:
        tmp = abs(mx - aa * 2)
        if tmp < cost:
            cost = tmp
            mn = aa
    print(mx, mn)


if __name__ == "__main__":
    resolve()

Solution (Python):
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)

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

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

A.sort()

n = A[-1]
r1 = n / 2
temp = 10 ** 9
r = 0

for i, x in enumerate(A):
  if abs(r1 - x) <= temp and i != N-1:
    r = x
    temp = abs(r1 - x)

print(str(n)+" "+str(r))

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

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


A = sorted(A, reverse = True)
one = A[0]
diff = one
ans = -1
for i in range(1,len(A)):
  if abs(one / 2 - A[i]) < diff:
    diff = abs(one / 2 - A[i])
    ans = A[i]
    
print(one, ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)

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

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

aa.sort()

nn=max(aa)

c=0
tmp=10**9

for a in aa:
    if abs(nn/2.0-a)<tmp:
        tmp=abs(nn/2.0-a)
        c=a

print(nn,c)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
amax = a[-1]
tmp1 = amax + 1
for i in a[:n-1]:
    tmp2 = i - amax/2
    if tmp2 > tmp1:
        break
    else:
        r = i
        tmp1 = abs(tmp2)
print(amax, r)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
m=10**9+1
temp=ans1/2
i=0
for index,val in enumerate(a):
    if val==ans1: continue
    if abs(val-temp)<m:
        m=abs(val-temp)
        i=index
ans2=a[i]
print(ans1,ans2)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter











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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
m = max(A)
nya = m
mid = m/2
for i in range(n):
    if abs(A[i] - mid) <= nya:
        nya = abs(A[i]-mid)
        k = A[i]
print(m,k)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = a[-1]
m = a[0]
C = -1
for i in range(n):
  c = a[i]*(M-a[i])
  if C < c:
    C = c
    m = a[i]
  else:
    break
print(M, m, sep=' ')

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	
	al = lin()
	
	ai = max(al)
	c = al.index(ai)
	pa(c)
	al.pop(c)
	pa(al)
	aj = min(al, key = lambda v : abs((ai/2)-v))
	
	print(ai, aj)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
def check(n, m):
    l = n // 2
    r = l + (n % 2 == 1)

    return min(abs(l - m), abs(r - m))


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

A.sort()
n = A[-1]
pd = float('inf')
for i in range(N - 1):
    a = A[i]
    d = check(n, a)
    if d < pd:
        b = a
        pd = d
print(n, b)

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

Solution (Python):
import bisect

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

if amax//2 in set(a):
  print(amax,amax//2)
else:
  ind = bisect.bisect_left(a,amax//2)
  MIN = min(abs(a[ind]-(amax//2)),abs(a[ind-1]-(amax//2)))
  if amax == 100 and a[ind] == 100:
    print(100,0)
    exit()
  
  if MIN == abs(a[ind]-(amax//2)):
    print(amax,a[ind])
  else:
    print(amax,a[ind-1])

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
A.sort()
first = A[-1]
second = max((min(x, first-x), x) for x in A[:-1])
print(first, second[1])

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = 0
for i in A[:-1]:
    if abs(A[-1] // 2 - i) < tmp:
        tmp = abs(A[-1] // 2 - i)
        ans = i
    elif A[-1] % 2 != 0 and abs(A[-1] // 2 - i + 1) < tmp:
        tmp = abs(A[-1] // 2 - i + 1)
        ans = i
print(A[-1], ans)

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

i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: abs(i/2-a))

print(i, j)

Solution (Python):
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)

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

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

Solution (Python):
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

n = max(A)

if n % 2 == 0:
    nn = n // 2
else:
    nn = (n + 1) // 2

minA = n
aa = n
for a in A:
    if abs(a - nn) <= minA:
        minA = abs(a - nn)
        aa = a
print(n, aa)

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = -1
    aabs = 10**12
    amax = a[N-1]
    
    for i in range(N-1):
        tmp = abs(amax/2 - a[i])
        if tmp < aabs:
            aabs = tmp
            ans = i
    print(a[N-1], a[ans])

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = sorted(map(int, input().split()))
diff = float("inf")
ans = 0
for a in A[:-1]:
    d = abs(a - A[-1] / 2)
    if d < diff:
        ans = a
        diff = d
print(A[-1], ans)

Solution (Python):

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

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

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


i = bisect.bisect_left(a[:-1], m)

if i == n-1:
    i -= 1
elif i > 0 and abs(a[i-1]-m) < abs(a[i]-m):
    i -= 1

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
x = a[-1]/2
ans = 0
dis = float("Inf")
for i in range(n-1):
    if dis > abs(x-a[i]):
        ans = a[i]
        dis = abs(x-a[i])
print(a[-1],ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
m=max(l)
l.remove(m)
if m%2!=0:
  med=(m+1)//2
else:
  med=m//2
mi=m
for ll in l:
  mi=min(mi,abs(ll-med))
if med+mi in l:
  print(m,med+mi)
else:
  print(m,med-mi)

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

idx = bisect.bisect_left(a, mx//2)
if a[idx] == mx//2:
    print(mx, a[idx], sep=" ")
else:
    if a[idx] == mx:
        print(mx, a[idx-1], sep=" ")
        exit()
    if idx > 0:
        if abs(mx//2 - (mx-a[idx])) > abs(mx//2 - a[idx-1]):
            print(mx, a[idx-1], sep=" ")
        else:
            print(mx, a[idx], sep=" ")
    else:
        print(mx, a[idx], sep=" ")

Solution (Python):
def resolve():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    n = A[-1]
    import bisect
    idx = bisect.bisect_left(A, n//2)
    candidates = []
    if idx < N:
        candidates.append(A[idx])
    if idx > 0:
        candidates.append(A[idx-1])

    if abs(n/2 - candidates[0]) < abs(n/2 - candidates[1]):
        print(n, candidates[0])
    else:
        print(n, candidates[1])       

    
if '__main__' == __name__:
    resolve()

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

A.sort()


ncand = A[-1]

ccand = A[0]
nhalf = ncand // 2
diff = abs(nhalf - ccand)

for i in range(1, N-1):
    d = abs(nhalf - A[i])
    if diff >= d:
        ccand = A[i]
        diff = d

print(ncand, ccand)

Solution (Python):


N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

h = A[0]/2
r = 10**9
v = 0
for a in A[1:]:
    if r > abs(a-h):
        r = abs(a-h)
        v = a

print(str(A[0]) + ' ' + str(v))

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

if __name__ == '__main__':
    main()

Solution (Python):
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))])

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
A_max = max(A)
ans = 100

for i in range(n):
    if B[i] > A_max // 2:
        B[i] = A_max-B[i]

B.sort()
if B[-1] in A:
    print(str(A_max)+" "+str(B[-1]))
else:
    print(str(A_max)+" "+str(A_max-B[-1]))

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

Solution (Python):
import bisect
import math

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

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

if j == 0 or a - As[j] > As[j-1]:
  print("{} {}".format(a, As[j]))
else:
  print("{} {}".format(a, As[j-1]))

Solution (Python):
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)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
  elif abs(v-d/2) == abs(f-d/2):
    f = min(f,v)
print(d,f)

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

Solution (Python):
import bisect

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


last = a[-1]
a = a[:-1]

first = 10**10
now = 10**10

for i in a:
    m = min(abs(i-last//2),abs(i-(last+1)//2))
    if now > m:
        now = m
        first = i

print(last,first)

Solution (Python):






from collections import defaultdict











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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
A = sorted(A)
MAX = A[-1]
MIN = A[0]
for i in range(1,n-1):
    if abs(MAX/2 - A[i]) <= abs(MAX/2 - MIN):
        MIN = A[i]
print(MAX,MIN)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N-1):
  if A[i] <= a and A[i+1] >= a:
    if (M-A[i])*A[i] >= (M-A[i+1])*A[i+1]:
      ans = [M, A[i]]
    else:
      ans = [M, A[i+1]]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)

Solution (Python):
import sys


def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = 10**10
    if a[-1]%2 == 0:
        for e in a:
            if abs(e-a[-1]//2) < abs(t-a[-1]//2):
                t = e
    else:
        for e in a:
            if abs(e-(1+a[-1])//2) < abs(t-(1+a[-1])//2):
                t = e
    print(a[-1],t)
if __name__ == '__main__':
    main()

Solution (Python):
import sys


def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = 10**10
    if a[-1]%2 == 0:
        for e in a:
            if abs(e-a[-1]//2) < abs(t-a[-1]//2):
                t = e
    else:
        for e in a:
            if abs(e-(1+a[-1])//2) < abs(t-(1+a[-1])//2):
                t = e
    print(a[-1],t)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
n = A[-1]
k = A[0]
for i in range(1,N-1):
    j = A[i]
    if k<=n//2 and j<=n//2:
        k = max(k,j)
    elif k<=n//2 and j>n//2:
        if k<n-j:
            k = j
    elif k>n//2 and j<=n//2:
        if n-k<j:
            k = j
    elif k>n//2 and j>n//2:
        if n-k<n-j:
            k = j
print(n,k)

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

n = int(input())
a = [int(x) for x in input().split()]
N = max(a)

if N % 2 == 0:
    ans = N // 2
    dis = 10**18
    ans_ = N
    for i in a:
        if abs(i - ans) <= dis:
            dis = abs(i - ans)
            ans_ = i
    print(N, ans_)

else:
    ans1 = N // 2
    ans2 = ans1 + 1
    ans_ = N
    dis = 10**18
    for i in a:
        if abs(i -ans1) <= dis:
            dis = abs(i - ans1)
            ans_ = i
        if abs(i - ans2) <= dis:
            dis = abs(i - ans2)
            ans_ = i
    print(N, ans_)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from bisect import bisect_left


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



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

a1 = A[-1]
tmp = bisect_left(A, a1 // 2)
b1 = A[tmp]

if tmp != 0:
    if abs(b1 / a1 - 1/2) >= abs(A[tmp - 1] / a1 - 1/2):
        b1 = A[tmp - 1]

print (a1, b1)

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

a.sort()
left = a.pop()
yoi = left/2
for i in range(n-1):
    if a[i] >= yoi:
        a[i] = (abs(a[i]-yoi), 1)
    else:
        a[i] = (abs(a[i]-yoi), -1)
a.sort()
right = abs(int(a[0][0]+a[0][1]*yoi))
print(left, right)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()
    L = A[N-1]
    ans = -1
    for a in A[:N-1]:
        if abs(L/2 - a) < abs(L/2 - ans): ans = a
    print(L, ans)


    return 0

if __name__ == "__main__":
    solve()

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
x = max(A)
A.pop(A.index(max(A)))
ans = A[0]
ABS = abs(x//2-A[0])
for a in A[1:]:
    if ABS > abs(x//2-a):
        ans = a
        ABS = abs(x//2-a)
print(x,ans)

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

m = max(a)
res = 1e10
ans = 0
for i in a:
    if i != m:
        if abs(m//2-i) < res:
            res = abs(m//2-i)
            ans = i

print(m,ans)

Solution (Python):
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])

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans1 = max(A)
if A[1] == 0:
    print(ans1, 0)
for i in range(n):
    if i == 0:
        pass
    elif i == 1:
        ans2 = A[i]
        now_div = abs(ans1/2 - ans2)
    else:
        chk = A[i]
        chk_div = abs(ans1/2 - chk)
        if chk_div > now_div:
            print(ans1, ans2)
            exit()
        if abs(ans1/2 - chk) < abs(ans1/2 - ans2):
            ans2 = chk
            now_div = abs(ans1/2 - ans2)

Solution (Python):
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)

Solution (Python):

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

m = a[-1]
a_minus_m = [abs(aa-m/2) for aa in a]

mi = 10**10
i_mi=0
for i,aa in enumerate(a_minus_m):
    if aa<mi:
        mi =aa
        i_mi=i

r = a[i_mi]
print(m,r)

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

a.sort()

large = max(a)
a.remove(large)
min_list = [0, large/2]
for i in a:
    if abs(i - large/2) < min_list[1]:
        min_list = [i, abs(i - large/2)]

print(large, min_list[0])

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

a.sort()

large = max(a)
a.remove(large)
min_list = [0, large/2]
for i in a:
    if abs(i - large/2) < min_list[1]:
        min_list = [i, abs(i - large/2)]

print(large, min_list[0])

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
A = sorted(A)
ma = A[-1]
mi = A[0]
for i in range(n-1):
    if abs(A[i] - ma/2) <= abs(mi - ma / 2):
        mi = A[i]
print(ma,mi)

Solution (Python):


import sys
readline = sys.stdin.readline

n = int(readline())
A = list(int(a) for a in readline().split())
A.sort(reverse=True)

N = A[0]
R = 0
tmpR = 0
for i in range(1, n):
    tmp = min(A[i], N-A[i])
    if tmpR < tmp:
        tmpR = tmp
        R = A[i]       

print(N, R)

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

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


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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
maxkouho = a[-1]
k = maxkouho/2
maxans = 10**18
ans = 0
for i in range(n-1):
	s = abs(a[i]-k)
	if s < maxans:
		maxans = s
		ans = a[i]
print(maxkouho, ans)

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

ansn = max(a)
b = list(map(lambda x: abs(x-ansn/2), a))

minu = 10**9+1
ind = 0

for i in range(n):
  if b[i] <= minu:
    minu = b[i]
    ind = i
    
print(str(ansn)+" "+str(a[ind]))

Solution (Python):

"""
Created on Thu Jun  4 19:55:07 2020

@author: NEC-PCuser
"""

def binary_search(b, a):
    low = 0
    high = len(b) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = b[mid]
        if guess == a:
            return b[mid]
        elif guess > a:
            high = mid - 1
        else:
            low = mid + 1
    abs_low = a * 4
    if len(b) > low: 
        abs_low = abs(b[low] - a)
    abs_high = abs(b[high] - a)
    return b[high] if abs_low > abs_high else b[low]
    
            


if __name__ == "__main__":
    n = int(input())
    
    a = list(map(int, input().split()))
    
    a.sort()
    
    b = a[0:len(a)-1]
    c = binary_search(b, a[len(a)-1] / 2)
    print(str(a[len(a)-1]) + " " + str(c))

Solution (Python):
import numpy as np

n = int(input().strip())
A = list(map(int,input().strip().split(' ')))
sorted_A = sorted(A)
ai=sorted_A[-1]
print(ai)
del sorted_A[-1]
tmplist=np.array([min(i,ai-i) for i in sorted_A])
maxidx = np.argmax(tmplist)

print(sorted_A[int(maxidx)])

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
AS = sorted(list(set(A)))
n = AS[-1]
checkAS = len(AS)-1
nHalf = n/2
min = 10**10


for i in range(checkAS):
    temp = abs(AS[i]-nHalf)
    if min > temp:
        r = AS[i]
        min = temp

print(str(n) + ' ' + str(r))

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

Solution (Python):
n = int(input())
A = map(int, input().split())
A = sorted(A)
maxa = max(A)

from bisect import bisect_left
m = (maxa+1)//2
l2 = bisect_left(A, m)

if abs(A[l2] - m) >= abs(A[l2-1] - m):
    print(maxa, A[l2-1])
else:
    print(maxa, A[l2])

Solution (Python):
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)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
m1 = A[-1]
m2 = m1 // 2 + int(m1 % 2 == 1)
ans = [m1, 0]
tmp = 10**9 + 1

for a in A[:len(A) - 1]:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)

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


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    A.sort()
    n = N-1
    p = bisect_left(A, A[n] / 2)
    low = max(0, p - 1)
    high = min(N - 1, p)
    if n == high:
        return "%d %d" % (A[n], A[low])
    elif A[low] > A[n] - A[high]:
        return "%d %d" % (A[n], A[low])
    else:
        return "%d %d" % (A[n], A[high])


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
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)

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
x = dat[-1]
xx = x / 2
dat = dat[:-1]
mindiff = 999999999999999999999999999
minnum = None
for i in range(n-1):
    if abs(xx-dat[i]) < mindiff:
        mindiff = abs(xx-dat[i])
        minnum = dat[i]
print(x, minnum)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

n = INT()
a = LIST()

p = max(a)
m = (p+1)/2 - 0.1
b = []
a.remove(p)
for x in a:
	b.append((x, abs(x-m)))

b.sort(key = lambda x:x[1])

print(p, b[0][0])

Solution (Python):
import bisect

N = int(input())
a = set(map(int,input().split()))
A = sorted(list(a))
M = max(A)
num = M//2

index = bisect.bisect_right(A,num)

if index > 0 and abs(num - A[index]) > abs(num - A[index-1]):
    index = index-1


if M != A[index]:
    print(M,A[index])
else:
    print(M,A[index-1])

Solution (Python):
n = int(input())
a_list = list(map(int,input().split()))
a_list.sort()
a_max = a_list.pop()
result = []
import math
for a in a_list:
  result.append(abs(math.ceil(a_max /2) - a))

print(a_max,a_list[result.index(min(result))])

Solution (Python):
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)

Solution (Python):
import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))

big = arr.max()
arr = np.delete(arr, arr.argmax())

if big % 2 == 0:
    small = arr[(np.abs(arr - big // 2)).argmin()]
else:
    a = (np.abs(arr - (big + 1) // 2)).min()
    b = (np.abs(arr - (big) // 2)).min()
    if a <= b:
        small = arr[(np.abs(arr - (big + 1) // 2)).argmin()]
    else:
        small = arr[(np.abs(arr - big // 2)).argmin()]

print(big, small)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    a.sort()
    a_max=a[-1]
    b_max=-1
    for i in range(n-1):
        if b_max<min(a[i],a_max-a[i]):
            b_max=a[i]

    print(a_max,b_max)

if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
y1 = x//2
y2 = x//2 + 1
sa1, sa2 = float("inf"), float("inf")
z1, z2 = 0, 0
for i in range(n-1):
    if sa1 > abs(y1 - a[i]):
        sa1 = abs(y1-a[i])
        z1 = a[i]
    if sa2 > abs(y2 - a[i]):
        sa2 = abs(y2 - a[i])
        z2 = a[i]

if sa1 > sa2:
    print(x, z2)
else:
    print(x, z1)

Solution (Python):
import bisect

n,*a = map(int, open(0).read().split())
if n == 2:
    print(*a)
else:
    a.sort()
    f = a[-1]
    h = f / 2
    bs = bisect.bisect_left(a,h)
    if abs(a[bs-1]-h) >= abs(a[bs]-h):
        s = a[bs]
    else:
        s = a[bs-1]
    print(f,s)

Solution (Python):
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))