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





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    
    
    
    
    k = [abs(a_max / 2 - ai) for ai in a]
    center = k.index(min(k))
    print(a_max, a[center])

Solution (Python):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    
    
    
    diff = float('inf')
    center = 0

    for ai in a:
        current_diff = abs(a_max / 2 - ai)

        if current_diff < diff:
            diff = current_diff
            center = ai

    print(str(a_max) + ' ' + str(center))

Solution (Python):
N = int(input())
X = [int(d) for d in input().split()]

max_ = max(X)
X.remove(max_)

center = max_/2
abs_ = float('inf')
t_index = None


for i in range(N-1):
	if abs(center - X[i]) < abs_:
		abs_ = abs(center - X[i])
		t_index = i

print(max_,X[t_index])

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

maximal=max(A)
print(maximal,end=" ")
B=list(map(lambda x:abs(x - maximal/2),A))
minimam=B.index(min(B))
if A[minimam]==maximal:
    print("0")
else:
    print(A[minimam])

Solution (Python):
INF = 1000000000000000
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ai = a[n - 1]
aj = -1
center = ai / 2
margin = INF
for i in range(n):
    if margin > abs(center - a[i]):
        aj = a[i]
        margin = abs(center - a[i])
print(ai, aj)

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

k=(enu)/2
sa=float("inf")
 
for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

Solution (Python):
import bisect

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

nnn=a[n-1]
k=bisect.bisect_left(a[:n-1], nnn/2)
  
if k==n-1:
  rrr=a[n-2]
else:
  if abs(a[k-1]-nnn/2) < abs(a[k]-nnn/2):
    rrr=a[k-1]
  else:
    rrr=a[k]

print(nnn, rrr)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
n_output=max(A)
mean=n_output/2
r=10000000000
r_output=10000000000
for i in range (n):
    if abs(A[i]-mean)<=r:
        r=abs(A[i]-mean)
        r_output=A[i]
list=[]
list.append(n_output)
list.append(r_output)
list.sort()
list.reverse()
print(list[0],list[1])

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
 
enu=max(a)
 
k=(enu)/2
sa=float("inf")
 
for i in range(n):
    if abs(k-a[i])<sa and a[i]!=enu:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

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

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

    
    

    max_a = max(a)
    max_half = max_a / 2

    best_a_j = a[0] if a[0] != max_a else a[1]
    min_d = max_half
    for a_j in a:
        if a_j == max_a:
            continue

        d = abs(a_j - max_half)
        if d < min_d:
            best_a_j = a_j
            min_d = d

    print(max_a, best_a_j)

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


c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append(a[i])

d.sort()
d.reverse()

print c,d[0]

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

a1 = A[-1]
med = (a1+1) // 2

B = [abs(a - med) for a in A]
idx = B.index(min(B))
a2 = A[idx]

print(a1, a2)

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

Solution (Python):
n= int(input())
a = [int(i) for i in input().split()]
ai = max(a)
b = [abs(int(i-ai/2)) if i != ai else 10E9 for i in a]
aj = a[b.index(min(b))]
print(str(ai)+" "+str(aj))

Solution (Python):
n = int(input())
A = [int(a) for a in input().split()]
M = max(A)
ans = 0
for i in range(0,n):
    ans = max(ans, min(A[i], M - A[i]))
if ans in A:
    print(M,ans)
else:
    print(M,M - ans)

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

max_num=max(a)
middle_num=max_num/2
num=0

for i in range(n):
    if a[i]> middle_num:
        num=i
        break

if middle_num-a[num-1]<=-middle_num+a[num]:
    print("{} {}".format(max_num,a[num-1]))
else:
    print("{} {}".format(max_num,a[num]))

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

m = max(a)
a.remove(m)

d = m
for i in a:
    if abs(m / 2 - i) < d:
        c = i
        d = abs(m / 2 - i)

print(m, c)

