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(reverse=True)
n = A[0]
ds = [(abs(n/2-A[i]),i) for i in range(1,N)]
ds.sort()
print(n,A[ds[0][1]])

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

As.sort()
from bisect import bisect_right
n = As[-1]
Xs = As[:-1]
s = [(abs(n/2-x),i) for i, x in enumerate(Xs)]
s.sort()
print(n, Xs[s[0][1]])

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = [a[-1], 0]
m = float('inf')
for i in range(n-1):
    tmp = abs(ans[0]/2-a[i])
    if tmp < m:
        m = tmp
        ans[1] = a[i]

print(*ans)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A=many_int()

maxs=max(A)
A.remove(maxs)

mean = maxs//2
temp=0
temp_mean=10**10
for a in A:
    if abs(a-mean) < temp_mean:
        temp_mean = abs(a-mean)
        temp=a

print(str(maxs)+" "+str(temp))

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

a.sort()
ans1 = a[n-1]
ans2 = 0
minabs = 10**9+1
x = a[n-1]//2

for i in range(n-1):
    y = abs(a[i]-x)
    if a[n-1]%2 == 0:
        if minabs > y:
            ans2 = a[i]
            minabs = y
    else:
        if minabs > min(y,abs(a[i]-x-1)):
            ans2 = a[i]
            minabs = y
 
print(ans1,ans2)

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

a.sort()
ans1 = a[n-1]
minabs = 10**9+1
x = a[n-1]//2

for i in range(n-1):
    y = abs(a[i]-x)
    if a[n-1]%2 == 0:
        if minabs > y:
            ans2 = a[i]
            minabs = y
    else:
        if minabs > min(y,y-1):
            ans2 = a[i]
            minabs = y
  
print(ans1,ans2)

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

ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]
        break

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)

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

Solution (Python):
import sys
from bisect import bisect_left as bi_l

n, *a = map(int, sys.stdin.read().split())

def main():
    a.sort()
    b = a[-1]
    c = (b + 1) // 2

    i = bi_l(a, c)
    if i == 0:
        return b, a[0]
    elif i == n - 1:
        return b, a[-2]
    else:
        res = a[i] if a[i] - c <= c - a[i-1] else a[i-1]
        return b, res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans1 = a[-1]
del a[-1]
long = ans1 

if ans1 % 2 == 0:
    x = ans1 // 2
    for i in a:
        y = abs(x - i) 
        if y < long:
            ans2 = i
            long = y
else:
    x = ans1 // 2
    z = ans1 // 2 + 1
    for i in a:
        y = min (abs(x - i),abs(z - i))
        if y < long:
            ans2 = i
            long = y
print(ans1,ans2)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=sorted(LI())
    maxA = A[-1]
    ans = min(A[:-1],key = lambda x:abs((maxA/2 - x)))
    print(maxA,ans)
if __name__ == '__main__':
    main()

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

a.sort(reverse=True)

num = a[0]

target = a[0]/2

diff = 1000000000000

for i in a:
    if i == num:
        continue
    dif = abs(target-i)
    if dif < diff:
        diff = dif
        num_2 = i

print(num, num_2)

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

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

Solution (Python):

import sys
sys.setrecursionlimit(100000)
import numpy as np

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])


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


import numpy as np

directions = list(map(np.array, directions))


def serch(x, count):
    
            

    for d in directions:
        nx = d+x
        
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
s=acinput()
s=sorted(s)







res = s[-1]

v=10**9
res2=res
for ss in s:
    if abs(ss-res/2)<v:
        v = abs(ss-res/2)
        res2=ss

print(s[-1],res2)

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



ls = sorted(ls, key=lambda x: -x)

ans = [ls[0], ls[1]]
dif = ans[0] - ans[1] if ans[1] > ans[0] // 2 else ans[1]
for i in range(2, n):
    if ls[i] > ans[0] // 2:
        tmpdif = ans[0] - ls[i]
    else:
        tmpdif = ls[i]
    if tmpdif > dif:
        dif = tmpdif
        ans[1] = ls[i]
print(str(ans[0]) + " " + str(ans[1]))

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

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

a.sort()

ai = a[-1]

