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,a=open(0)
*a,=map(int,a.split())
m=max(a)
print(m,min((abs(m-2*i),i)for i in a)[1])

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

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

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

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

maxi = 0
i = -1
key = a[i] // 2
for j in range(n):
    if a[j] > key:
        break


if abs(a[j-1] - key) >= abs(a[j] - key) and j < n-1:
    ans = [a[i], a[j]]
else:
    ans = [a[i], a[j-1]]














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

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

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

a.sort(reverse=True)
ans=a[1]
for i in range(n-1):
    if min(a[0]-a[i+1],a[i+1])>min(a[0]-ans,ans):
        ans=a[i+1]
    
print(a[0],ans)

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

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

a.sort(reverse=True)
ideal = a[0]//2
dif_mn = 10**9

for i in range(1,n):
    tmp = a[0]-a[i] if a[i] > ideal else a[i]
    dif = ideal-tmp
    if dif < dif_mn:
        r = a[i]
        dif_mn = dif

print(a[0], r)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ai = max(a)
a.remove(ai)
aj = a[0]
for i in a:
    if abs(ai/2-i) < abs(ai/2-aj):
        aj = i
print(ai,aj)

Solution (Python):
import bisect

n=int(input())
a=list(map(int,input().split()))
a.sort()
k=bisect.bisect_left(a,a[-1]/2)

if k==n-1:
    print(a[-1],a[-2])
elif k==0:
    print(a[-1],a[0])
else:
    if a[-1]/2-a[k-1]<a[k]-a[-1]/2:
        k-=1
    print(a[-1],a[k])

Solution (Python):
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 2:
    print(A[1], A[0])
    exit()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)

Solution (Python):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = sorted(input_int_list())
    ans_a = A[-1]
    ans_b = A[0]
    for a in A:
        tmp = a
        if tmp > ans_a - a:
            tmp = ans_a - a
        if tmp > ans_b:
            ans_b = a
    print(ans_a, ans_b)

    return


if __name__ == "__main__":
    main()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n = I()
    a = LI()

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

    r = (float("inf"), -1)
    half = mx//2
    
    if mx%2 == 0:
        for x in a:
            sa = abs(x-half)
            if sa < r[0]:
                r = (sa, x)
    else:
        for x in a:
            sa = min(abs(x-half), abs(x-(half+1)))
            if sa < r[0]:
                r = (sa, x)

    ans = (mx, r[1])
    print(*ans)
            

                    


main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
check = a[-1] / 2
MIN = 10 ** 10

for i in range(n - 1):
    if abs(a[i] - check) < MIN:
        keep = i
        MIN = abs(a[i] - check)

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter





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

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
a = na()
a.sort(reverse=True)
ans = -1
t = a[0]
target = (a[0] + (2 - 1)) // 2

pre = inf
if n == 2:
    print(max(a), min(a))
    sys.exit()
for i in range(1, n):
    
    dif = abs(target - a[i])
    if pre < dif:
        print(t, a[i-1])
        sys.exit()
    else:
        pre = dif

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 10**9
A.remove(maxA)
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)

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

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

x = a[0] // 2
l = 1
r = N - 1
while r - l > 1:
    mid = l + (r - l) // 2
    if a[mid] < x:
        r = mid
    else:
        l = mid
if abs(x - a[l]) <= abs(x - a[r]):
    print(a[0], a[l])
else:
    print(a[0], a[r])

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

lis.sort()

ans1 = lis[-1]

lis = lis[:-1]
half = ans1/2

ans2 = 0
length = 10**9+7

for i in lis:
    t = abs(half - i)
    if t < length:
        length = t
        ans2 = i
    

print(ans1, ans2)

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

MAXN = N+1
p = 10**9+7
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % p)
def nCr(n, r, mod=p):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

MA = max(A)
out = [MA,0]
MA2 = MA//2
mincand = 10**9
for i in range(N):
    if mincand>abs(A[i]-MA2) and A[i]!=MA:
        mincand = abs(A[i]-MA2)
        out[1] = A[i]
print(*out)

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

