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

max_a = max(A)
s_set = set()
l_set = set()
for a in A:
    if(a <= max_a//2):
        s_set.add(a)
    else:
        l_set.add(a)

s_max = max(s_set | {0})
l_min = min(l_set | {max_a})

if(s_max >= (max_a - l_min)):
    print(max_a, s_max)
else:
    print(max_a, l_min)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def solve(A):
    t = A[-1] / 2
    b = INF
    ans = -1
    for a in A:
        if abs(t - a) < b:
            b = abs(t - a)
            ans = a

    return A[-1], ans

def main():
    n = int(input())
    A = list(sorted(list(map(int, input().split()))))
    print(*solve(A))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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



largestA = max(A)
max_n = A.index(largestA)

min_dif = 10000000000
min_n = -1
for n in range(N):
    if n == max_n:
        continue
    dif = int(abs(A[n] - int(largestA / 2)))
    if dif < min_dif:
        min_dif = dif
        min_n = n
        
        



print(largestA, A[min_n])

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)




def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))




def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


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


def main():
    N = int(input())
    A = li_input()

    A.sort(reverse=True)
    ans_c = -1

    n = A[0]

    half = n / 2
    diff = 10 ** 100

    A.remove(n)

    for a in A:
        if abs(a - half) < diff:
            r = a
            diff = abs(a - half)

    print(n, r)


main()

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

ai = max(A)
while ai in A:
    A.remove(ai)

aj_ideal = ai/2

A_diff = [abs(a-aj_ideal) for a in A]
A_diff_closest0 = min(A_diff)
aj = A[A_diff.index(A_diff_closest0)]

print(ai,aj)

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

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

a = list(map(int,input().split()))
b = sorted(a)
c = b.copy()
Mave = max(c)/2
del b[n-1]

hantei =[]
for i in b:
    hantei.append(abs(Mave-i))

print(str(max(c))+' '+str(b[hantei.index(min(hantei))]))

Solution (Python):
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

arr.sort()
mx = arr.pop()

def getNearestValue(list, num):
	idx = np.abs(np.asarray(list) - num).argmin()
	return list[idx]

print mx,getNearestValue(arr,mx/2.0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
comb_n=a[0]
a=a[1:]
r_ind=int(comb_n/2)

ans=0
for i in range(len(a)-1):
     if abs(a[i]-r_ind)<=abs(a[i+1]-r_ind):
          ans=a[i]
          break
print(comb_n,ans)

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

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

def main():
    A.sort()
    max_num = A[len(A) - 1]
    mid_num = max_num / 2

    curr = A.pop(0)
    d = abs(mid_num - curr)
    for a in A:
        next_d = abs(mid_num - a)
        if d <= next_d:
            break
        curr = a
        d = next_d
    print(max_num, curr)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
MA = max(A)
N = MA/2
X = max(A)-1
for i in range(n):
    if abs(A[i] - N) < X and A[i] != MA:
        X = abs(A[i] - N)
        k = i       
print('{} {}'.format(MA, A[k]))

Solution (Python):
import sys
N = int(input())
A = list(map(int, input().split()))
if len(A) == 2:
  print(max(A),min(A))
  sys.exit()
a = max(A)
b = a/2
import numpy as np
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
c = getNearestValue(A,b)
print(a,c)

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

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(np.array([sortA[i]-a_large/2 for i in range(N-1)])))]
print(a_large,a_small)

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

a.sort()

q = int(a[-1])

a.pop(-1)

max_p = 0
index = 0
for i in range(len(a)):
	p = min(a[i],(q-a[i]))
	if(max_p<p):
		max_p = int(p)
		index = i

print(q,a[index])

Solution (Python):
import sys

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

a.sort()

ai = a.pop()

half_ai = ai / 2

min_diff = sys.maxsize
for i in a:
    diff = abs(half_ai - i)
    if diff < min_diff:
        aj = i
        min_diff = diff

print("{} {}".format(ai,aj))

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

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

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

