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



Sample input:
5
6 9 4 2 11


Sample output:
11 6

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)

import math
import bisect
max = L[-1]
maxdiv2 = max//2
posleft = bisect.bisect_left(L, maxdiv2)
posright = bisect.bisect_right(L, maxdiv2)

if posleft!= posright:
	print(max, L[posleft])
	exit()

if abs(max/2 - L[posleft]) > abs(max/2 - L[posleft-1]):
	print(max, L[posleft-1])
else:
	print(max, L[posleft])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
camel = A[-1]
k = camel // 2
omega = set(A)
# print(omega)
i = 0
while True:
    star = []
    bases = (k+i, k-i)
    for base in bases:
        # print(base)
        if base in omega:
            print(str(camel) + ' ' + str(base))
            exit()
    i += 1

Submission status: Wrong Answer

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

import bisect
import numpy as np
amax = a[-1]
cent = amax // 2

idx = bisect.bisect_left(a, cent)
if idx == len(a)-1:
    print(amax, a[-2])
else:
    max_idx = np.argmin([abs(a[idx]-cent), abs(a[idx+1]-cent)])
    if max_idx:
        print(amax, a[idx+1])
    else:
        print(amax, a[idx])

Submission status: Wrong Answer

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

import bisect
import numpy as np
amax = a[-1]
cent = amax // 2

if len(a) == 2:
    print(max(a), min(a))
elif cent in a:
    print(amax, cent)
else:
    idx = bisect.bisect_left(a, cent)
    max_idx = np.argmin([abs(a[idx]-cent), abs(a[idx+1]-cent)])
    if max_idx:
        print(amax, a[idx+1])
    else:
        print(amax, a[idx])

Submission status: Wrong Answer

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

# nCrにおいてrが一定の時にnが最大の時に場合の数が最大になる
# max_xCrとnCmax_xを全て調べればO(N)

def calc_comb(n, r):
    x = 1
    y = 1
    lc = r
    for _ in range(lc):
        x *= n 
        y *= r
        n -= 1
        r -= 1
    return x//y

max_a = max(a)
res = [calc_comb(max_a, x) if x != max_a else -1 for x in a] 
import numpy as np
idx = np.argmax(res) % len(a)
print(res)
print('{:d} {:d}'.format(max_a, a[idx]))

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma // 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma // 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] < A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Submission status: Wrong Answer

Solution code:
import bisect
from scipy.special import comb

n = int(input())
a = sorted(map(int, input().split()))
ans = []
if len(a) == 2:
    print(a[1], a[0])
    exit(0)
for n in a:
    tmp = n // 2
    l = a[bisect.bisect_left(a, tmp)]
    r = a[bisect.bisect_right(a, tmp)]
    print(n, l, r)
    if n < r:
        ans.append([comb(n, l, exact=True), n, l])
    else:
        l_comb = comb(n, l, exact=True)
        r_comb = comb(n, r, exact=True)
        if l_comb > r_comb:
            ans.append([l_comb, n, l])
        else:
            ans.append([r_comb, n, r])
ans.sort()
print(ans[-1][1], ans[-1][2])

Submission status: Wrong Answer

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

