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):
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()

def comb(n, k):
    ans = 1
    for i in range(k):
        ans = ans * (n - i) // (i + 1)
    return ans


i = bisect_left(a, a[-1]/2)
if i > 0:
    if abs(a[-1]/2 - a[i]) < abs(a[-1]/2 - a[i-1]):
        print(a[-1], a[i])
    else:
        print(a[-1], a[i-1])
else:
    print(a[-1], a[i])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
d = a[0]
t = mx/2
if n==2:
    print(max(a),min(a))
    exit()
for i in a:
    if abs(i-t)<abs(d-t):
        d = i
print(mx,d)

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

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

Solution (Python):
from bisect import bisect_left

n = input()
a = list(map(int, input().split()))
a.sort()
N = a[-1]
i = bisect_left(a, (N + 1) // 2)
K1 = a[i]
K2 = a[i - 1]
if K1 != N and N - K1 > K2:
    K = K1
else:
    K = K2
print(N, K)

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

Solution (Python):
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(str(ans_a) + ' ' + str(ans_b))

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

ai = max(a)
a.remove(ai)
b = list(map(lambda x: abs(x - ai / 2), a))
aj = min(b)+(ai/2) if min(b)+(ai/2) in a else min(b)-(ai/2)
print(ai, abs(int(aj)))

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

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) <= diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)

Solution (Python):
import bisect

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

x = num_list[-1]
x_half = x / 2
y = bisect.bisect_left(num_list,x_half)
if y != 0:
    if y == n-1:
        y -= 1
    else:
        if abs(num_list[y] - x_half) >= abs(num_list[y-1] - x_half):
            y -= 1
