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

a_list_min = sorted(a_list)
ai = a_list_min[-1]

mid_ai = ai // 2

for i in range(n):
    if a_list_min[i] >= mid_ai:
        if i == 0:
            aj = a_list_min[i]
        elif i == n-1:
            aj = a_list_min[i-1]
        else:
            if a_list_min[i] - mid_ai > mid_ai - a_list_min[i-1]:
                aj = a_list_min[i-1]
            else:
                aj = a_list_min[i]
        break
print(ai, aj)

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

n, r = max(a), -pow(10, 9)
a.remove(n)
for ai in a:
    if abs(n // 2 - r) > abs(n // 2 - ai):
        r = ai
print(n, r)

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

n, r = max(a), -pow(10, 9)
for ai in a:
    if abs(n // 2 - r) > abs(n // 2 - ai) and ai != n:
        r = ai
print(n, r)

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

n, cnt, r = max(a), max(a) // 2, -pow(10, 9)
for ai in a:
    if abs(cnt - r) > abs(cnt - ai) and ai != n:
        r = ai
print(n, r)

Solution (Python):
n = int(input())
Alist = list(map(int,input().split()))
Alist.sort()
n = Alist[-1]
if n%2 == 0:
    R = n//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R) < rmin:
            r = i
            rmin = abs(r-R)
else:
    R1 = (1+n)//2
    R2 = (n-1)//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R1) < rmin or abs(i-R2) < rmin:
            r = i
            rmin = min(abs(r-R1),abs(r-R2))
print(n,r)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
comba = max(a)
ref = 10**10

for i in a:
    temp = abs(i - comba/2)
    if ref > temp:
        if comba > i:
            ref = temp
            combb = i

print(comba, combb)

Solution (Python):
from bisect import *

N = int(input())
A = list(map(int, input().split()))
A.sort()
i = bisect_left(A,A[-1]/2)
if A[i] - A[-1]/2 < A[-1]/2 - A[i-1]:
    a = A[i]
else:
    a = A[i-1]
print(A[-1], a)

Solution (Python):
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
di = ls[:]
di.append(ls[-1]//2)
di.sort()
ind = di.index(ls[-1]//2)
il,ir = -1,-1
if ind > 0:
    il = ind - 1 
if ind < n-1:
    ir = ind + 1
if il < 0 or ir < 0:
    now = max(ir,il)
else:
    if ls[-1] % 2 == 0:
        if abs(ls[-1]//2 - di[ir]) < abs(ls[-1]//2 - di[il]):
            now = di[ir]
        else:
            now = di[il]
    else:
        if min(abs(ls[-1]//2 - di[ir]),abs(ls[-1]//2 + 1 - di[ir])) < min(abs(ls[-1]//2 - di[il]),abs(ls[-1]//2 + 1 - di[il])):
            now = di[ir]
        else:
            now = di[il]
print(ls[-1],now)

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

ma=max(a)
mi=float('inf')
ans=0
for i in range(n-1):
  sa=ma-a[i]
  if abs(a[i]-sa)<=mi:
    mi=abs(a[i]-sa)
    ans=a[i]

print(ma,ans)

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

ma=max(a)
half=ma//2
mi=float('inf')
for i in range(n):
  if abs(half-a[i])<=abs((half-mi)) and ma!=a[i]:
    mi=a[i]

print(ma,mi)

Solution (Python):
n = input()
l = list(map(int, input().split()))
m = max(l)
if n == '2':
    print(m,min(l))
else:
    r = min(l, key = lambda x: abs(x-(m//2)))
    print(m,r)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]/2
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(ans-A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

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

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

if n==2:
  print(str(max(a))+" "+str(min(a)))
  quit()

a.sort()
ans1=a.pop(n-1)

num = ans1//2
c = bisect_left(a, num)
cand1 = a[c]

if c!=0:
  cand2 = a[c-1]
  if abs(cand2-ans1/2)<abs(cand1-ans1/2):
    cand1=cand2
print(str(ans1)+" "+str(cand1))

Solution (Python):


import bisect
import math

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    n = II()
    a = LII()

    a.sort()
    n = a.pop(-1)
    mn = 10**9
    for ai in a:
        if abs(n//2 - ai) <= abs(n//2 - mn):
            mn = ai
    

    print(n, mn)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
one = max(a)
if one%2 == 0:
    test = one//2
else:
    test = one//2+1
x = float("inf")
diff = float("inf")
for i in a:
    if i < one:
        if abs(test-i) < diff:
            x = i
            diff = abs(test-i)
print(one,x)

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

max_val = a.pop()

max_dif = 10 ** 100
ret = 0

for item in a:
    dif = abs(max_val - item * 2)
    if max_dif > dif:
        ret = item
        max_dif = dif

print(max_val, ret)

Solution (Python):
n, *A = map(int, open(0).read().split())
A.sort()
a = A.pop()
b = min(A, key=lambda x: abs(x - a / 2))
print(a, b)

Solution (Python):
from bisect import *
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = a[-1]/2
b = bisect_left(a,ans)
if abs(ans-a[b]) < abs(ans-a[b-1]):
  print(a[-1],a[b])
else:
  print(a[-1],a[b-1])

Solution (Python):
from bisect import *
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = a[-1]//2
b = bisect_left(a,ans)
if a == [0,100]:
  print(100,0)
  exit()
if abs(ans-a[b]) <= abs(ans-a[b-1]):
  print(a[-1],a[b])
else:
  print(a[-1],a[b-1])

Solution (Python):

import sys
import math

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
mid = a[-1] / 2
ans = 10 ** 9
l = 0
for i in range(n):
    if ans > abs(mid - a[i]):
        ans = abs(mid - a[i])
        l = a[i]
print(a[-1], l)

Solution (Python):



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


def main():
    W = sorted(A)
    a = W[-1]
    h = a / 2
    b = W[0]
    for x in W[1:-1]:
        if max(b - h, h - b) > max(x - h, h - x):
            b = x
    print(a, b)


if __name__ == "__main__":
    main()

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A.sort()

n = A[-1]

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

Solution (Python):



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

Solution (Python):
N, = map(int, input().split())
As = list(map(int, input().split()))
am = max(As)
bm = (0,0)
for i, a in enumerate(As):
    if min(am-a, a) > min(bm):
        bm = (a, am-a)
print(am, bm[0])

Solution (Python):
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
ai = A[-1]

tmp = ai / 2
i = bisect.bisect_left(A, tmp)
if abs(tmp - A[i]) < abs(tmp - A[i - 1]):
    print(ai, A[i])
else:
    print(ai, A[i - 1])

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

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

Solution (Python):
from bisect import *

n=int(input())
a=sorted(list(map(int,input().split())))
N=a[-1]
inx=bisect(a,N//2)
a=[a[0]]+a+[a[-1]]
th=10**9
for i in [a[inx-1],a[inx],a[inx+1]]:
 if abs(i-N//2)<=th and i<N:
  R=i
  th=abs(i-N//2)
print(N,R)

Solution (Python):
import numpy as np
import bisect
def getNearestValue(list_, num):
    idx = np.abs(np.asarray(list_) - num).argmin()
    return list_[idx]

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

A.sort()
a=A[-1]
print(a,getNearestValue(A,a/2))

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
if n == 2:
    print(max(a), min(a))
    exit()

a.sort()
ans1 = a[-1]
tmp = ans1 // 2
index = bisect.bisect_left(a, tmp)
tmp1 = abs(tmp - a[index - 1])
tmp2 = abs(tmp - a[index])
if tmp1 < tmp2:
    ans2 = index - 1
else:
    ans2 = index

print(ans1, a[ans2])

Solution (Python):
import bisect as bi

n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1];a=a[:-1]

i=max(bi.bisect_left(a,m/2)-1,0)
j=min(i+1,n-2)

if m/2-a[i]<a[j]-m/2:
    r=a[i]
else:
    r=a[j]

print(m,r)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    max_a = max(a)
    ideal_comb = []
    if max_a % 2 == 0:
        ideal_comb.append(max_a // 2)
    else:
        ideal_comb.append(max_a // 2)
        ideal_comb.append(max_a // 2 + 1)

    diff = [0] * n

    for i in ideal_comb:
        for j in range(n):
            if a[j] == max_a:
                diff[j] += 10 ** 10
            else:
                diff[j] += abs(a[j] - i)

    tmp = diff.index(min(diff))

    print(max_a, a[tmp])

    


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    m = a[-1] / 2
    i = bisect(a, m)
    d0 = m - a[i - 1]
    d1 = a[i] - m
    if d0 < d1 or i == n - 1:
        print(a[-1], a[i - 1])
    else:
        print(a[-1], a[i])

main()

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

x=A.pop()
dif=0
ans=0
for i in range(n-1):
    a=A[i]
    tmp=min(a, x-a)
    if tmp>=dif:
        dif=tmp
        ans=a

print(x, ans)

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
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() 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)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007




n = I()
L = sorted(LI())
a = L[-1]
L = L[:-1]
l = bisect_left(L, a / 2)
if l < n - 1 and L[l] - a / 2 < a / 2 - L[l - 1]:
    print(a, L[l])
else:
    print(a, L[min(l - 1, n-2)])

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

if half_ind == 0:
    print(str(a[-1]) + " " + str(a[half_ind]))
elif half_ind == n - 1:
    print(str(a[-1]) + " " + str(a[half_ind - 1]))
else:
    if abs(2 * a[half_ind] - a[-1]) > abs(2 * a[half_ind - 1] - a[-1]):
        print(str(a[-1]) + " " + str(a[half_ind - 1]))
    else:
        print(str(a[-1]) + " " + str(a[half_ind]))

Solution (Python):

def main():
    
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    mid, r, cur = n / 2, -1, float("inf")
    for i in A:
        if i != n:
            x = abs(mid - i)
            if x < cur:
                r, cur = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import bisect


def solve(n: int, a: "List[int]"):
    a.sort()
    N = a[-1]
    i = bisect.bisect(a, N // 2)
    candidate = [a[i]]
    if i > 0:
        candidate.append(a[i-1])
    if i < n-1:
        candidate.append(a[i+1])
    m = N*2
    for c in candidate:
        if c == N:
            continue
        if abs(N//2 - c) < abs(N//2 - m):
            m = c
    print(N, m)
    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):
def find(A):
    A=sorted(A)
    MAX=A[-1]
    mid=MAX/2
    MIN=MAX
    need=-1
    for i in range(len(A)-1):
        if abs(A[i]-mid)<MIN:
            need=A[i]
            MIN=abs(A[i]-mid)
    return (MAX,need)
input()
x,y=find(list(map(int,input().strip().split(' '))))
print("{} {}".format(x,y))

Solution (Python):
import bisect

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

A = sorted(A)

ans1 = A[-1]

ind = bisect.bisect_left(A, ans1/2)


c = float("inf")
for i in range(max(0,ind-1), min(N-1,ind+2)) :
    calc = abs(ans1/2 - A[i])
    if calc < c :
        ans2 = A[i]
        c = calc
print(ans1,ans2)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
a1=max(A)
a2=0
for a in A:
    if abs(a1//2-a2)>abs(a1//2-a):
        a2=a
print(a1,a2)

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

x = max(a)

y = 0
for i in range(n):
    if abs(a[i]*2-x)<abs(y*2-x) and a[i]!=x:
        y = a[i]
print(x,end=' ')
print(y)

Solution (Python):
n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop()
dif=float("inf")
ans=0
for i in range(n-1):
    if abs(a[i]-b/2)<dif:
        ans=a[i]
        dif=abs(a[i]-b/2)
print(b,ans)

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

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

if len(A) == 2:
    print(A[1])
    print(A[0])

half = A[-1] / 2
for i in range(N-2):
    if abs(A[i]-half) >= abs(A[i+1]-half) <= abs(A[i+2]-half):
            print(A[-1])
            print(A[i+1])
            exit()

Solution (Python):
def getlist():
	return list(map(int, input().split()))

n = int(input())
a = getlist()
a = sorted(a)
x = a[-1]
xx = x / 2
y = 0
s = float("inf")
for i in range(n - 1):
	if abs(xx - a[i]) < s:
		s = abs(xx - a[i])
		y = a[i]

print(x, y)

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

maxi = a[-1]
mini = 1000000001
for i in range(n-1):
    if abs(maxi/2 - a[i]) < mini:
        minindex = i
        mini = abs(maxi/2 - a[i])
print(maxi, a[minindex])

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

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

Solution (Python):
def upperbound(zs, left, right, ok):
    if left + 1 >= right:
        return left
    m = (left + right) // 2
    if ok(zs[m]):
        return upperbound(zs, m, right, ok)
    else:
        return upperbound(zs, left, m, ok)

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

ds = sorted(xs)

a = ds[-1]
c = a / 2
zs = [d - c for d in ds[:-1]]

i = upperbound(zs, 0, len(zs)-1, lambda z: z<=0)

j = i+1 if i < len(zs)-1 else i

b = ds[i] if abs(zs[i]) < abs(zs[j]) else ds[j]

print(a, b)

Solution (Python):
n = int(input())
alist = list(sorted(map(int, input().split())))
maxa = alist[-1]
halfa = maxa / 2
mina = maxa
a2 = 0
for a in alist:
  if abs(halfa - a2) > abs(halfa - a):
    a2 = a
print(maxa, a2)

Solution (Python):
input();a=list(map(int,input().split()));m=max(a);b=[abs(2*i-m+0.1) for i in a];print(m,a[b.index(min(b))])

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

Solution (Python):
input();a=list(map(int,input().split(' ')));m=max(a);a.remove(m);b=[abs(2*i-m) for i in a];print(m,a[b.index(min(b))])

Solution (Python):
import numpy as np;input();a=list(map(int,input().split(' ')));m=max(a);a.remove(m);b=[abs(2*i-m) for i in a];j=b.index(min(b));print(m,a[j])

Solution (Python):
from bisect import bisect_left
n = int(input())
a = sorted(list(map(int, input().split())))
r = bisect_left(a, a[-1]/2)
l = r-1 if r else 0
if abs(a[-1]/2 - a[l]) > abs(a[-1]/2 - a[r]):
    l,r = r,l
print(a[-1],a[l])

Solution (Python):
import bisect

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A = sorted(A)

ma = A[-1]
A = A[:-1]
mi = -1
mid = ma/2

mid_ind = bisect.bisect_left(A, mid)
l = n-1
if mid_ind >= l:
    mi = A[-1]
elif mid_ind <= 0:
    mi = A[0]
else:
    if abs(A[mid_ind]-mid) > abs(A[mid_ind-1]-mid):
        mi = A[mid_ind-1]
    else:
        mi = A[mid_ind]
print(ma, mi)

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

a.sort()
b = []
c = a[-1]/2
for i in range(n-1):
    b.append(abs(a[i]-c))

k = b.index(min(b))

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

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


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


x = A.pop()
N -= 1
for i in range(N):
    if A[i] > x // 2:
        break
if abs(A[i] - x / 2) < abs(A[i - 1] - x / 2):
    print(x, A[i])
else:
    print(x, A[i - 1])

Solution (Python):



def main():

    n = input()
    a = sorted(list(map(int, input().split())))
    ai = max(a)
    a.remove(ai)
    aj = float('inf')
    tmp = float('inf')

    for aa in a:
        diff = abs(ai / 2 - aa)

        if diff < tmp:
            tmp = diff
            aj = aa

    print(ai, aj)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ma = max(a)
    diff = 100000000000000
    ans = 0
    for aa in a:
        t = abs(ma//2-aa)
        if ma != aa and diff > t:
            diff = t
            ans = aa
    print(ma,ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
mid = A[-1]/2
Aj = A[0]
for i in range(1, N-1):
    if abs(A[i] - mid) < abs(Aj - mid):
        Aj = A[i]
print(A[-1], Aj)

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

ai = max(a)
a.remove(ai) 
ans = 0
for aj in a:
    if min(ans,ai-ans) < min(aj,ai-aj):
        ans = aj
print(ai,ans)

Solution (Python):

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

maxa = max(a)
mida = min(a)
for x in a:
    
    if abs(maxa//2 - x)<abs(maxa//2-mida):
        mida = x
print(maxa, mida)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A1=max(A)
A2=(-1)
for i in range(N):
    if A[i]==A1:
        pass
    elif abs(A1/2-A[i])<abs(A1/2-A2):
        A2=A[i]
print(A1,A2)

Solution (Python):
input()
a=list(map(int,input().split()))
m=max(a)
d=min(a,key=lambda d:abs(m-2*d)if m!=d else 1e18)
print(m,d)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(a)
for j in a:
    if abs(ai - 2 * aj) > abs(ai - 2 * j):
        aj = j
print(ai, aj)

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


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


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

n = getN()
nums = getList()

c1 = max(nums)
nums.sort()
nums = nums[:-1]

c2 = 0
dif = float(c1)/2

for num in nums:
     diff = abs(float(c1)/2 - float(num))
     if diff < dif:
         dif = diff
         c2 = num

print(c1, c2)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
y = max(a[: -1], key=lambda a_i: min(a_i, a[-1] - a_i))
print(x, y)

Solution (Python):
'''input
2
100 0
'''
n = input()
arr = map(int,raw_input().split())
m = max(arr)
zz = float(m)/2
diff = 10**20
arr.sort()
for i in range(n):
	if abs(arr[i]-zz) < diff:
		diff = abs(arr[i]-zz)
		ans = arr[i]
print m,ans

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

y = max(x)
sub = y
res = 0
for i in range(n):
    if abs(float(y/2-x[i])) < sub and x[i] != y:
        sub = abs(float(y/2-x[i]))
        res = x[i]

print(y,res)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
a.remove(ans1)
ans2=min(a,key=lambda b:abs(ans1/2-b))
print(ans1,ans2)

Solution (Python):
import math

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

N=int(input())
a=list(map(int,input().split()))
maxoutput=0
output=0


a.sort(reverse=True)
n=a[0]
r=a[N-1]

for i in range(1,N):
  if abs(r-n/2)>abs(a[i]-n/2):
    r=a[i]
print(n,r)

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

    x, y = max(a), min(a)
    for i in range(n):
        if abs(a[i]-x/2) < abs(y-x/2):
            y = a[i]

    print(x, y)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect

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

med = a_list[-1] / 2
idx = bisect.bisect_left(a_list, med)

if (med - a_list[idx-1]) > (a_list[idx] - med):
    print('%d %d' % (a_list[-1], a_list[idx]))
else:
    print('%d %d' % (a_list[-1], a_list[idx-1]))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

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

def reads():
  return [int(x) for x in input().split()]

n = read()
a = sorted(reads())

x = a.pop()
y = sorted((abs(x-2*p), p) for p in a)[0][1]
print(x, y)

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

l = max(a)
r = 0
d = 10**9
for i in range(n):
    if (l == a[i]):
        continue
    tmp = abs(l - 2*a[i])
    if (tmp < d):
        r = a[i]
        d = tmp

print("{0} {1}".format(l, r))

Solution (Python):


def dist(x, y):
    assert 0 <= y <= x
    return min(y, x - y)

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ai = sorted(ai)

    x = ai[-1]
    y = ai[0]
    for i in range(n - 1):
        if dist(x, ai[i]) > dist(x, y):
            y = ai[i]

    print("%d %d" % (x, y))

main()

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

l=a[-1]
r=a[0]
for num in a:
    if abs(num-l/2)<abs(r-l/2):
        r=num
print(str(l)+" "+str(r))

Solution (Python):

import sys



n = int(sys.stdin.readline().strip())
aArray = list(map(int, sys.stdin.readline().strip().split(" ")))



sortedArray = sorted(aArray)
maxNum = max(aArray)
idealHalfNum = maxNum / 2

i = 0
while abs(idealHalfNum - sortedArray[i]) > abs(idealHalfNum - sortedArray[i+1]):
    i = i + 1


print(maxNum, sortedArray[i])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = a[n - 1]
ans2 = a[0]
for i in range(n):
    ans2 = max(ans2, min(a[i], ans1 - a[i]))
exist = False
for i in range(n):
    if (ans2 == a[i]):
        exist = True
if (exist):
    print(ans1, ans2)
else:
    print(ans1, ans1 - ans2)

Solution (Python):
input()
da = list(map(int,input().split()))
 
x = max(da)
y = x + 1
for i in da:
  if i == x:
    continue
  if abs(x/2 - i ) <= abs(x/2 - y):
    y = i
print(x,y)

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

x = max(a)
y = x + 1
for e in a:
	if x == e:
		continue
	if abs(x / 2 - e) < abs(x / 2 - y):
		y = e

print(x, y)

Solution (Python):
import numpy as np
n=int(input())
A=sorted([int(i) for i in input().split()])
ai=max(A)
j=np.argmin(np.array([abs(a-ai/2) for a in A[:n-1]]))
aj=A[j]
print(str(ai)+" "+str(aj))

Solution (Python):
import numpy as np

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

ai = a[-1]
a = a[:-1]
aj = a[np.argmin(np.abs(a - ai/2))]

print(ai, aj)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
ai2 = ai/2
aj = a[1] if a[0] == ai else a[0]
d = abs(aj - ai2)
for i in range(1,n):
    tempd = abs(a[i] - ai2)
    if tempd < d and a[i] != ai:
        d = tempd
        aj = a[i]

print(ai, aj)

Solution (Python):
n = int(input())
A = [int(i) for i in input().split(" ")]
A.sort()
k = A[-1]
x = 0
for i in range(n-1):
    if abs(k/2-A[x])>abs(k/2-A[i]):
        x = i
print(k, A[x])

Solution (Python):

import numpy as np
import math

def get_nearest_val(l, n):
    i = np.abs(np.asarray(l) - n).argmin()
    return l[i]

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

max_n = max(A)
A = sorted(A)
max_n = A[-1]

A.pop(-1)
key_r = (max_n + 1) / 2


















r = get_nearest_val(A, key_r)

print(str(max_n) + ' ' + str(r))

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

import bisect
m = a[-1] / 2
b = bisect.bisect_left(a, m)
if abs(a[b]-m) < abs(a[b-1]-m):
  res = a[b]
else:
  res = a[b-1]

print(a[-1], res)

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

ai = max(a)
m = ai/2

aj = -1
for ak in a:
    if ak != ai and abs(ak - m) < abs(aj - m):
        aj = ak
print("{} {}".format(ai, aj))

Solution (Python):
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = a_max / 2


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx2] if difidx2 > 0 else a[difidx]
ans2 = str(a_max)
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    if a[0] > a[1]:
        print(str(a[0]) + " " + str(a[1]))
    else:
        print(str(a[1]) + " " + str(a[0]))

Solution (Python):
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = a_max / 2


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx2] if difidx2 > 0 else a[difidx]
ans2 = str(a_max)
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    if a[0] > a[1]:
        print(str(a[0]) + " " + str(a[1]))
    else:
        print(str(a[1]) + " " + str(a[0]))

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 = input().split()

a = [int(x) for x in a]

am = max(a)
ai = 0
r = abs(a[0] - (am/2)) 

for i in range(n):
    if r >= abs(a[i]-(am/2)):
        r = abs(a[i]-(am/2))
        ai = a[i]
        
print("{0} {1}".format(am,ai))