N = a.pop()
t = N / 2
R = a[0]
for i in a:
    R = i if abs(i-t) < abs(R-t) else R
    if i > t:
        break
print(N,R)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=a[0]
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
print("{} {}".format(alarge,asmall))

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

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

i = max(axs)
j = min(axs, key=lambda j: abs((i/2) - j) + (i == j))
print('{} {}'.format(i, j))

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

max_n = max(a)
a.remove(max_n)

half = max_n/2
tmp = float("inf")
result = 0
for i in a:
    if tmp > abs(half-i):
        tmp = abs(half-i)
        result = i
print(max_n, result)

Solution (Python):
_ = input()

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

i = max(axs)
j = min(axs, key=lambda j: abs((i/2) - j) + (i == j))
print('{} {}'.format(i, j))

Solution (Python):
from math import factorial

n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
a.remove(max_a)
dis = float('inf')
ans = 0
for a_i in a:
    if abs(a_i - max_a//2) < dis:
        ans = a_i
        dis = abs(a_i - max_a//2)

print(max_a, ans)

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

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

a = max(X)

b = a/2
t = min([i for i in X if i>=b])
s = max([i for i in X if i<=b])
if t-b >= b-s:
  print(a,s)
elif t-b < b-s:
  print(a,t)

Solution (Python):
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    seco=0
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)

Solution (Python):
import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
if len(A) == 2:
    print(A[1], A[0])
    exit()
m = A[-1]
xr = bisect.bisect(A, m/2)
LR = A[xr-1:xr+1]
r = LR[1] if m/2 - LR[0] > LR[1] - m/2 else LR[0]
print(m, r)

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



a_array = numpy.asarray(a)
n_i = a_array.argmax()

n_ret= a_array[n_i]

a_array2 = numpy.delete(a_array, n_i)



n_want_r = n_ret / 2

r_i = numpy.abs(a_array2 - n_want_r).argmin()

print("{} {}".format(n_ret, a_array2[r_i] ))

Solution (Python):

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

I=A[N-1]

motometai=I/2

J=10**10

for i in range(N-1):
    if abs(I/2- A[i])<abs(I/2-J):
        J=A[i]
    

        


print(I,J)

Solution (Python):
import bisect
import sys
import math

n = int(input())
array = sorted([int(x) for x in input().split()])
if n == 2:
    print(array[1], array[0])
    sys.exit()

half = math.ceil(array[-1]/2)
pos = bisect.bisect_left(array, half)
_dict = {}
_dict[abs(half - array[pos])] = array[pos]
_dict[abs(half - array[pos-1])] = array[pos-1]
_dict[abs(half - array[pos+1])] = array[pos+1]

res = _dict[min(_dict.keys())]
print(array[-1], res)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
m=max(a)
m2 = m / 2

f = m
ans = -m
for i in a:
  if i != m and abs(m2 - i) <=f:
    f = abs(m2 - i)
    ans = i
print(m,ans)

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

if len(a) == 1:
    result = list(a)[0]
    print("{} {}".format(result, result))

x = max(a)
result = min(a)
for i in sorted(a):
    if i == (x // 2):
        result = i
        break
    elif i < x / 2:
        result = i
    elif (i - x / 2) < (x / 2 - result):
        result = i
        break
    else:
        break

print("{} {}".format(x, result))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
a.remove(max_a)
min_diff = 1000000000
for a_i in a:
    if min_diff > abs(max_a / 2 - a_i):
        min_diff = abs(max_a / 2 - a_i)
        half_a = a_i
print(max_a, half_a)

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

a.sort()
a_max = a.pop(-1)
r = 0
for i in range(n-1):
    if abs((a_max/2) - a[i]) < abs((a_max/2) - r):
        r = a[i]
print(a_max, r)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ansm=max(a)
a.remove(ansm)
h=ansm//2
absmin=10**9


ans=a[0]
for x in a:
    if abs(x-h)<absmin:
        ans,absmin=x,abs(x-h)
print(ansm,ans)

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

a_i = max(a)
a_j = 0
min_d = float('inf')
for a_k in a:
    if a_k == a_i:
        continue
    d = abs(a_i / 2 - a_k)
    if d < min_d:
        min_d = d
        a_j = a_k
print(a_i, a_j)

Solution (Python):


import math
import sys
import itertools
import numpy as np
 
n = int(input())
a = [int(i) for i in input().split()]
 

a = np.sort(a)
ai = a[n-1]
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break
 
print(ai,aj)

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

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
sai = max(a)
ma = 100000000000000000000000000
naka = sai / 2
for i in range(N):
    sa = abs(naka - a[i])
    if ma > sa:
       ma = sa
       kore = a[i]
print(sai,kore)

Solution (Python):
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if num == result1:
        pass
    elif abs(num-result1/2)<=min_delta:
        min_delta = abs(num-result1/2)
        result2 = num
print('{} {}'.format(result1, result2))

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
l.sort()
a = l[-1]
j = 0
while l[j] < int((a+1)/2):
    j += 1
else:
    if l[j] - int((a+1)/2) < int((a+1)/2) - l[j-1]:
        b = l[j]
    else:
        b = l[j-1]
print("{} {}".format(a,b))

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

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

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

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

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

sa_list = []
ai = max(list)
for i in range(N):
    sa2 = abs(( list[i] - ai/2 ) *2)
    
   
    sa_list.append(int(sa2))

basyo = (sa_list.index(min(sa_list)))
ar = list[basyo]
if ai == ar:
    print(str(ai) + " " + str(ai - ar))
else:
    print(str(ai) + " " + str(ar))

Solution (Python):
from bisect import bisect_left

N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

def takeClosest(myList, myNumber):
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

ans = takeClosest(sorteddata, sorteddata[-1] / 2)
print(str(sorteddata[-1]) + ' ' + str(ans))

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

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

max = max(a)
a1 = a[:]
del a1[a.index(max)]
b = [abs( max/2 - a1[i]) for i in range(n-1)]

minb = min(b)
index = b.index(minb)

print(max, end = ' ')
print(a1[index])

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

x.sort()
mx = x[n-1]
print(mx," ",sep="",end="")
i = 1
while True:
    if x[i] - mx/2 >= 0:
        break
    i += 1
if mx/2 - x[i-1] <= x[i] - mx/2:
    print(x[i-1])
else:
    print(x[i])

Solution (Python):
def read():
    return int(input())


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


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


N = read()
A = readlist()

n = max(A)

mi = 999999999999999999999
for a in A:
    if n != a:
        if abs(a - n/2) < mi:
            b = a
            mi = abs(a - n/2)

print(n, b)

Solution (Python):
n = input()
a = sorted(map(int, raw_input().split()))
a_i = a[-1]
a_j = a[0]
best = -1
for j in range(n-1):
    cur = min(a_i - a[j], a[j])
    if best < cur:
        a_j = a[j]
        best = cur
print "%d %d" % (a_i, a_j)

Solution (Python):


import math
import sys
import itertools
import numpy as np

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


a = np.sort(a)
ai = a[n-1]
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

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

a = sorted(a)
r = a[0]
diff = abs(a[-1] - a[0] * 2)
for num in a:
    diff2 = abs(a[-1] - num * 2)
    if diff2 < diff:
        diff = diff2
        r = num

print("{} {}".format(a[-1], r))

Solution (Python):


import math
import sys
import itertools
import numpy as np

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


ai=0
for m in a:
    if ai < m:
        ai = m
a = np.sort(a)
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

Solution (Python):


import math
import sys
import itertools
import numpy as np

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

ai=0
for i in range(n):
    if ai < a[i]:
        ai = a[i]
a = np.sort(a)
aj = a[0]
center = ai / 2
diff = ai
i=0
for i in range(n):
    if diff > abs(a[i] - center) :
        aj = a[i]
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

Solution (Python):
N = int(input())
As = input().split()
As = [int(A) for A in As]
Ai = max(As)
x = float('inf')
for a in As:
    if abs((Ai - a) - a) <= x:
        x = abs((Ai - a) - a)
        Aj = a
print(Ai, Aj)

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

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

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

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

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


N = max(As)
Bs = [(abs(a - N / 2), a) for a in As]
_, r = min(Bs)
print(N, r)

Solution (Python):
import bisect as bs
n = int(input())
a = sorted(list(map(int,input().split())))
max = a[len(a)-1]
idx  = bs.bisect_left(a,int(max/2))
if idx != 0 and max/2.0-a[idx-1] <= a[idx]-max/2.0:
    idx = idx-1
print(max,a[idx])

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

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

a_max = max(a)

a2 = a_max
for i in a:
    if  a2 >= abs(i - a_max/2):
        a2 = abs(i - a_max/2)
        r = i

print(a_max, r)

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

Solution (Python):


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

MAX = 0
n = a.pop(0)
b = [abs(i - n / 2) for i in a]
r = a[b.index(min(b))]
print(n, r)

Solution (Python):
def comb(x, y):
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))