tmp = 0
num = 0
for i in range(n):
    if(a[i] >= a[0]//2):
        aa = a[0]-a[i]
        if(aa >= tmp):
            tmp = aa
            num = a[i]
    else:
        if(a[i] >= tmp):
            tmp = aa
            num = a[i]

print(a[0], num)

Submission status: Wrong Answer

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

tmp = -1
num = 0
for i in range(n):
    if(a[i] >= a[0]//2):
        aa = a[0]-a[i]
        if(aa > tmp):
            tmp = aa
            num = a[i]
    else:
        if(a[i] > tmp):
            tmp = aa
            num = a[i]

print(a[0], num)

Submission status: Wrong Answer

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

tmp = 0
num = 0
for i in range(n):
    if(a[i] >= a[0]//2):
        aa = a[0]-a[i]
        if(aa > tmp):
            tmp = aa
            num = a[i]
    else:
        if(a[i] > tmp):
            tmp = aa
            num = a[i]

print(a[0], num)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx < 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai//2
    j=bisect_right(s, aj0)-1
    #print(s,aj0,j) 
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1<=aj2-aj0:
            aj=aj1
        else:
            aj=aj2
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai//2
    j=bisect_left(s, aj0)
    #print(s,aj0,j) 
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1>=aj2-aj0:
            aj=aj2
        else:
            aj=aj1
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai//2
    j=bisect_right(s, aj0)
    #print(s,aj0,j) 
    aj=s[j]   
    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1>aj2-aj0:
            aj=aj2
        else:
            aj=aj1
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
m = 0
st_n = a[0]
st_r = a[1]
for n in range(N-1):
    for r in range(n+1,N):
        if a[r] != 0:
            if m < a[n]*(a[n]-1)//a[r]:
                st_n = a[n]
                st_r = a[r]
                m = a[n]*(a[n]-1)//a[r]
a.reverse()
for n in range(N-1):
    for r in range(n+1,N):
        if a[r] != 0:
            if m < a[n]*(a[n]-1)//a[r]:
                st_n = a[n]
                st_r = a[r]
                m = a[n]*(a[n]-1)//a[r]

print(st_n,st_r)

Submission status: Wrong Answer

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

a_max = sorted(a)[-1]

dif = []
for i,ai in enumerate(a):
    dif.append((i,abs(ai-(a_max/2))))

dif_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = a[dif_i]

print(a_max, dif_min)

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

def gnv(list, num):

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

N = i()
a = l()
m = max(a)
print(m,gnv(a,m/2))

Submission status: Wrong Answer

Solution code:
import bisect
import sys

def main(args):
    
    n = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    
    diff = 0
    ans = [A[0], A[1]]
    for a in A[::-1][:n-1]:
        check = a//2
        right = bisect.bisect_left(A, check)
        left = right - 1
        
        #print("a",a)
        #print("right",A[right])
        #print("left",A[left])
        if A[right] == a:
            r = A[right]
        else:
            r1 = min(A[right],a-A[right])
            r2 = min(A[left],a-A[left])
            if r1 > r2:
                r = A[right]
            else:
                r = A[left]
            
        #print("r", r)
        
        if a-r > diff:
            ans = [a, r]
            diff = a-r
        
        #print("###############")
    
    ans.sort(reverse=True)
    print(*ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
import bisect
import sys

def main(args):
    
    n = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    
    diff = 0
    ans = [A[0], A[1]]
    for a in A[::-1][:n-1]:
        check = a//2
        right = bisect.bisect_left(A, check)
        left = right - 1
        
        #print("a",a)
        #print("right",A[right])
        #print("left",A[left])
        
        r1 = min(A[right],a-A[right])
        r2 = min(A[left],a-A[left])
        if r1 > r2:
            r = A[right]
        else:
            r = A[left]
            
        #print("r", r)
        
        if a-r > diff:
            ans = [a, r]
            diff = a-r
        
        #print("###############")
            
    print(*ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
import bisect
import sys

def main(args):
    
    n = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    
    diff = 0
    ans = [A[0], A[1]]
    for a in A[::-1][:n-1]:
        check = a//2
        right = bisect.bisect_right(A, check)
        left = right - 1
        
        #print("a",a)
        #print("right",A[right])
        #print("left",A[left])
        
        r1 = min(A[right],a-A[right])
        r2 = min(A[left],a-A[left])
        if r1 > r2:
            r = A[right]
        else:
            r = A[left]
            
        #print("r", r)
        
        if a-r > diff:
            ans = [a, r]
            diff = a-r
        
        #print("###############")
            
    print(*ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=a[n-1]
if c%2==0:
  p=c//2
  o=10**9
  for i in range(n):
    if abs(p-a[i])<=o:
      o=abs(p-a[i])
      ans=a[i]
else:
  p=c//2
  q=c//2+1
  o=10**9
  for i in range(n):
    if abs(p-a[i])<abs(q-a[i]):
      if abs(p-a[i])<o:
        o=abs(p-a[i])
        ans=a[i]
    else:
      if abs(q-a[i])<o:
        o=abs(q-a[i])
        ans=a[i]
print(c,ans)

Submission status: Wrong Answer

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

import math

n = A[-1]
P_dif_A = sorted([[abs(a-n), a] for a in A])
r = P_dif_A[1][1]

print(n, r)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
N = int(input())
*A, = map(int, input().split())
A.sort()
m = A[-1]
div = m / 2
print(m, min(abs(m - A[bisect_right(A, m / 2)]), abs(m - A[bisect_left(A, m / 2)])))

Submission status: Wrong Answer

Solution code:
n=int(input())
L=list(map(int, input().split()))
a=max(L)
b=0
for i in range(n):
	if min(a-L[i],L[i])>=b:
		b=L[i]
print(a,b)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

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

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

aa.sort()

nn=aa[-1]

import bisect
#a=[0,2,3,4,67,8]
#a.sort()
i=bisect.bisect_left(aa,nn//2) 

if abs(aa[i]-nn//2)<abs(aa[i+1]-nn//2):
    print(nn,aa[i])
else:
    print(nn,aa[i+1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

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

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

aa.sort()

nn=aa[-1]

import bisect
#a=[0,2,3,4,67,8]
#a.sort()
i=bisect.bisect_left(aa,nn//2) 
print(nn,aa[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
m=10**9+1
temp=ans1/2
i=0
for index,val in enumerate(a):
    if abs(val-temp)<m:
        m=abs(val-temp)
        i=index
ans2=a[i]
print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = a[-1]
m = 0
C = 0
for i in range(n):
  c = a[i]*(M-a[i])
  if C < c:
    C = c
    m = a[i]
  else:
    break
print(M, m, sep=' ')

Submission status: Wrong Answer

Solution code:
import bisect

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

if amax//2 in set(a):
  print(amax,amax//2)
else:
  ind = bisect.bisect_left(a,amax//2)
  MIN = min(abs(a[ind]-(amax//2)),abs(a[ind-1]-(amax//2)))
  
  if MIN == abs(a[ind-1]-(amax//2)):
    print(amax,a[ind-1])
    exit()
  else:
    print(amax,a[ind])
    exit()

Submission status: Wrong Answer

Solution code:
import bisect

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

if amax//2 in set(a):
  print(amax,amax//2)
else:
  ind = bisect.bisect_left(a,amax//2)
  MIN = min(abs(a[ind]-(amax//2)),abs(a[ind-1]-(amax//2)))
  
  if MIN == abs(a[ind]-(amax//2)):
    print(amax,a[ind])
    exit()
  else:
    print(amax,a[ind-1])
    exit()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = -1
for i in A[:-1]:
    if abs(A[-1]//2-i) < tmp:
        tmp = abs(A[-1]//2-i)
        ans = i
print(A[-1],ans)

Submission status: Wrong Answer

Solution code:
import sys
from scipy.misc import comb
import bisect
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
l = bisect.bisect_left(A,A[-1]//2)-1
r = l+1
if r==N-1 or comb(A[-1],A[l]) > comb(A[-1],A[r]):
    print(A[-1],A[l])
else:
    print(A[-1],A[r])

Submission status: Wrong Answer

Solution code:
import sys
from scipy.misc import comb
import bisect
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
l = bisect.bisect_left(A,A[-1]//2)-1
r = l+1
if comb(A[-1],A[l]) > comb(A[-1],A[r]):
    print(A[-1],A[l])
else:
    print(A[-1],A[r])

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = [int(a) for a in input().split()]

i = max(arr)
j = min(arr, key=lambda a: min(abs(i//2-a), abs((i+1)//2-a)))

print(i, j)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


n = int(input())
A = sorted(map(int, input().split()))
print(A[-1], A[min(n - 2, bisect_left(A[:-1], A[-1] // 2))])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


n = int(input())
A = sorted(map(int, input().split()))
print(A[-1], A[bisect_left(A[:-1], A[-1] // 2)])

Submission status: Wrong Answer

Solution code:

n = int(input())
a = list(map(int, input().split()))
x = max(a)
a.sort()
del a[-1]
for i in range(n - 1):
    if a[i] >= x / 2:
        print(x, a[i])
        exit()

print(x, a[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int,input().split()))
a1 = 0
d = a[-1] - a[0]


for i in range(n-1):
	d1 = max(a[i],a[-1]-a[i])
	if d1 < d:
		a1 = a[i]
	
print(a[-1], a1)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
if m%2!=0:
  med=(m+1)//2
else:
  med=m//2
mi=m
for ll in l:
  mi=min(mi,abs(ll-med))
if med+mi in l:
  print(m,med+mi)
else:
  print(m,med-mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
if m%2!=0:
  med=(m+1)//2
else:
  med=m//2
mi=m
for ll in l:
  mi=min(mi,abs(ll-med))
print(m,mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mx = max(a)

ans = 0
for i in a:
    if mx == i:
        continue
    if mx - i <= i:
        if ans <= mx-i:
            ans = i
    else:
        if ans <= i:
            ans = i

print(mx, ans, sep=" ")

Submission status: Wrong Answer

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

A.sort()

# import bisect

ncand = A[-1]

ccand = A[0]
nhalf = ncand // 2
diff = abs(nhalf - ccand)

for i in range(1, N-1):
    d = abs(nhalf - A[i])
    if diff > d:
        ccand = A[i]
        diff = d

print(ncand, ccand)

# from math import factorial
# ans = factorial(ncand)//(factorial(ncand-ccand)*factorial(ccand))
# print(ans)

Submission status: Wrong Answer

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

A.sort()

import bisect

ncand = A[-1]
ix = bisect.bisect_left(A[:-1], ncand//2)
# print(A[:-1], ix)
if A[ix] == ncand:
    ix -= 1
ccand = A[ix]

print(ncand, ccand)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 10**18
for i in range(n-1):
    if abs(a[i] - n/2) < ans:
        ans = a[i]
print(a[-1],ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) <= abs(f-d/2):
    f = min(f,v)
print(d,f)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
print(d,f)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
ans=l[0]
for i in range(n-1):
  if abs(l[-1]-ans)>abs(l[-1]-l[i]):
    ans=l[i]
print(l[-1],ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = a[-1]

import bisect

idx_1 = bisect.bisect_left(a, a_max//2)
idx_2 = bisect.bisect_left(a, a_max//2 + 1)

b = [a[idx_1], a[idx_1 - 1], a[idx_2], a[idx_2 - 1]]
ans = [0, 10**10]
for i in b:
    if i == a_max:
        continue
    if n % 2 == 0 and a_max//2 - i < ans[1]:
        ans = [i, a_max//2 - i]
    elif n % 2 == 0 and a_max//2 + 1 - i < ans[1]:
        ans = [i, a_max//2 + 1 - i]
    elif n % 2 == 1 and a_max//2 + 1 - i < ans[1]:
        ans = [i, a_max//2 + 1 - i]
print(a_max, ans[0])

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = a[-1]

import bisect

idx_1 = bisect.bisect_left(a, a_max//2)
idx_2 = bisect.bisect_left(a, a_max//2 + 1)

b = [a[idx_1], a[idx_1 - 1], a[idx_2], a[idx_2 - 1]]
ans = [0, 10**10]
for i in b:
    if i == a_max:
        continue
    if n % 2 == 0 and (a_max//2 - i < ans[1] or a_max//2 + 1 - i < ans[1]):
        ans = [i, a_max - i]
    elif n % 2 == 1 and  a_max//2 + 1 - i < ans[1]:
        ans = [i, a_max - i]
print(a_max, ans[0])

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = a[-1]

import bisect

idx_1 = bisect.bisect_left(a, a_max//2)
idx_2 = bisect.bisect_left(a, a_max//2 + 1)

b = [a[idx_1], a[idx_1 - 1], a[idx_2], a[idx_2 - 1]]
ans = [0, 10**10]
for i in b:
    if i == a_max:
        continue
    if a_max//2 - i < ans[1] or a_max//2 + 1 - i < ans[1]:
        ans = [i, a_max - i]
print(a_max, ans[0])

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from bisect import bisect_left


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


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

ai = a[-1]
candn = bisect_left(a, ai/2)

cands = set([max(candn-1, 0), candn,  min(candn+1, n-1)])

max_cmb = 0
ans = (ai, a[max(candn-1, 0)])

for ci in cands:
    if a[ci] < (ai-1)/2:
        ans = (ai, a[ci])
print(*ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()
    L = A[N-1]
    ans = -1
    for a in A[:N-1]:
        if abs(L/2 - a) < abs(L/2 - ans): ans = a
    print(ans, L)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

a.sort()
left = a.pop()
yoi = left/2
for i in range(n-1):
    if a[i] >= yoi:
        a[i] = (abs(a[i]-yoi), 1)
    else:
        a[i] = (abs(a[i]-yoi), -1)
a.sort()
right = int(a[0][0]+a[0][1]*yoi)
print(left, right)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = a[-1]

import bisect

idx_1 = bisect.bisect_left(a, a_max//2)
idx_2 = bisect.bisect_left(a, a_max//2 + 1)

b = [a[idx_1], a[idx_1 - 1], a[idx_2], a[idx_2 - 1]]
ans = [0, 10**10]
for i in b:
    if i == a_max:
        continue
    if a_max - i < ans[1]:
        ans = [i, a_max - i]
print(a_max, ans[0])

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from bisect import bisect_left


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


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

ai = a[-1]
candn = bisect_left(a, ai/2)

cands = set([max(candn-1, 0), candn,  min(candn+1, n-1)])

max_cmb = 0
for ci in cands:
    if cmb(ai, a[ci]) >= max_cmb:
        max_cmb = cmb(ai, a[ci])
        ans = (ai, a[ci])
print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = a[-1]

import bisect

idx_1 = bisect.bisect_left(a, a_max//2)
idx_2 = bisect.bisect_left(a, a_max//2 + 1)

b = [a[idx_1], a[idx_1 - 1], a[idx_2], a[idx_2]]
ans = [0, 10**10]
for i in b:
    if i == a_max:
        continue
    if a_max - i < ans[1]:
        ans = [i, a_max - i]
print(a_max, ans[0])

Submission status: Wrong Answer

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

m = max(a)
res = 0
ans = 0
for i in a:
    if i != m:
        if abs(m//2-i) < res:
            res = abs(m//2-i)
            ans = i

print(m,ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
mx = max(A)

A.sort(key=lambda a: abs(mx / 2 - a))
print(mx, A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans1 = max(A)
for i in range(n):
    if i == 0:
        pass
    elif i == 1:
        ans2 = A[i]
        now_div = abs(ans1/2 - ans2)
    else:
        chk = A[i]
        chk_div = abs(ans1/2 - chk)
        if chk_div > now_div:
            print(ans1, ans2)
            exit()
        if abs(ans1/2 - chk) < abs(ans1/2 - ans2):
            ans2 = chk
            now_div = abs(ans1/2 - ans2)

Submission status: Wrong Answer

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

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

max_ = 0
for i, a1 in enumerate(a_lst):
  for a2 in a_lst[i+1:]:
    if a1 > a2:
      cand = combinations_count(a1, a2)
    else:
      cand = combinations_count(a2, a1)
    if max_ < cand:
      max_ = cand
print(max_)

Submission status: Wrong Answer

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    p = max(a)
    a.remove(p)
    *b, = map(lambda x: abs(x - p / 2), a)
    c = min(b)
    q, r = int(c + p / 2), int(p / 2 - c)
    if r >= 0:
        print(p, r)
    else:
        print(p, q)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from bisect import bisect_right
    n, *a = map(int, open(0).read().split())
    a.sort()
    x = max(a)
    i = bisect_right(a, x / 2)
    p, q = a[i], a[i - 1]
    if p == x:
        print(x, q)
    elif (x / 2 - p) < (x / 2 - q):
        print(x, p)
    else:
        print(x, q)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
li = sorted(map(int, input().split()), reverse=True)
M = 0
ans = []
for i in range(n-1):
    pre = 0
    for j in range(n-1, i+1, -1):
        c = comb(li[i], li[j])
        if c > M:
            M = c
            ans = [li[i], li[j]]
        if c <= pre:
            break
        else:
            pre = c       
print(*ans)

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
li = list(map(int, input().split()))
M = 0
ans = []
for i in range(n-1):
    for j in range(i+1, n):
        c = comb(li[i], li[j])
        if c > M:
            M = c
            ans = [li[i], li[j]]
print(*ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
data = list(map(int, input().split()))
eps = 0.0001
n = max(data)
nn = ceil(n/2.0+eps)
r = min((d for d in data if d != n), key=lambda x: abs(nn-x))
print(n, r)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(int, input().split())
A = sorted(A)
maxa = max(A)
if abs(maxa//2 - A[n//2-1]) <= abs(maxa//2 - A[n//2]):
    print(maxa, A[n//2-1])
else:
    print(maxa, A[n//2])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(int, input().split())
A = sorted(A)

maxa = max(A)

if maxa%2 == 1:
    l2 = maxa//2
    r2 = maxa//2 + 1
else:
    l2 = maxa//2
    r2 = maxa//2


from bisect import bisect_left, bisect_right

li = bisect_left(A, l2)
ri = bisect_left(A, r2)

print(maxa, A[li])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m1 = A[-1]
m2 = m1 // 2 + int(m1 % 2 == 1)
ans = [m1, 0]
tmp = 10000000

for a in A[:len(A) - 1]:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
m1 = max(A)
m2 = m1 // 2 + int(m1 % 2 == 1)
ans = [m1, m2]
tmp = 10000000

for a in A:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n = int(input())
A = list(map(int,input().split()))
A.sort()
y = max(A)
idx = bisect_left(A, y//2)
if A[idx]==y:
    print(y, A[idx-1])
else:
    print(y, A[idx])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n = int(input())
A = list(map(int,input().split()))
A.sort()
y = max(A)
idx = bisect_left(A, y//2)
print(y,A[idx])

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
a = set(map(int,input().split()))
A = sorted(list(a))
M = max(A)
num = M//2

index = bisect.bisect_right(A,num)
#print(index)

if M != A[index]:
    print(M,A[index])
else:
    print(M,A[index-1])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

n = INT()
a = LIST()

p = max(a)
m = (p+1)/2 - 0.1
b = []
for x in a:
	b.append((x, abs(x-m)))

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

print(p, b[0][0])