if __name__=="__main__":
    n,a = getval()
    main(n,a)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,A=ilint()
n=max(A)
r=0
tmp=INF
for a in A:
    if a!=n and abs(n//2-a)<tmp:
        r=a
        tmp=abs(n//2-a)
print(n,r)

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

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

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

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

r_=n/2

a_before=''
for a in A[:-1]:
    if a >= r_:
        break
    a_before = a
    
if abs(r_-a) >= abs(r_-a_before):
    r = a_before
else:
    r = a
    
print(n,r)

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

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

m = float('inf')
ans = 0
mea = A[0]/2
for i in range(n-1):
    if m > abs(mea-A[i+1]):
        ans = A[i+1]
        m=abs(mea-A[i+1])
print(A[0], ans)

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

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






x = max(a)
y = float("inf")
for ai in a:
    if abs(x / 2 - ai) < abs(x / 2 - y) and ai < x:
        y = ai
print(x, y)

Solution (Python):
def binary_search(A, target):
  left = 0 
  right = len(A)
  while(3 <= right - left):
    index = (left + right) // 2
    if(A[index] < target):
      left = index
    else:
      right = index + 1
  return left
  
N = int(input())
A = list(map(int, input().split()))
A.sort()
target = A[N - 1] / 2
if(target <= A[0]): ai = A[0]
elif(A[N - 2] <= target): ai = A[N - 2]
else:
  index = binary_search(A[:N - 1], target)
  ai = A[index] if(abs(A[index] - target) < abs(A[index + 1] - target)) else A[index + 1]
print(A[N - 1], ai)

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

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

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

a.sort()

i = bisect(a, (a[-1]+1) // 2)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
sort_A=sorted(A)
max_A=sort_A[-1]
answer=[]
half_A=max_A//2
number=pow(10,9)
answer=0
for n in range(N-1):
    if number>=abs(sort_A[n]-half_A):
        answer=n
        number=abs(sort_A[n]-half_A)
print(max_A,sort_A[answer])

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

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n - 1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
center = int((a_max + 1) / 2)
a_set = set(a_list)
diff_min = a_max
ans = 0
for a in a_set:
    diff = abs(a-center)
    if diff_min > diff:
        diff_min = diff
        ans = a

print(a_max, ans)

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1]
def bigger(ind):
    global 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])

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = max(a)
    r = 0
    chk = 10**9+1
    for x in a:
        if abs(x-l//2) < chk and x != l:
            r = x
            chk = abs(x-l//2)
    print(l, r)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
dif = 1000000000
best = a[0] // 2
ans = 0
for i in range(1, n):
    new_dif = abs(best - a[i])
    if dif <= new_dif:
        ans = a[i - 1]
        break
    dif = new_dif
else:
    print(a[0], a[1])
    exit()
print(a[0], ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
ma = a[-1]
mn = float("inf")
mni = -1
for i in range(n-1):
  if abs(2*a[i]-ma) < mn:
    mn = abs(2*a[i]-ma)
    mni = i
print(ma,a[mni])

Solution (Python):
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
else:
    if idx != 0:
        if abs(A[idx - 1] - t) <= abs(A[idx] - t):
            idx = idx - 1

print(' '.join([str(A[-1]), str(A[idx])]))

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
an = a[-1]
a = a[:n - 1]
res = 10 ** 9
ans = 0
if an % 2 == 0:
    mid_l = an // 2
    mid_r = an // 2
else:
    mid_l = an // 2
    mid_r = (an + 1) // 2

for i in range(n - 1):
    if a[i] <= mid_l:
        if mid_l - a[i] < res:
            ans = a[i]
            res = mid_l - a[i]
    elif mid_r <= a[i]:
        if a[i] - mid_r < res:
            ans = a[i]
            res = mid_r - a[i]

print(an, ans)

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

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

Solution (Python):
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = a[-1]
    s = t/2
    z = a[0]
    for i in range(1,n-1):
        if abs(a[i]-s)<abs(z-s):
            z = a[i]
    print(t,z)

if __name__ == "__main__":
    main()

Solution (Python):



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

if __name__ == '__main__':
  main()

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


if __name__ == '__main__':
    main()

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


if __name__ == '__main__':
    main()

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

Solution (Python):
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))
    else:
        if a[c]-x//2>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

        
else:
    if x//2 in a :
        print("{} {}".format(x,x//2))
    elif x//2+1 in a:
        print("{} {}".format(x,x//2+1))
    else:
        if a[c]-(x//2+1)>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

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

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

m = max(lst)
r = m//2
k = float('inf')

for i in range(n):
  if lst[i] != m and abs(r-lst[i]) < abs(r-k):
    k = lst[i]
    
print(m, k)

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] < A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])

Solution (Python):

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)






ai2=ai/2

jj=bisect(a,ai2)

if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj=jj-1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Solution (Python):


import bisect

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

a.sort()

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




















x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])