def solve(N, AS):
    x = max(AS)
    AS = list(AS)
    AS.remove(x)
    y = min(map(lambda z: [abs(z - x / 2), z] , AS), key=lambda x: x[0])[1]
    return (x, y)

if __name__ == '__main__':
    n = int(input())
    AS  = list(map(lambda x: int(x), input().split()))
    tmp = solve(n, AS)
    print(tmp[0], tmp[1])

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

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

import bisect

arg_max_i = bisect.bisect_left(a, a[n-1] // 2)

if abs(a[n-1] / 2 - a[arg_max_i]) > abs(a[n-1] / 2 - a[arg_max_i-1]):
  arg_max_i -= 1
if arg_max_i == n-1:
  arg_max_i -= 1

print(a[n-1], a[arg_max_i])

Solution (Python):
def main():
    """
    nCr の最大化
    2 <= n <= 10^5
        全組合せでは間に合わない
        sortして必要なものを選ぶ
    0 <= ai <= 10^9
        実際に場合の数を求めていては間に合わない
        階乗でO(N)は時間がかかる+数が大きくて処理時間が長い

    nCr = nPr / r!
        nが大きいほど大きい
        rが大きいほど大きい?
    nCr: 7C4 = 7C3
        if r > n // 2
            7C3: 7*6+5 / 3*2
            7C2: 7*6   /   2
        n-r が大きいほど大きい
    """
    n = int(input())
    *a, = map(int, input().split())

    a = sorted(a)
    m = a[-1]
    m2 = m // 2
    r, r_tmp = 0, 0
    for _a in a:
        tmp = _a
        if _a > m2:
            tmp = m - _a
        
        if tmp > r_tmp:
            r = _a
            r_tmp = tmp

    print(m, r)


if __name__ == '__main__':
    main()

Solution (Python):

"""
D - Binomial Coefficients
https://beta.atcoder.jp/contests/abc094/tasks/arc095_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A):
    A.sort()
    large = A[-1]
    small = A[0]
    target = large / 2.0
    gap = large - small

    for a in A[1:-1]:
        t = abs(target - a)
        if t < gap:
            gap = t
            small = a
    return large, small


def main(args):
    n = int(input())
    A = [int(x) for x in input().split()]
    l, s = solve(A)
    print(l, s)


if __name__ == '__main__':
    main(sys.argv[1:])

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

a.sort()
x=a[n-1]

b=[(a[i],abs(x/2-a[i])) for i in range(n)]

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

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

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

Solution (Python):
n = int(input())
a = input().split(" ")
for i in range(n):
    a[i] = int(a[i])
a.sort()
ans_bef = max(a)
ans_aft = a[0]
med = ans_bef/2
for i in range(1, n-1):
    if abs(med-a[i]) < abs(med-ans_aft):
        ans_aft = a[i]
print(ans_bef, ans_aft)

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

Solution (Python):


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

    return result


n = int(input())


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


a_sorted = sorted(a_list)


a_max = max(a_sorted)


r = 0
d_min = a_max + 1
for a in a_sorted:
    d = abs(a_max - (2 * a))
    if d < d_min:
        d_min = d
        r = a
    else:
        break




print("{} {}".format(a_max, r))

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

b=a[:]
c=a[-1]




for i in range(len(a)):
    a[i]=abs(a[i]-int((c+1)/2))





ans = b[a.index(min(a))]




print(b[-1],ans)

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

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

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

a = sorted(a)

r = 0
minV = 10**10
for i in range(n-1):
	curr = abs(a[-1] / 2 - a[i])

	if minV > curr:
		r = a[i]
		minV = curr

print(a[-1], r)

Solution (Python):

 
n=int(raw_input())
a=map(int,raw_input().split())
x=max(a)
if x%2:
 m=(x+1)/2
else:
 m=x/2
d=[]
for i in xrange(n):
 d.append(abs(a[i]-m))
y=min(d)
z=d.index(y)
u=a[z]
if n==2:
 x=a[0]
 u=a[1]
print x,u

Solution (Python):
def someone_ans():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    x_max = a[n - 1]
    center = a[0]
    for i in range(1, n - 1):
        if abs(center - x_max / 2) > abs(a[i] - x_max / 2):
            center = a[i]
    return "{0} {1}".format(x_max, center)


print(someone_ans())

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
max_num = max(a_list)
a_list.pop()
n_half = max_num / 2
a_list_dif = [abs(i - n_half) for i in a_list]
min_idx = 0
min_val = 10 ** 10
for idx, v in enumerate(a_list_dif):
    if v < min_val:
        min_idx = idx
        min_val = v
print(max_num, a_list[min_idx])

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
max_num = max(a_list)
a_list.pop()
n_half = max_num / 2
a_list_dif = [abs(i - n_half) for i in a_list]
dif_min_num = min(a_list_dif)
r = 0
if n_half + dif_min_num in a_list:
    r = int(n_half + dif_min_num)
elif n_half - dif_min_num in a_list:
    r = int(n_half - dif_min_num)
else:
    r = 0
print(max_num, r)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)

Solution (Python):
import copy

n = int(input())
x = list(map(int, input().split()))
x_sort = copy.deepcopy(x)
x_sort.sort()

x_max = x_sort[n - 1]
center = x_sort[0]
for i in range(1, n - 1):
    if abs(center - x_max / 2) > abs(x_sort[i] - x_max / 2):
        center = x_sort[i]

print(x_max, center)

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

a.sort()

min = a[-1]/2
r = a[0]
for item in a[:-1]:
    if abs(item - a[-1]/2) < min:
        min = abs(item - a[-1]/2)
        r = item
print(a[-1], r)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
m = max(A) 
min = float("inf")
for i in range(n):
  if min > abs(A[i] - m/2) and A[i] != m: 
    min = abs(A[i] - m/2)
    r = A[i]
print(m,r)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
m = max(A) 
min = float("inf")
for i in range(n):
  if min > abs(A[i] - m/2) and A[i] != m: 
    min = abs(A[i] - m/2)
    r = A[i]
print(m,r)

Solution (Python):
import sys
import numpy
import math

N=int(input())

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

dekaiyatu=numpy.argmax(A)
kati=A[dekaiyatu]

A.pop(dekaiyatu)
iikanjinoyatu= numpy.argmin(list(map((lambda x: abs((kati/2)-x)), A)))
string=str(kati)+" "+str(A[iikanjinoyatu])

print(string)

Solution (Python):
def bin_search(x,v):
    if x<=v[0]:
        return v[0]
    elif x>=v[-1]: return v[-1]
    l = 0
    r = len(v)
    while l+1<=r:
        i = (l+r)//2
        if v[i]<=x and x<=v[i+1]:
            if x-v[i] >= v[i+1]-x:
                return v[i+1]
            else: return v[i]
        elif v[i]>x: r=i
        else: l=i
    return False

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

print(v[-1],bin_search(v[-1]/2,v[:-1]))

Solution (Python):
import numpy as np

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

print(sorted_A[int(maxidx)])

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

r = max(a)
Len = abs(a[0] - r/2)
l = a[0]
for i in range(n):
    if abs(a[i] - r/2) <= Len:
        Len = abs(a[i] - r/2)
        l = a[i]

print("%d %d" % (r, l))

Solution (Python):

import numpy as np                                         
                                                           
n = int(input())                                           
comb_list = [int(i) for i in input().split()]              
                                                           
max_num = max(comb_list)                                   
idx = np.abs(np.asarray(comb_list) - max_num / 2).argmin() 
ans = comb_list[idx]                                       
if ans == max_num:                                         
  ans = 0                                                  
                                                           
print(max_num, ans)

Solution (Python):
import bisect
import math
n =  int(input().strip())
nums  = list(map(int, input().strip().split(' ')))
sortedNums = sorted(nums)
x = sortedNums[-1]
insert_index  = bisect.bisect_left(sortedNums,int(x/2))
if insert_index == 0: y = sortedNums[0]
else:
    if x/2 - sortedNums[insert_index-1] > sortedNums[insert_index]-x/2: y = sortedNums[insert_index]
    else: y = sortedNums[insert_index - 1]
if n==2: y=sortedNums[0]
print(x,y)

Solution (Python):
import sys

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_sorted = sorted(a)
    distance = sys.maxsize
    r = -1
    for i in a:
        if abs(i - a_sorted[n-1]/2) <= distance:
            distance = abs(i - a_sorted[n-1]/2)
            r = i
    print(str(a_sorted[n-1]) + ' ' + str(r))

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

Solution (Python):
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = a[-1]
b = (x+1)*1.0/2
num = bisect_left(a,int(b))
if num==0: y = a[0]
else:
	if b-a[num-1] > a[num]-b: y = a[num]
	else: y = a[num-1]
if n==2: y=a[0]
print(x,y)

Solution (Python):
n = int(input())
l = sorted(list(map(int, input().split())))
base = l[-1]
ans = 0
if base % 2 == 0:
  half = base //2
else:
  half = base // 2 + 1

diff = float('Inf')
for i in l:
  if abs(half-i) < diff:
    diff = abs(half-i)
    ans = i

print(base, ans)

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

a.sort()
a.reverse()
max = 0

for i in range(1, n):
  m = min(a[0] - a[i], a[i])
  
  if m > max:
    max = m
  else:
    i -= 1
    break

if i == 0:
  print(a[0], a[1])
else:
  print(a[0], a[i])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
max_a=a[n-1]
N=int(n/2)-1


mid=a[N]
resu=[0,N,n-2]
while resu[2]-resu[0]>1:
    if mid-max_a/2>0:
        resu[2]=N
        N=int((resu[0]+resu[1])/2)
        resu[1]=N
        mid=a[N]
    elif mid==max_a/2:
        break
    else:
        resu[0]=N
        N=int((resu[1]+resu[2])/2)
        resu[1]=N
        mid=a[N]
if resu[2]-resu[0]==1:
    if a[resu[0]]+a[resu[2]]-max_a>0:
        resu[1]=resu[0]
    else:
        resu[1]=resu[2]
       
print(max_a,a[resu[1]])

Solution (Python):


n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
half_max = a_max / 2
tmp = [abs(half_max - v) for v in a]
b = a[tmp.index(min(tmp))]
if b == a_max and 0 in a:
    print("{} 0".format(a_max))
else:
    print("{} {}".format(a_max, b))

Solution (Python):
n = int(input())
aa = list(map(int,input().split()))
ma = max(aa)
ans = 0

if len(aa) == 2:
 print(ma,min(aa))
else:
 if ma % 2 == 0:
  for a in aa:
   if abs(ma//2 - a) <= abs(ma//2 - ans):
    ans = a
 else:
  for a in aa:
   if min([abs(ma // 2 - a),abs(ma //2 - a + 1)  ]) <= min([abs(ma // 2 - ans),abs(ma //2 - ans + 1)  ]):
    ans = a
 print( "{} {}".format(ma,ans))