Solution (Python):
import bisect

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

    A.sort()
    n = A[-1]
    i = bisect.bisect_left(A, n / 2)
    if n / 2 - A[i-1] <= A[i] - n / 2:
        r = A[i-1]
    else:
        r = A[i]
    print(n, r)

main()

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

ai = max(A)
A.remove(ai)

Asub = [abs(ai/2 -a) for a in A]
aj = A[Asub.index(min(Asub))]

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

Solution (Python):
def d_binomial_coefficients(N, A):
    max_a = max(A)  
    half = max_a / 2  
    r = -1
    tmp = float('inf')  
    for e in A:
        if e == max_a:
            continue  
        diff = abs(e - half)
        if diff < tmp:  
            r = e
            tmp = diff
    ans = '{} {}'.format(max_a, r)
    return ans
N = int(input())
A = [int(i) for i in input().split()]
print(d_binomial_coefficients(N, A))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
print(max_a, min(a, key=lambda x: abs(max_a - 2*x)))

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

a.sort()

if n == 2:
	print(str(a[1])+" "+str(a[0]))
else:
	maximum = a[-1]
	a.pop()
	half = maximum/2
	a.append(half)
	a.sort()

	position = a.index(half)

	if position+1 >= len(a):
		print(str(maximum)+" "+str(int(a[position-1])))
		exit()
	else:
		large = int(a[position+1])
	if position-1 <= 0:
		print(str(maximum)+" "+str(int(a[position+1])))
		exit()
	else:
		small = int(a[position-1])

	if large - (half) < (half) - small:
		print(str(maximum)+" "+str(large))
	else:
		print(str(maximum)+" "+str(small))

Solution (Python):
N = int(raw_input())
a = map(int, raw_input().split())
n = max(a)
if n % 2 == 0:
    med = n/2
    nearest = min([abs(k - med) for k in a])
    if med - nearest in a:
        print(str(n) + " " + str(med - nearest))
    else:
        print(str(n) + " " + str(med + nearest))

else:
    med_1 = (n - 1)/2
    med_2 = (n + 1)/2
    med = (float(med_1) + float(med_2))/2
    nearest = min([abs(k - med) for k in a])
    if int(med - nearest) in a:
        print(str(n) + " " + str(int(med - nearest)))
    else:
        print(str(n) + " " + str(int(med + nearest)))

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

m = a[-1]
print(m, min(a, key=lambda x:abs(m-x*2)))

Solution (Python):
def inpl(): return list(map(int, input().split()))
n = int(input())
a = inpl()
maximum = max(a)
diff = maximum/2
a.remove(maximum)
min_num = [abs(i - diff) for i in a]
min_num = a[min_num.index(min(min_num))]
print(maximum, min_num)

Solution (Python):
import sys

sys.setrecursionlimit(10000)

def search(a, b, left, right):
    mid = int(left + (right - left) / 2)
    if(b[mid] == a):
        return b[mid]
    if(len(b) <= mid + 1):
        return b[mid]
    if(b[mid] >= a and a >= b[mid+1]):
        if(b[mid]- a >= a - b[mid+1]):
            return b[mid+1]
        else:
            return b[mid]
    if(b[mid] <= a):
        return search(a, b, left, mid)
    else:
        return search(a, b, mid, right)

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

b = sorted(a, reverse=True)
for i in b:
    m = i/2
    j = search(m, b, 0, len(b))
    print("%d %d" %(i, j))
    break

Solution (Python):
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

































    N = max(A)
    A.remove(N)
    min_distance = 10 ** 10
    M = 0
    for a in A:
        if abs(N/2 - a) < min_distance:
            min_distance = abs(N/2 - a)
            M = a
    print("{} {}".format(N, M))

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

a = sorted(a, reverse=True)

comb = -1
a_i = a[0]
if a_i % 2 == 0:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if dif > abs(a[i]-mid):
            dif = abs(a[i]-mid)
            a_j = a[i]
else:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if a[i] > mid:
            if dif > abs(a[i]-mid-1):
                dif = abs(a[i]-mid-1)
                a_j = a[i]
        else:
            if dif > abs(a[i]-mid):
                dif = abs(a[i]-mid)
                a_j = a[i]

print(a_i, a_j)

Solution (Python):
n = int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
max = a[-1]
tmp = 0
for i in range(len(a)):
    if a[i] > max/2:
        tmp=i-1
        break
if max/2-a[tmp] <= -max/2+a[tmp+1]:
    print("{} {}".format(max, a[tmp]))
else:
    print("{} {}".format(max, a[tmp+1]))

Solution (Python):
def abs(c): 
    if c > 0: 
        return c 
    else: 
        return -c

    n = int(input())
n = int(input())
a = [int(i) for i in input().split()]
h = len(a)
a.sort()
t = a[h-1]
s = a[0]
center = t/2
interval = abs(center-s)

for i in range(1,h-1):
    if abs(center-a[i]) < interval:
        s = a[i]
        interval = abs(center-a[i])
        
print(t,end="")
print(" ",end="")
print(s)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a,reverse=True)
x=a[0]
a=a[1:]
y=min([(i,x-i) for i in a], key=max)[0]
print("{} {}".format(x, y))

Solution (Python):


import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - maxl/2)**2
com = X[np.where(Xed == np.min(Xed))]

print(maxl,com[0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
m = a[0]
ans = a[0]
if a[0]%2 == 0:
    b = a[0]//2
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

else:
    b = a[0]//2 + 0.5
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
m = a[0]
ans = a[0]
if a[0]%2 == 0:
    b = a[0]//2
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

else:
    b = a[0]//2 + 0.5
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

Solution (Python):


import math

def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = max(a)
    a.remove(m)

    ans = m
    h = m / 2
    dif = 9999999999
    for num in a:
        if abs(h - num) < dif:
            ans = num
            dif = abs(h - num)

    print(m)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

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


ai = max(a)
a.remove(ai)


abs_dist = [abs(a_temp-(ai/2)) for a_temp in a]
chosen_temp = min(abs_dist)
aj = a[abs_dist.index(chosen_temp)]

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

Solution (Python):
from sys import stdin


def main():
    n = int(stdin.readline().rstrip())
    ai = [int(x) for x in stdin.readline().rstrip().split()]
    ai = sorted(ai)
    ans1 = ai[-1]
    a = ans1 / 2
    before = ans1
    beforei = 0
    ans2 = ai[0]
    for i in ai[:-1]:
        d = abs(a - i)
        
        if before < d:
            ans2 = beforei
            break
        before = d
        beforei = i

    print(ans1, ans2)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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




a1=max(a)
a.remove(a1)
a2=a1/2
b=[]
for i in a:
  b.append(abs(i-a2))

print(a1,a[b.index(min(b))])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A.sort()
T={}
for i in range(n-1):
    T[abs(A[i]-(A[-1]-A[i]))] = A[i]

T_min = min(T.items())

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

Solution (Python):


n = int(raw_input())
l = map(int, raw_input().split())

l.sort()

n = l[-1:][0]


def factorial(n):
    buff = n
    c_n = 1
    while buff > 0:
        c_n = c_n * n
        buff = buff - 1
    return c_n

i = 0
flag = True
while i < len(l) - 1:
    if i == len(l) - 2: 
        break
    c1 = (n - l[i+1]) * l[i+1]
    c2 = (n - l[i]) * l[i]
    if c1 < c2:
        break
    i = i + 1
print("{} {}".format(n,l[i]))

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = max(a)
c = b // 2
s = bisect.bisect_right(a, c)
min_a = abs(c-(b-a[s]))
min_b = abs(c-(b-a[s-1]))
if min_a < min_b:
    ans = a[s]
else:
    ans = a[s-1]
print("{} {}".format(b,ans))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
max_num = max(a)
diff = max_num / 2
a.remove(max_num)
min_num = [abs(i - diff) for i in a]
min_num = a[min_num.index(min(min_num))]
print(max_num, min_num)

Solution (Python):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    max_num = max(a)
    dif = 10**10
    ansnum = 0
    for num in a:
        if(num != max_num and dif > abs((max_num/2) - num)):
            dif = abs((max_num/2) - num)
            ansnum = num
            
    print("{} {}".format(max_num, ansnum))
        
if __name__=="__main__":
    main()

Solution (Python):
import numpy as np

n = int(input())
A = list(map(int, input().split()))
As = sorted(A)
m = As[-1]
s = np.searchsorted(As,m/2)
d1 = abs(m/2-As[s])
d2 = abs(m/2-As[s-1])
if d1 >= d2:
    r = As[s-1]
else:
    r = As[s]
print(m,r)

Solution (Python):
from math import factorial
import sys

def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

    n = max(A)
    A.remove(n)
    A.sort()
    max_r = n/2
    max_r_2 = n - max_r
    min_sub = sys.maxint
    r = 0
    for i in range(len(A)):
        if abs(max_r - A[i]) < min_sub or abs(max_r_2 - A[i]) < min_sub:
            min_sub = min(abs(max_r - A[i]), abs(max_r_2 - A[i]))
            r = A[i]





    print n, r


if __name__ == '__main__':
    main()

Solution (Python):
import bisect


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])