ans.sort()

print(x, ans[0][1])

Solution (Python):


import bisect

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

a.sort()

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




















x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

print(x, ans[0][1])

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mini = [[] for _ in range(n)]
for i, v in enumerate(a):
    r = maxa - v
    mini[i] = [v, abs(v - r)]
mini.sort(key=lambda x: x[1])
if n == 2:
    print(maxa, min(a))
else:
    print(maxa, mini[0][0])

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

if n==2:
    print(max(l),min(l))
    exit()
maxi = max(l)
med = maxi//2
d = 10**9+1
ans = -1

for i in range(n):
    x = l[i]
    if l[i] > med:
        x = maxi-l[i]
    if med-x < d:
        d = med-x
        ans = l[i]

print(maxi,ans)

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

k = []
max_a = a[-1]
max_half = max_a / 2
for i in range(n):
    if a[i] >= max_half:
        if i == 0:
            k.append(a[i])
            break
        k.append(a[i])
        k.append(a[i-1])
        break
ans = 0
if len(k) == 1:
    ans = k[0]
else:
    if abs(max_half - k[0]) < abs(max_half - k[1]):
        ans = k[0]
    else:
        ans = k[1]

print(max_a, ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    As.sort()
    max_num = max(As)

    res = 10**9 + 1
    if max_num % 2 == 0:
        if max_num //2 in As:
            res = max_num //2
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
    else:
        if max_num //2 in As:
            res = max_num //2
        elif max_num // 2 + 1 in As:
            res = max_num //2 + 1 
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
                if abs(max_num //2 + 1 - res) > abs(max_num //2 + 1 - item):
                    res = item


    print(max(As), res)

if __name__ == "__main__":
    resolve()

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort(reverse=True)
    n = max(A)
    med = n/2
    r = INF
    d = INF
    for a in A[1:]:
        if abs(a-med)<d:
            r = a
            d = abs(a-med)
    print(n,r)



if __name__ == '__main__':
    main()

Solution (Python):
_ = int(input())
a = sorted(list(map(int, input().split())))
num0, num1, val = a[-1], 0, float('inf')

for i in a[:-1]:
    val0 = abs(i-num0/2)
    if val0 < val:
        num1 = i
        val = val0
print(num0, num1)

Solution (Python):

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)

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

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

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

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

t.sort()

max_value = t[-1]

mid_value = 0

for a in t:
    if abs(max_value/2-a) < abs(max_value/2-mid_value):
        mid_value = a

print(max_value, mid_value)

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

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

Solution (Python):
def resolve():
    import bisect
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    if N == 2:
        print(max(A), min(A))
        return
    maxA = A[-1]
    half = maxA / 2
    i = bisect.bisect_left(A, half)
    if A[i] - half < half - A[i - 1]:
        print(maxA, A[i])
    else:
        print(maxA, A[i - 1])


resolve()

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort()
    n = max(A)

    i = 0
    while i < N - 2 and 2 * A[i] < n:
        i += 1

    if i in (0, N - 1):
        r = A[i]
    elif abs(2 * A[i] - n) < abs(2 * A[i - 1] - n):
        r = A[i]
    else:
        r = A[i - 1]

    print(n, r)
    return


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
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])
    exit()
if median_ind == N-1:
    print(A[-1],A[-2])
    exit()

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

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