print(x,num_list[y])

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
ans1=a[0]
num=99999999999999
for i in range(1,n):
    if ans1%2==0:
        u=abs(a[i]-ans1//2)
        if num>u:
            num=u
            ans2=a[i]
    else:
        u,v=abs(a[i]-ans1//2),abs(a[i]-(ans1//2+1))
        if num>min([u,v]):
            num=min([u,v])
            ans2=a[i]
print(ans1,ans2)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
A.remove(mx)
ans = 10**9
ans_dist = ans
med = mx // 2

for a in A:
    if ans_dist > abs(med - a):
        ans, ans_dist = a, abs(med - a)
print(mx, ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
ans = mx * 3
med = mx // 2
for a in A:
    if mx == a:
        continue
    if abs(med - ans) > abs(med - a):
        ans = a
print(mx, ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = max(A) * 3
mx = max(A)
med = mx // 2
for a in A:
    if mx == a:
        continue
    if abs(med - ans) > abs(med - a):
        ans = a
print(mx, ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=max(a)
c=b
d=0
for i in a:
  if c>=abs(b/2-i):c=abs(b/2-i);d=i
print(b,d)

Solution (Python):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	h = A[-1]//2
	c = A[0]
	for a in A:
		if a == A[-1]:
			continue
		if abs(h-a) <= abs(h-c):
			c = a
	print(" ".join([str(A[-1]), str(c)]))


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
x=a[-1]
ans=[x,0]
for i in a:
    if x>i and abs(x//2-i)<abs(x//2-ans[1]):
        ans[1]=i
    if x>i and x%2 and abs((x+1)//2-i)<abs((x+1)//2-ans[1]):
        ans[1]=i

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

Solution (Python):
import math
import sys


if __name__ == '__main__':
    n = int(input())
    a_list = list(map(int, input().split()))

    max_a = max(a_list)
    a_list.remove(max_a)

    min_diff = sys.maxsize
    answer1 = max_a
    answer2 = -1
    for i in range(n-1):
        diff = math.fabs(max_a/2 - a_list[i])
        if min_diff > diff:
            min_diff = diff
            answer2 = a_list[i]

    print(str(answer1) + " " + str(answer2))

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

if n-a[i]>min(a[i-1],n-a[i-1]):
    r = a[i]
else:
    r = a[i-1]
print('{} {}'.format(n,r))

Solution (Python):
import math
import bisect
N = int(input())
a = [int(x) for x in input().split()]

a.sort()
upper=bisect.bisect_left(a,a[-1]/2)
lower=upper-1 if upper>0 else 0
b = a[lower] if abs(a[-1]/2-a[lower])<=abs(a[-1]/2-a[upper]) else a[upper]
print(a[-1],b)

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

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

comb1 = max(a)
comb2 = comb1//2
a.sort()
p = 0
keep = float("inf")
for i in range(n):
    if abs(a[i] - comb2) <= keep:
        p = a[i]
        keep = abs(a[i]-comb2)

if comb1 == p:
    print(comb1,0)
else:
    print(comb1,p)

Solution (Python):
n=int(input())
a_list=list(map(int,input().split()))
a_list.sort()
M=a_list[n-1]
m=a_list[0]
d=M/2-m
for i in a_list[:n-1]:
    if abs(M/2-i)<d:
        d=abs(M/2-i)
        m=i
print(M)
print(m)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[n-1]
a=a[0:n-1]
y=x
z=x
for j in range(n-1):
  if z>=abs(abs(x-a[j])-a[j]):
    y=a[j]
    z=abs(abs(x-a[j])-a[j])
print(x,y)

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

a = sorted(a)

import numpy as np
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
  
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

tmp0 = a[n-1] / 2
tmp1 = getNearestValue(a[0:n-1], tmp0)
print(a[n-1], tmp1)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a)

    mx = a[-1]
    
    midiff = abs(mx/2 - a[0])
    minum = a[0]

    for i in a[:-1]:
        if abs(i - mx/2) < midiff:
            midiff = abs(mx/2 - i)
            minum = i
    
    print(mx, minum)

    

solve()

Solution (Python):

n = int(input())
As = list(map(int,input().split(" ")))

As.sort()
if As[-1] % 2 == 0:
    r = As[-1]//2
    l = As[-1] // 2
else:
    r = As[-1] // 2
    l = As[-1] -r

ans = 10e9
for a in As:
    if abs(a-r) < abs ( ans - r ):
        ans = a
    if abs(a-l) < abs ( ans - l ):
        ans = a

print(As[-1],ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
N = max(A)
l,r = 0,0
for i in A:
    if i > N/2:
        r = i
        break
    l = i
if N/2 - l > r - N/2:
    print(N,r)
else:
    print(N,l)

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

Solution (Python):
"""
combination
右が固定 : 左は大きければ大きいほうが良い
左が固定 : 右は1/2に近ければ近いほうが良い
これを左から順に探していくので良い
"""

N = int(input())
As = list(map(int,input().split()))
As = sorted(As, reverse=True)
l = As[0]
r = As[1]

for a in As[2:]:
    if abs(l/2-a) < abs(l/2-r):
        r = a
print(l,r)

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

a.sort()

ai = a.pop(-1)

ai_half = ai / 2

dist = []
for i in range(n-1):
    dist.append(abs(a[i] - ai_half))

idx = min(range(n-1), key=dist.__getitem__)

aj = a[idx]

print(ai, aj)

Solution (Python):

import sys
import bisect


def solve(n: int, A: "List[int]"):
    A.sort()
    n = A[-1]
    r = n/2.0

    min_diff = float("inf")
    bi = 0
    for i in range(len(A)-1):
        if abs(A[i]-r) < min_diff:
            min_diff = abs(A[i]-r)
            bi = i

    print(n,A[bi])








def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(n) ]  
    solve(n, a)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys


def solve(n: int, a: "List[int]"):
    mx = max(a)
    a.sort()
    l = -1
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if a[m] > (mx + 1) // 2:
            r = m
        else:
            l = m
    target = (mx + 1) // 2
    if r == n - 1 or abs(target - a[l]) < abs(target - a[r]):
        print(mx, a[l])
    else:
        print(mx, a[r])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(n) ]  
    solve(n, a)

if __name__ == '__main__':
    main()

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

A.sort()

def comb(x, y):
    p = 1
    d = 1
    for i in range(y):
        p *= x - i
        d *= y -i
    return p // d

diff = -1
ans = [A[n-1], -1]
for a in A[:n-1]:
    new_diff = min(a, A[n-1]-a)
    if diff < new_diff:
        diff = new_diff
        ans[1] = a
print(*ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
amax=arr[0]
rbest=amax//2
arr=arr[1:]
r=0
diff=10**18
for i in range(n-1):
  tmp=abs(rbest-arr[i])
  if tmp<diff:
    diff=tmp
    r=arr[i]
print(amax,r)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    alist = intina()

    alist.sort()

    m = alist[-1]

    ind = binl(alist, m // 2)
    ind1 = ind - 1 if ind > 0 else None
    ind2 = ind

    mmlist = [m // 2]
    if m & 1:
        mmlist.append(m // 2 + 1)

    c1 = float('inf')
    if ind1 is not None and ind1 != len(alist) - 1:
        for mm in mmlist:
            c1 = min(c1, abs(alist[ind1] - mm))

    c2 = float('inf')
    if ind2 != len(alist) - 1:
        for mm in mmlist:
            c2 = min(c2, abs(alist[ind2] - mm))

    if c1 < c2:
        print('%d %d' % (m, alist[ind1]))
    else:
        print('%d %d' % (m, alist[ind2]))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans_1 = max(a)
check_2 = ans_1 / 2
a.sort()
ans_box = [0]*n
for i in range(n):
    ans_box[i] = abs(a[i]-check_2)
ans_2 = a[ans_box.index(min(ans_box))]
print(ans_1,ans_2)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
A.sort()
ai=A[-1]
tA=A[:n-1]
aj=0
for i in range(n-1):
    aj=max(aj,min(tA[i],ai-tA[i]))
if aj in tA:
    print(ai,aj)
else:
    print(ai,ai-aj)

Solution (Python):

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

tmp = 10 ** 9
ans = 1
for i in range(1,N):
  if abs(a[0]/2 - a[i]) < tmp:
    tmp = abs(a[0]/2 - a[i])
    ans = a[i]

    
s = str(a[0]) + " " + str(ans)
print(s)

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


if N == 2:
    print(A[-1], A[0])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[-1], A[0])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
if A==[100,0]:print(100,0)
else:
    Ai=max(A)
    Aj=0
    curdif=10000000000000000
    for a in A:
        if abs(Ai/2-a)<curdif:
            Aj=a
            curdif=abs(Ai/2-a)
    print(Ai,Aj)

Solution (Python):
import bisect
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
l=A[-1]
A=A[:-1]
n=bisect.bisect_left(A,l//2)
if n==len(A):
  s=A[-1]
else:
  s=A[n]
if n>1 and abs(A[n-1]-l/2)<abs(A[n]-l/2):
  s=A[n-1]
print(l,s)

Solution (Python):

import bisect





def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1

        ans_kari_1 = min(data[left_ind], data[i] - data[left_ind])
        ans_kari_2 = min(data[right_ind], data[i] - data[right_ind])


        if ans_kari_1 > ans_kari_2:
            ans_list = [data[i], data[left_ind]]
        else:
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






if __name__ == '__main__':
    main()

Solution (Python):

N=input()
A=map(int,raw_input().split())
A.sort()
n=A[-1]
med=n/2
p=0
mi=1145141919810
for i,a in enumerate(A):
    b=min(a,n-a)
    if abs(b-med) < mi:
        p=i; mi=abs(b-med)
print("%d %d"%(n,A[p]))

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

q = max(A)
p = q//2
tmp = p+1
for i in range(N):
    if q != A[i]:
        if tmp > abs(A[i]-p):
            tmp = abs(A[i]-p)
            ans = A[i]

print(q, ans)

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

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
As.sort()
a1 = As[-1]
a2 = 0
a3 = As[-1]
m = a1//2
for a in As:
    if a > a2 and a <=m:
        a2 = a
    elif a < a3 and m < a:
        a3 = a
if m % 2 == 0:
    if abs(a2-m) <= abs(a3-m):
        print(a1, a2)
    else:
        print(a1, a3)
else:
    if abs(a2-m) <= abs(a3-m-1):
        print(a1, a2)
    else:
        print(a1, a3)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
print(max_a, min(A, key=lambda a:abs(max_a-a*2)))

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

Solution (Python):
from bisect import bisect_left
N=int(input())
inp=[int(i)for i in input().split()]
inp.sort()
ma=inp[-1]
idx = bisect_left(inp[0:-1], ma//2)
if idx >= len(inp)-1:
    if idx >= len(inp)-1:
        print(ma, inp[idx-1])
    else:
        print(ma, inp[idx])
elif abs(inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]) or abs(ma - inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]):
    print(ma, inp[idx])
else:
    print(ma, inp[idx-1])

Solution (Python):
from bisect import bisect_left
N=int(input())
inp=[int(i)for i in input().split()]
inp.sort()
ma=inp[-1]
idx = bisect_left(inp[0:-1], ma//2)

if idx >= len(inp)-1:
    
    if idx >= len(inp)-1:
        print(ma, inp[idx-1])
    else:
        print(ma, inp[idx])
elif abs(inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]) or abs(ma - inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]):
    
    print(ma, inp[idx])
else:
    
    print(ma, inp[idx-1])

Solution (Python):
import bisect
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
from operator import mul

import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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



n = A[-1]

r = bisect.bisect_left(A, n / 2)

if abs(A[r - 1] - n / 2) < abs(A[r] - n / 2):
    r -= 1
while A[r] == n:
    r -= 1
print(n, A[r])

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

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A.sort()
ai=A[-1]
A=A[:-1]
ans=10**19
aj=0
if ai%2==0:
    a=ai//2
    for i in range(n-1):
        if ans>abs(A[i]-a):
            ans=abs(A[i]-a)
            aj=A[i]
    print(ai,aj)
else:
    a=(ai-1)//2
    b=a+1
    for i in range(n-1):
        if ans>min(abs(A[i]-a),abs(A[i]-b)):
            ans=min(abs(A[i]-a),abs(A[i]-b))
            aj=A[i]
    print(ai,aj)

Solution (Python):
import sys
import math
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
A = na()
A.sort()
n = A[-1]
m = n*1.0/2

inf = 10**9
ans=0
for i in range(N):
    if(abs(A[i]-m)<inf):
        inf= abs(A[i]-m)
        ans = A[i]
print(n,ans)

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

A.sort(reverse = True)

x = A[0]
y = 0
temp = 0

for yy in A:
    d = min(yy, x-yy) 
    if d > temp:
        temp = d
        y = yy

ans = (x,y)
print(*ans)

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

Solution (Python):
from operator import itemgetter

n = int(input())
a = sorted(list(map(int, input().split())))
max_n = a.pop(-1)
x = max_n / 2
a_ = sorted([(x, abs(max_n/2-x)) for x in a], key=itemgetter(1))

print(max_n, a_[0][0])

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

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

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:1]:
    r = binary_search(c/2)
    
    
        
    ans = str(c)+" "+str(r)
print(ans)

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

a.sort()

ai = a[-1]

aj = a[0]
for i in a[:-1]:
    if abs(ai//2 + ai % 2- aj) > abs(ai//2 + ai % 2 - i):
        aj = i

print(ai, aj)

Solution (Python):
import sys


fin = sys.stdin.readline
n = int(fin())
a_list = sorted(int(elem) for elem in fin().split())

num_elems = a_list[-1]
num_choices = -1
max_diff = float('-inf')
for a in a_list[:-1]:
    diff = min(num_elems - a, a)
    if diff > max_diff:
        num_choices = a
        max_diff = diff

print(num_elems, num_choices)

Solution (Python):
import bisect

N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
M=b[N-1]
i=bisect.bisect_left(b,M/2)

if i==0: print(M,b[0])
elif abs(M/2-b[i-1])<=abs(M/2-b[i]): print(M,b[i-1])
else: print(M,b[i])

Solution (Python):

import sys


def solve(n: int, a: "List[int]"):
    a.sort()
    n = a[-1]
    a = a[0:len(a)-1]
    maxDiff = 0
    maxK = a[0]
    for k in a:
        if maxDiff <= min(n-k, k):
            maxDiff = min(n-k, k)
            maxK = k
    print(str(n) + " " + str(maxK))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(n)]  
    solve(n, a)


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)

z = A / 2
d = float('INF')
da = 0
for i in range(n - 1):
    
    if d > abs(a[i] - z):
        da = a[i]
        d = abs(da - z)
print(A, da)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
aj = max(A)
temp = 10000000000
for a in A:
    if a != aj:
        if temp > abs(int(aj/2+0.5)-a):
            ai = a
            temp = abs(int(aj/2+0.5)-a)
            
print(aj,ai)

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

ans1 = a[0]
dif = 1e10
for i in a:
    if i==ans1:
        continue
    if abs(i-ans1//2)<dif:
        ans2 = i
        dif = abs(i-ans1//2)

print(ans1, ans2)

Solution (Python):
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
k = 10**10
for i in range(1,n):
    k = min(k,abs(A[0]/2 -A[i]))
    if k == abs(A[0]/2 -A[i]):
        ans = [A[0],A[i]]
print(ans[0],ans[1])

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

max_comb = -1
k = lst[0]
mid = k/2
high = 1
low = N-1
while abs(high - low) > 1:
    if mid - lst[(high+low)//2] ==0:
        high = (high+low) // 2
        low = high
        break
    elif mid - lst[(high+low)//2] > 0:
        low = (high+low)//2
    else:
        high = (high+low)//2
p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
print(k, p)

Solution (Python):
import bisect
N=int(input())
A=[int(x) for x in input().split()]
A.sort()
At=A[-1]
i=bisect.bisect_left(A,At/2)
if i==0:
  As=A[i]
elif i==N-1:
  As=A[i-1]
else:
  As=A[i] if A[i]-At/2<At/2-A[i-1] else A[i-1]
print(At,As)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**9
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])

Solution (Python):
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 >= ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007



def A():
    a,b = LI()
    if not (a*b)%2:
        print("Even")
    else:
        print("Odd")
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = I()
    a = LI()
    f = 0
    for j in range(100000):
        for i in range(n):
            if a[i]%2:
                f = 1
                break
            a[i] //= 2
        if f:break
    print(j)
    return


def D():
    a,b,c,x = IR(4)
    su = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:su += 1
    print(su)
    return


def E():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)
    return


def F():
    s = input()
    while s:
        if s[:11] == "dreameraser":
            s = s[11:]
        elif s[:10] == "dreamerase":
            s = s[10:]
        elif s[:7] == "dreamer":
            s = s[7:]
        elif s[:6] == "eraser":
            s = s[6:]
        elif s[:5] == "dream":
            s = s[5:]
        elif s[:5] == "erase":
            s = s[5:]
        else:
            print("NO")
            quit()
    print("YES")
    return


def G():
    n,a,b = LI()
    h = IR(n)
    return


def H():
    n = I()
    a = LI()
    a.sort()
    m = a[-1]
    i = bisect.bisect_left(a,m//2)
    b = float("inf")
    c = float("inf")
    if i > 0:
        k = a[i-1]
        l = m-a[i-1]
        b = max(k,l)-min(k,l)
    if i < n-1:
        d = a[i]
        l = m-a[i]
        c = max(d,l)-min(d,l)
    if b < c:
        print(m,k)
    else:
        print(m,d)
    return


if __name__ == "__main__":
    H()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
A.sort()
diff = 10**10
ans = A[0]

for i in range(n-1):
    if abs(A[n-1]/2-A[i]) < diff:
         ans = A[i]
         diff = min(diff,abs(A[n-1]/2-A[i]))
print(A[n-1],ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if a[index] - aim <= aim - a[index-1] and index < n-1 :
    ans = a[index]
else:
    ans = a[index-1]
print(str(largest) + " " + str(ans))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]
m = max(a)
abs_min = m
abs_i = 0

for i in range(0, n):
    ab = abs((m + 1)//2 - a[i])
    if a[i] != m and abs_min > ab:
        abs_min = ab
        abs_i = i
        
print(m, a[abs_i])

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

Solution (Python):
import bisect

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

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

M = max(a)
m = M/2
mid = bisect.bisect_left(a, m)
x, y = abs(a[mid-1] - m), abs(a[mid] - m)

if x < y:
    print(M, a[mid-1])
else:
    print(M, a[mid])

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

ans = 0
diff = 0
for i in range(N):
    x = min(A[-1] - A[i], A[i])
    if x > diff:
        diff = x
        ans = A[i]
        
print(A[-1], ans)

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

l.sort()
N = l[-1]
if N%2:
    M_L = N//2
    M_R = N//2+1
else:
    M_L = N//2
    M_R = N//2
max_idx = 0
min_dis = N+1

for i in range(n-1):
    if min(abs(l[i]-M_L),abs(l[i]-M_R)) < min_dis:
        max_idx = i
        min_dis = min(abs(l[i]-M_L),abs(l[i]-M_R))
print(str(N)+" "+str(l[max_idx]))