def get_comb(num, sort_numbers):
    index = bisect.bisect(sort_numbers, int(num/2))
    left = sort_numbers[index-1]
    right = sort_numbers[index]
    choose_num = left if abs(num/2 - left) < abs(num/2 - right) or right == num else right
    return choose_num

def solve():
    N = get_next_int()
    numbers = get_next_ints()
    max_num, max_choose = 0, -1
    sort_numbers = sorted(numbers)
    for num in sort_numbers[int(len(sort_numbers)/2):][::-1]:
        choose = get_comb(num, sort_numbers)
        if choose > max_choose:
            max_num = num
            max_choose = choose
    print(max_num, max_choose)



solve()

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

a = sorted(a)
x1 = max(a)
x2 = min(a)
k = x1

for i in a:
    if  abs(x1/2 - i)< k:
        x2 = i
        k = abs(x1/2 - i)
    else:
        break

print(x1,x2)

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

def f(N, A):
    
    if len(A) == 2:
        A.sort()
        print(A[1], A[0])
        return

    res = 0
    temp = 0
    maxA = max(A)

    for a in A:
        if a == maxA:
            continue
        
        b = min(a, maxA - a)
        if temp < b:
            temp = b
            res = a
        
    return print(maxA, res)

f(N, A)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a.remove(m)
l = 10**9
t = a[0]
for i in range(n-1):
  if abs(m/2-a[i]) < l:
    l = abs(m/2-a[i])
    t = a[i]

print(m, t)

Solution (Python):
N = input()
N = int(N)
A = input()
array = A.split()
ind = 0
for n in array:
    array[ind] = int(n)
    ind = ind+1

mx = max(array)
array.remove(mx)
haf = mx/2
x = [abs(e-haf) for e in array]
min_idx = x.index(min(x))
r = array[min_idx]

print(mx, r)

Solution (Python):
def check(m, mid, A):
    tmp = abs(A[mid] - m)
    if mid > 0:
        tmp = min(tmp, abs(A[mid - 1] - m))
    if len(A) - 1 > mid:
        tmp = min(tmp, abs(A[mid + 1] - m))
    return tmp != abs(A[mid] - m)

def nbt(m, A):
    left = 0
    right = len(A)
    mid = (left + right) // 2
    while check(m, mid, A):
        if A[mid] > m:
            right = mid
        elif m > A[mid]:
            left = mid
        mid = (left + right) // 2
    return A[mid]

        
n = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1], nbt(A[-1] / 2, A[:-1]))

Solution (Python):
from itertools import *
from bisect import *
from operator import *
import math

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

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