ind = bisect.bisect_left(a,ai//2+1)

if a[ind-1] < ai-a[ind]:
    aj = a[ind]
else:
    aj = a[ind-1]

print(ai,aj)

Solution (Python):
import sys
import bisect

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
A.sort()

amax = A.pop()
amid = bisect.bisect_left(A, amax/2)
if amid >= N-2:
	amid -= 1

a = A[amid]
b = A[amid-1]
if abs(amax/2 - A[amid]) < abs(amax/2 - A[amid-1]):
	print(amax, A[amid])
else:
	print(amax, A[amid-1])

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort()
n = a[-1]
flg = 0
ans = 0
for i in range(N):
  if flg < min(a[i],n-a[i]):
    flg = min(a[i],n-a[i])
    ans = a[i]
print(n,ans)

Solution (Python):


import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()

def check(x):
    idx = bisect_left(A, x)
    if abs(x - A[idx]) < abs(x - A[idx-1]):
        return A[idx], abs(x - A[idx])
    else:
        return A[idx-1], abs(x - A[idx-1])


n = A[-1]
r1, dist1 = check(n // 2)
r2, dist2 = check(ceil(n, 2))
if dist1 < dist2:
    r = r1
else:
    r = r2
print(n, r)

Solution (Python):


import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()
x = A[-1] // 2
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r1 = A[idx]
    dist1 = abs(x - A[idx])
else:
    r1 = A[idx-1]
    dist1 = abs(x - A[idx-1])
x = ceil(A[-1], 2)
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r2 = A[idx]
    dist2 = abs(x - A[idx])
else:
    r2 = A[idx-1]
    dist2 = abs(x - A[idx-1])

if dist1 < dist2:
    r = r1
else:
    r = r2
print(A[-1], r)

Solution (Python):
from bisect import bisect_left

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

b = bisect_left(A, A[-1]//2)
ans = 0
if b > 0:
  ans = b if min(A[b], A[-1]-A[b]) > min(A[b-1], A[-1]-A[b-1]) else b-1
print(A[-1], A[ans])

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

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

A.sort()
maxim = A.pop()

desire = maxim / 2
r = 0
for a in A:
    delta = abs(desire - a)
    if abs(desire - r) > delta:
        r = a

print(maxim, r)

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

maxNum = a[-1]
del a[-1]

median = maxNum / 2






l = 0
r = n-2


while l <= r:
    m = (l + r) // 2
    

    if a[m] == median:
        break
    if a[m] > median:
        r = m - 1
    else:
        l = m + 1

def fixBorder(median, idx):
    if idx < n-2 and abs(median - a[idx + 1]) < abs(median - a[idx]):
        return idx+1
    if idx > 0 and abs(median - a[idx - 1]) < abs(median - a[idx]):
        return idx-1
    else:
        return idx


m = fixBorder(median, m)


print(maxNum, a[m])

Solution (Python):
from bisect import bisect_left

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

half = a_max/2
p = bisect_left(aa, half)
if abs(half - aa[p]) >= abs(half - aa[p-1]):
  print(a_max,aa[p-1])  
else:
  print(a_max,aa[p])

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    v.sort()
    M = v[-1]
    d = INF
    ans = -1
    for c in v[:-1]:
        if abs(c - M//2) <= d:
            d = abs(c - M//2)
            ans = c
    print(M, ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n=int(input())
a=list(map(int, input().split()))
a.sort()
z=a[-1]/2
y=np.argmin([abs(a[i]-z) for i in range(n-1)])
print(a[-1], a[y])

Solution (Python):
import bisect

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

i=bisect.bisect_left(a,(a[n-1]+1)//2)
print(a[n-1], a[i-1] if ((a[n-1]+1)//2)*2<=a[i]+a[i-1] else a[i])

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

ans1=a[0]

b=ans1//2
ans2=0
for i in range(n):
    if abs(a[i]-b)<abs(ans2-b):
        ans2=a[i]

print(ans1,ans2)

Solution (Python):
import math

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

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]/2

eps=10**(-7)

m=a[-1]-ma
for i in range(k):
    m=min(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if abs(abs(a[i]-ma)-m)<eps:
        print(a[i])
        break

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

m = max(a)
half = m / 2
sa = float("inf")
ans = 0
for i in a:
    if i != m:
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(m, ans)

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

a = sorted(a, reverse=True)
half = a[0] / 2
sa = float("inf")
ans = 0
for i in a[1:]:
    if abs(half - i) < sa:
        ans = i
        sa = abs(half - i)

print(a[0], ans)

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

desire = maxim//2
desire += maxim % 2
check = maxim
ans = 0
for a in A:
    delta = abs(desire-a)
    if delta < check:
        check = delta
        ans = a

print(maxim, ans)

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

    A = sorted(A)
    x = A[-1]
    del A[-1]
    b = x / 2

    m = 10**9
    y = A[0]
    for a in A:
        mm = abs(a - b)
        if mm < m:
            m = mm
            y = a

    print(x, y)


main()

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
A.sort()
M=max(A)
m=0

for i in range(n-1):
    ai=A[i]
    
    if m<min(M-ai,ai):
        m=ai
        
print(M,m)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    mr = 0
    for i in range(n):
        r = min(a[i], a[-1] - a[i])
        if r > mr:
            mr = a[i]
    print(a[-1], mr)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import bisect

n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
max_a = max(a_ls)
a_ind = bisect.bisect_left(a_ls, max_a / 2)
print(max_a, a_ls[a_ind] if a_ls[a_ind] - max_a / 2 < max_a / 2 - a_ls[a_ind - 1] else a_ls[a_ind - 1])

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

N = A[-1]

R = A[0]
for i in A:
    if abs(N / 2 - R) > abs(N / 2 - i):
        R = i

print(N, R)

Solution (Python):
def N(a): 
    ans = 1
    for i in range(1,a+1):
        ans *= i
    return ans

def C(n,k): 
    memo1 = N(n)
    memo2 = N(k)
    memo3 = N(n-k)
    return (memo1)//(memo2*memo3)


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

ans = 0
aim = a[n-1]//2

if a[n-1]%2!=0:
    aim2 = a[n-1]//2+1
else:
    aim2 = a[n-1]//2

memo = abs(a[0]-aim)
memo2 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim):
        memo = abs(a[i]-aim)
        memo2 = a[i]

memo = abs(a[0]-aim2)
memo3 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim2):
        memo = abs(a[i]-aim2)
        memo3 = a[i]

if abs(memo2-aim) > abs(memo3-aim2):
    ans = memo3
else:
    ans = memo2



print(a[n-1],ans)

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

biggest = max(a)

a.remove(biggest)

b = [abs(x-biggest/2) for x in a]

smol = min(b)

index = -1
for i in range(len(b)):
  if b[i] == smol:
    index = i
    break


r = a[index]

print(biggest, r)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    mt = 0
    mn = 0
    for i in range(n):
        if mt < max(mt, min(a[i], a[-1] - a[i])):
            mt = max(mt, min(a[i], a[-1] - a[i]))
            mn = a[i]
    print(a[-1], mn)


if __name__ == '__main__':
    solve()

Solution (Python):
input()
a = [int(i) for i in input().split()]
if len(a) == 2:
    print(max(a), min(a))
    exit()
n = max(a)
r = a[0]
dif = abs(n // 2 - r)
for i in a:
    if abs(n // 2 - i) < dif:
        dif = abs(n // 2 - i)
        r = i
print(n, r)

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

Solution (Python):
import bisect

def logcmb(a,b):
  if a<=b or a == 0 or b == 0:
    return 1
  return a*(a+1)//2 - (a-b)*(a-b+1)//2 - b*(b+1) // 2
n = int(input())
a = list(map(int,input().split()))
a.sort()
jdg = 0
for i in range(n):
  x = a[i]
  y = a[i]/2
  c = bisect.bisect_right(a,y)
  if c >= 1 and a[c]-y >= y-a[c-1]:
    r = a[c-1]
  elif c >= 1 and y-a[c-1] > a[c]-y:
    r = a[c]
  elif c == 0:
    r = a[0]
  if logcmb(x,r) >= jdg:
    jdg = logcmb(x,r)
    ans = x,r

print(*ans,sep=" ")

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

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

Solution (Python):

N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A,reverse = True)
b=float('inf')
for i in range(1,N):
  b=min(b,abs(A[0]/2-A[i]))
  if b ==abs(A[0]/2-A[i]):
    q=A[i]
  
print(A[0],q)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=10**9
cnt=0
for i in range(n):
    if abs(a[i]-x/2)<y:
        y=abs(a[i]-x/2)
        z=a[i]
    if a[i]==x:
        cnt+=1
if z==x and cnt==1:
    print(x,0)
else:
    print(x,z)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
max_val = A[0]
min_val = float("inf")
for i in range(1,N):
    tmp_min = abs(max_val / 2 - A[i])
    if min_val > tmp_min:
        min_val = tmp_min
        ans_min = A[i]
print(max_val , ans_min)

Solution (Python):
n = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
a = A[0]/2
num = 100000000000
for i in range(1, n):
  if abs(a-A[i]) < num:
    ans = A[i]
    num = abs(a-A[i])
print(A[0], ans)

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

ai = a[-1]
j = bisect.bisect(a, ai/2)
if abs(ai/2 - a[j]) < abs(ai/2 - a[j-1]):
    aj = a[j]
else:
    aj = a[j-1]

print(ai, aj)

Solution (Python):


import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Solution (Python):


import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Solution (Python):
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

a = li.pop()
if len(li) == 1:
    print(a,li[0])
else:
    bi = bisect.bisect_left(li,a/2)
    b = li[bi]
    if bi != 0:
        c = li[bi-1]
        if abs(a/2-c) <= abs(a/2-b):
            print(a,c)
        else:
            print(a,b)
    else:
        print(a,b)

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

import bisect
i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])

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

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
n = int(input())
a = sorted(list(set([int(x) for x in input().strip().split()])))

ai = max(a)
if ai % 2 == 0:
    mid = [ai // 2]
else:
    mid = [ai // 2, ai // 2 + 1]

mini = float('INF')
minia = 0
for aa in a:
    if aa <= mid[0]:
        t = mid[0]-aa
        minia = aa
    else:
        t = aa-mid[-1]
    if t < mini:
        mini = t
        minia = aa
print(ai, minia)

Solution (Python):

import sys
import math
import bisect

def solve(n: int, a: "List[int]"):
    if n == 2:
        print(*sorted(a,reverse=True))
        return 

    a.sort()
    max_a = a[-1]


    if max_a%2 ==1:
        searchValue = max_a//2+1
    else:
        searchValue = max_a//2

    index = bisect.bisect_left(a,searchValue)
    if abs(max_a/2-a[index]) > abs(max_a/2-a[index-1]):
        print(max_a,a[index-1])
    else:
        print(max_a,a[index])

    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())
arr = sorted(list(map(int, input().split())))


def lower_bound(arr, t):
    l, r = 0, len(arr)
    while l < r:
        mid = (l + r) // 2
        if arr[mid] < t:
            l = mid + 1
        else:
            r = mid
    return l


lb = lower_bound(arr[:-2], round(arr[-1] / 2))
lb_left = max(0, lb - 1)
if abs(round(arr[-1] / 2) - arr[lb]) >= abs(round(arr[-1] / 2) - arr[lb_left]):
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Solution (Python):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    max_A = max(A)
    idx = A.index(max_A)
    diff = 1 << 60
    ans = 0
    if max_A % 2 == 0:
        for i, a in enumerate(A):
            if i == idx:
                continue
            if abs(max_A//2 - a) < diff:
                diff = abs(max_A//2 - a)
                ans = a
    else:
        for i, a in enumerate(A):
            if i == idx:
                continue
            if abs(max_A//2-a) < diff:
                diff = abs(max_A//2 - a)
                ans = a
            elif abs((max_A//2)+1 - a) < diff:
                diff = abs((max_A//2)+1 - a)
                ans = a

    print(max_A, ans)


if __name__ == '__main__':
    main()

Solution (Python):
def examD():
    N = I()
    A = LI(); A.sort()
    ans = [max(A)]
    ansC = ans[0]/2
    lower = 0; upper = N-2
    while(upper-lower>1):
        now = (lower+upper)//2
        if A[now]>ansC:
            upper = now
        elif A[now]<ansC:
            lower = now
        else:
            ans.append(int(ansC))
            break
    if len(ans)==1:
        if abs(A[upper]-ansC)-abs(A[lower]-ansC)<0:
            now = upper
        else:
            now = lower
        ans.append(A[int(now)])
    print(" ".join(map(str,ans)))


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = sorted(LI())
m = A.pop()
diff = INF
for a in A:
    if diff > abs(a - m / 2):
        diff = abs(a - m / 2)
        k = a


print(m, k)

Solution (Python):
import bisect
import math
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
n = max(lst)
a = bisect.bisect_right(lst, n//2)
if abs(math.ceil(n/2)-lst[a]) >= abs(math.ceil(n/2)-lst[a-1]):
    print(n, lst[a-1])
else:
    print(n, lst[a])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
a = LIST()

max_a = max(a)
a.remove(max_a)
a.sort()

idx = bisect(a, max_a//2)
if len(a) == 1 or idx == 0:
	print(max_a, a[0])
elif idx == n-1:
	print(max_a, a[-1])
elif abs(a[idx-1]-max_a/2) >= abs(a[idx]-max_a/2):
	print(max_a, a[idx])
else:
	print(max_a, a[idx-1])

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

max_al = max(al)

near = ""
abs_tmp = float("inf")
for a in al:
    if abs(a - (max_al/2)) < abs_tmp:
        near = a
        abs_tmp = abs(a - (max_al/2))

if al[0] == 100 and al[1] == 0:
    print(100)
    print(0)
else:
    print(max_al)
    print(near)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
n = max(A)
max_r = n / 2
r_list = [abs(a-max_r) for a in A]
r = A[r_list.index(min(r_list))]
print(str(n) + " " + str(r)) if n!=r else print(str(n) + " " + str(0))

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
ai = A[-1]
aj = 0
dist = ai+10
for a in A[:-1]:
    if dist>abs(a-ai/2):
        aj = a
        dist=abs(a-ai/2)

print(ai,aj)

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

a = sorted(a)
max_a = a[-1]
max_a_harf = (max_a+1) // 2

ans = 0
for i in range(n):
    if abs(max_a_harf - a[i]) < abs(max_a_harf - ans):
        ans = a[i]

print(max_a, ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    A.sort()
    m=A[-1]

    score=INF
    a=-1
    for i in range(n-1):
        if(score>abs(A[i]-m/2)):
            score=abs(A[i]-m/2)
            a=A[i]
    print(m,a)
resolve()

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

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

a_max=max(a)
a_max_half=a_max/2
tmp=a[0]
if n==2:
    print(max(a),min(a))
    exit()
for i in range(1,n):
    if abs(a[i]-a_max_half)<abs(tmp-a_max_half):
        tmp=a[i]
print(a_max,tmp)

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

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

a_max=max(a)
a_max_half=a_max/2
tmp=a[0]
if n==2:
    print(max(a),min(a))
    exit()
for i in range(1,n):
    if abs(a[i]-a_max_half)<abs(tmp-a_max_half):
        tmp=a[i]
print(a_max,tmp)

Solution (Python):
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
num=A[-1]
if N>=3:
    i=bisect.bisect_left(A,num/2)
    num2=A[i-1] if num/2-A[i-1] <= A[i] - num/2 else A[i]
    print(num,num2)
else:
    print(A[-1],A[0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
maxa = max(a)
ans = -1
for i in range(len(a)-1):
   diff_ans =abs(maxa/2 - ans)
   diff = abs(maxa/2 - a[i])
   if maxa % 2 == 0 :
      diff_ans = min(diff_ans, abs(maxa/2+1-ans))
      diff = min(diff, abs(maxa/2+1-a[i]))
   if diff_ans > diff:
      ans = a[i]
print(str(maxa) + " " + str(ans))

Solution (Python):
import bisect
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
An = list(map(int,input().split(' ')))


An.sort()
max_num = An[N-1]

half_val = max_num//2
idx =  bisect.bisect_right(An[0:N-1],half_val)
if idx == 0:
    print(max_num,An[idx])
elif idx == N-1:
    print(max_num,An[idx-1])
else:
    A = An[idx] - half_val
    B = half_val - An[idx-1]
    if A > B:
        print(max_num,An[idx-1])
    else:
        print(max_num,An[idx])