a_item = sorted(a)
a_max = a_item[-1]
a_item = a_item[:-1]
bisect_l_item = bisect_left(a_item, a_max//2)

if bisect_l_item >= n - 1:
    bisect_l = a_item[bisect_l_item - 1]
else:
    bisect_l = a_item[bisect_l_item]

bisect_r = a_item[bisect_l_item - 1]
if abs(bisect_r - a_max/2) <= abs(bisect_l - a_max/2):
    print(a_max, bisect_r)
else:
    print(a_max, bisect_l)

Solution (Python):

def main():
   N = int(input())
   a = list(map(int, input().split()))
   a.sort()
   A = a.pop()
   k = A/2
   for i in a:
      if k - i == 0:
         B = i
         break
      else:
         sa = k - i
         if sa < 0:
            if abs(B-k)>abs(sa):
               B = i
            break
         B = i
   return str(A)+" "+str(B)
         


print(main())

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

maxA=max(a)
midA=0
for ai in a:
    if abs(midA-maxA/2)>abs(ai-maxA/2):
        midA=ai

print(maxA,midA)

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

M = max(li)
li.remove(M)

N = int(M//2)
li_sa = [abs(li[i] - N) for i in range(n-1)]
m = min(li_sa)
k = li_sa.index(m)

N = li[k]

print(str(M)+" "+str(N))

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

low = 0
high = len(a_sorted) - 1

val = 10 ** 9 
absd = 10 ** 9 

while low <= high:
    mid = (low + high) // 2
    guess = a_sorted[mid]
    d = (ai / 2) - guess
    if absd > abs(d):
        absd = min(absd, abs(d))
        val = guess
    if d < 0:
        high = mid - 1
    else:
        low = mid + 1
print('{} {}'.format(ai, val))

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

def deff_half(l, h):
    d = abs(h/2 - l[0])
    r = 0
    for i in range(1, len(l)):
        if l[i] == h:
            continue
        if d >= abs(h/2 - l[i]):
            d = abs(h/2 - l[i])
            r = i
    return l[r]
    
n = int(input())
x = list(map(int, input().split(" ")))
 
a = max(x)
result = deff_half(x, a)

print(a , result)

Solution (Python):


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

max_value = max(number_list)
middle = max_value/2
number_list.remove(max_value)

diff_list = [abs(element-middle) for element in number_list]
nearest = number_list[diff_list.index(min(diff_list))]
print("{0} {1}".format(max_value, nearest))

Solution (Python):
from math import factorial
n = int(input())
a = [int(i) for i in input().split()]
sa = sorted(a,reverse=True)
m = sa[0]
sb = sa[1:]
k = [i if m - i > i else m - i for i in sb]
i = k.index(max(k))
print(m, sb[i])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
x=max(A)
A.remove(x)
B=[abs(x/2-a) for a in A]
y=A[B.index(min(B))]
print(x,y)

Solution (Python):
N = int(input())
a = sorted(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

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

a_max = 0

for ai in a:
    a_max = max(a_max, ai)

if a[0] != a_max:
    m = a[0]
else:
    m = a[1]

for ai in a:
    if ai == a_max or ai == m:
        continue

    if ai > m and ai < a_max - m:
        m = ai
    elif ai < m and ai > a_max - m:
        m = ai

print(a_max, m)

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

ai = sortx[n-1]
mid = float(ai)/2
x2 = sorted(abs(k - mid)for k in x)[0]

if (mid - x2) in x:
    aj = int(mid - x2)
else:
    aj = int(mid + x2)

print(ai," ",aj)

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
A.sort()
ma=0
mi=0
cnt=A[N-1]
for i in range(N-1):
  if ma<=A[i]*(cnt-A[i]):
    ma=A[i]*(cnt-A[i])
    mi=A[i]
  else:
    break
print(cnt,mi)

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

N = [int(i) for i in input().split()]
N_max = max(N)
if N_max % 2 == 0:
    N_mid = N_max / 2
else:
    N_mid = (N_max+1) / 2
d = 10000000000
ans = 0

for i in range(n):
    if N[i] == N_max:
        continue
    a = abs(N_mid-N[i])
    if d > a:
        ans = N[i]
        d = a
        
print(N_max,ans)

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

biggest = max(a)
base = biggest / 2

res = None
diff = float("inf")
for elem in a:
    if diff > abs(base - elem):
        diff = abs(base - elem)
        res = elem
if biggest != res:
    print(biggest, res)
else:
    print(biggest, 0)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

if n == 2:
    if a[0] > a[1]:
        print(a[0],a[1])
    else:
        print(a[1],a[0])
else:
    x = max(a)
    mid = x / 2
    a.remove(x)

    diff = abs(mid - a[0])
    ans = 0
    for i in range(len(a)):
        if diff > abs(mid - a[i]):
            diff = abs(mid - a[i])
            ans = i
    print(x,a[ans])

Solution (Python):
N = int(input())
a = [i for i in map(int , input().split())]
a.sort()
ai = a[N-1]
tmp = ai // 2
aj = 0
if ai % 2 == 0:
    for  i in a :
        if tmp == i:
            aj = i            
            break
        elif i - tmp > 0:
            if i - tmp < tmp - aj:
                aj = i
            break
        aj = i
else :
    for  i in a :
        if tmp == i:
            aj = i            
            break
        elif i - tmp > 0:
            if i - tmp <= tmp - aj:
                aj = i
            break
        aj = i

        
print(ai,aj)

Solution (Python):


import numpy as np
import scipy.misc as sc
def getNearestValue(listA, num):
    idx = np.abs(np.asarray(listA) - num).argmin()
    return listA[idx]
    
lenlist=input()
List=list(map(int,input().split()))
if lenlist=="2":
    List.sort()
    n=List[1]
    r=List[0]
    print(n,r)
    quit()
n=max(List)
r=getNearestValue(List,n/2)
print(n,r)

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

n = max(a)
r = n

if n_ == 2:
    print(max(a), min(a))

else:
    for i in a:
        if abs(r-int(n/2)) > abs(i-int(n/2)):
            r = i

    print(n, r)

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

n = max(a)
r = 0
M = 0
mid = n / 2
diff = 1000000000
for x in a:
    if x == n:
        continue
    if diff > abs(mid - x):
        diff = abs(mid - x)
        r = x

print(n, r)

Solution (Python):

n = int(input())
li = list(map(int,input().split()))
copied = li.copy()
copied.sort()

ans1 = copied[-1]

ans2 = copied[0]

for i in range(1, n):
    if abs(copied[i] - (ans1 / 2)) < abs(ans2 - (ans1 / 2)):
        ans2 = copied[i]

print("%s %s" %(ans1, ans2))

Solution (Python):
def d_binomial_coefficients(N, A):
    if N == 2:
        return '{} {}'.format(max(A), min(A))
    import numpy
    max_a = max(A)
    tmp = max_a / 2
    idx = numpy.abs(numpy.asarray(A) - tmp).argmin()
    ans = '{} {}'.format(max_a, A[idx])
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(d_binomial_coefficients(N, A))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
s = max(a)
if s % 2 == 0:
    mid = s // 2
else:
    mid = s // 2 + 1
diff = float("inf")
rec1, rec2 = 0, 0
for i in range(n):
    p = abs(a[i] - mid)
    if p < diff:
        diff = p
        rec2 = a[i]

print(s, rec2)

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

p = max(a)
q = 0
for i in range(n):
    m = abs(a[i]-p/2)
    if m < abs(q-p/2):
        q = a[i]
        

print(p,q)

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

k = max(data)
idx = [abs(data[i] - (k/2)) for i in range(n)]
msa = int(min(idx) + k/2)
msb = int(k/2 - min(idx))
if msa in data and msa == k:
    print(k,0)
elif msa in data:
    print(k,msa)
else:
    print(k,msb)

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

P = a[n-1]/2
S = 0
T = 0

for i in range(n):
    if a[i] > P:
        S = a[i-1]
        T = a[i]
        break


if abs(S-P) <= abs(T-P):
    print(a[n-1],S)
else:
    print(a[n-1],T)

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

if len(A) == 2:
    print(A[0], A[1])
else:
    res0 = max(A)
    temp = max(A) / 2

    hoge = 9999999999
    for a in A:
        if abs(a - temp) < hoge:
            hoge = abs(a - temp)
            res1 = a

    print(res0, res1)

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

ans1 = max(a)
sa = sorted(a)

if n == 2:
    ans1 = a[0]
    ans2 = a[1]
else:
    idx = n // 2
    flag = True
    if sa[idx] == ans1 // 2:
        ans2 = ans1 // 2
    elif sa[idx] < ans1 // 2:
        while True:
            idx += 1
            if ans1 // 2 <= sa[idx]:
                if abs(sa[idx] - ans1 / 2) < abs(sa[idx - 1] - ans1 / 2):
                    ans2 = sa[idx]
                else:
                    ans2 = sa[idx - 1]
                break
    else:
        while True:
            idx -= 1
            if sa[idx] <= ans1 // 2:
                if abs(sa[idx] - ans1 / 2) < abs(sa[idx + 1] - ans1 / 2):
                    ans2 = sa[idx]
                else:
                    ans2 = sa[idx + 1]
                break

print(ans1, ans2)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
ai = max(a_list)

a_list.remove(ai)

new_a_list = [abs(ai / 2 - a) for a in a_list]
aj = a_list[new_a_list.index(min(new_a_list))]
    
print(ai, aj)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
B = [abs(i-maxA/2) for i in A]
mid_pA = int(min(B) + maxA/2)
mid_mA = int(-min(B) + maxA/2)
A.sort()
for i in A[:N]:
    if i == mid_pA:
        print(maxA,mid_pA)
        break
    elif i == mid_mA:
        print(maxA,mid_mA)
        break

Solution (Python):
import copy

N = int(input())
num = list(map(int,input().split()))
memo = copy.deepcopy(num)
num.sort()

ans1 = num[0]
ans2 = num[N-1]
min = abs(ans2/2-num[0])
for i in range(1,N-1):
  if abs(ans2/2-num[i]) < min:
    ans1 = num[i]
    min = abs(ans2/2-num[i])
print(ans2,ans1)

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

Solution (Python):
n=int(input().rstrip())
A=list(map(int, input().rstrip().split())) 
A.sort()
work=int()
bestr=int(A[0])






for i in range(n-2):
    if abs(A[i]-A[n-1]/2)<abs(bestr-A[n-1]/2):
        bestr=A[i]
print("{0} {1}".format(A[n-1],bestr))

Solution (Python):
import sys
import numpy as np

N = int(sys.stdin.readline().strip())
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

index = np.argmax(a)
n = a.pop(index)

m = -1
tmp = n

for e in a:
    if abs((n/2) - e) < tmp:
        tmp = abs((n/2) - e)
        m = e
        
print(str(n) + " " + str(int(m)))

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


m = max(a)
a_ = sorted(a)[:n]
n = a_[np.abs(np.asarray(a_) - m/2).argmin()]
print(m, n)

Solution (Python):
import numpy as np

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

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

xs_arranged = sorted(xs)

ai = xs_arranged[-1]
xs_arranged.pop(-1)

aj = getNearestValue(xs_arranged, (ai/2))
    
print(ai,aj)

Solution (Python):
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

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


n = int(input())
a = list(map(int, input().split()))
ma = max(a)
h = getNearestValue(a, ma//2)
if h == ma:
    h = 0
print(ma, h)

Solution (Python):

n = int(input())
a = [0]*n
a = list(map(int, input().split()))

a.sort()
hoge = a[n-1] / 2 - a[0]
ans = 0
for i in range(n-1):
    if abs(a[n-1] / 2 - a[i+1]) > hoge:
        ans = i
        break
    else:
        hoge = abs(a[n-1] / 2 - a[i+1])

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

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