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

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = [int(x) for x in input().split()]
a_sorted = np.array(sorted(a))

a_sorted_floor = np.copy(a_sorted[:-1])
idx_floor = np.where(np.logical_and(a_sorted[-1] / 2 < a_sorted[:-1], a_sorted[:-1] < a_sorted[-1]))
a_sorted_floor[idx_floor] = a_sorted[-1] - a_sorted_floor[idx_floor]

print(a_sorted[-1], a_sorted[np.argmax(a_sorted_floor)])

Submission status: Accepted

Solution code:

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

B = sorted(A)
pivot = B[-1] / 2.0
min_diff = B[-1]
min_index = None
for i, b in enumerate(B):
    diff = abs(b - pivot)
    if diff < min_diff:
        min_diff = diff
        min_index = i

print(B[-1], B[min_index])

Submission status: Accepted

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

amax = max(ali)
ali.remove(amax)
b=min(ali,key=lambda x: abs(2*x-amax))
print(amax,end=' ')
print(b)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

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

sorted_a = sorted(a)

ai = sorted_a[n-1]

goal = ai / 2

min_dist = ai * 2
aj = ai

for i in range(n-1):
    dist = abs(sorted_a[i] - goal)
    if dist < min_dist:
        min_dist = dist
        aj = sorted_a[i]

print(ai, aj)

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
lst.sort()
x=lst[-1]
z=x/2
y=float('inf')
min_dif=100000000000
for w in lst:
    if abs(w-z)<min_dif:
        min_dif=abs(w-z)
        y=w
print(x,y)

Submission status: Accepted

Solution code:
from itertools import combinations

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

n = max(a)
s = n
r = n
d = n

for i, x in enumerate(a):
    if d >= abs(x - n / 2) and x != s:
        d = abs(x - n / 2)
        r = x

print(n)
print(r)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
half = maxA/2
t = 10000000000
for i in range(N):
    if A[i] != maxA and abs(A[i]-half) < abs(t-half):
        t = A[i]
print(maxA,t)

Submission status: Accepted

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

k=(enu)/2
sa=10000000000000000000000000000

for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)

Submission status: Accepted

Solution code:
import bisect

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

v1=x[-1]
del x[-1]

ins = bisect.bisect_left(x,v1/2)

if len(x)<=1:
    v2=0
elif abs(x[ins]-v1/2) > abs(x[ins-1]-v1/2):
    v2=x[ins-1]
else:
    v2=x[ins]

print(v1,v2)

Submission status: Accepted

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

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

aj = A[0]
delta_j = abs(ai/2 - aj)

for a in A:
    delta = abs(ai/2 - a)
    if delta < delta_j:
        aj = a
        delta_j = delta

print(ai, aj)

Submission status: Accepted

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

ai = max(a_list)
a_list.remove(ai)
aj = int(sorted([a - (ai / 2) for a in a_list], key=abs)[0] + (ai / 2))

print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
N = nums[-1]
work = 0
resind = 0
for i in range(n):
    if work < min((N-nums[i]),nums[i]):
        work = min((N-nums[i]),nums[i])
        resind = i
print(N,nums[resind])

Submission status: Accepted

Solution code:
#!python
# -*- coding: utf-8 -*-

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

A1 = max(a_s)
a_s.remove(A1)
A2 = a_s[0]
for a in a_s:
    if abs(A1 / 2 - A2) > abs(A1 / 2 - a):
        A2 = a

print(A1, A2)

Submission status: Accepted

Solution code:
def sel(data,n):
    an = n
    ans = 0
    for i in data:
        t = abs(n - i * 2)
        if t < an:
            an = t
            ans = i
    return(ans)

n = input()
As = list(map(int,input().split()))
As.sort()
l = As[-1]
m = sel(As[:-1],l)
print(l,m)

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
a.sort()
x = a[-1]
s = x
p = a[0]
for i in a:
    if s >= abs((x/2)-i):
        s = (x/2)-i
        p = i
    else:
        print x, p
        break
else:
    print a[1], a[0]

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if n == 2:
    print(max(a),min(a))
    exit()
ans_n = a[n-1]
bestr = ans_n//2
kouho = bisect.bisect_left(a,bestr)
if abs(bestr-a[kouho-1]) < abs(bestr-a[kouho]) and abs(bestr-a[kouho-1]) < abs(bestr-a[kouho+1]):
    ans_r = a[kouho-1]
elif abs(bestr-a[kouho]) < abs(bestr-a[kouho+1]):
    ans_r = a[kouho]
else:
    ans_r = a[kouho+1]
print(ans_n, ans_r)

Submission status: Accepted

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

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

d = 99999999999
now = -1
if m%2 == 1:
  z = (m+1)/2
  for x in a:
    if d > abs(x - z):
      now = x
      d = abs(x - z)
  print m,now
else:
  z = m/2
  for x in a:
    if x<=z:
      if d > abs(z-x):
        now = x
        d = abs(x-z)
    else:
      if d > abs(x-z-1):
        now = x
        d = abs(x-z-1)
  print m,now

Submission status: Accepted

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

a=sorted(a)
b=max(a)
m=float('inf')
for i in a:
    if abs(b//2-i)<=abs(b//2-m) and i!=b:
        m=i
print(b,m)

Submission status: Accepted

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

    l = max(a)
    r = 0
    best = l / 2
    for target in a:
        if abs(best - r) >= abs(best - target):
            r = target

    print(str(l) + " " + str(r))

Submission status: Accepted

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

ai = max(a_list)
a_list.remove(ai)
sorted([a - (ai / 2) for a in a_list])[0]

tmp = ai
cand = ai
for x in [a - (ai / 2) for a in a_list]:
    if abs(x) < tmp:
        tmp = abs(x)
        cand = int(x + (ai / 2))

print(ai, cand)

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int,input().split()))
alst.sort()
aj = alst[-1]
score = 10000000000
ai = -1
for i in range(n):
  s = abs(aj/2 - alst[i])
  if score > s:
    score = s
    ai = alst[i]
  else:
    print(aj,ai)
    break

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
b = a[:]
for i in range(n):
    if a[i] != ai:
        b[i] = abs(a[i] - ai / 2)
    else:
        b[i] = abs(a[i] - ai / 2 + 1)
c = min(b)
d = b.index(c)
aj = a[d]
print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
x = max(A)
y = 1e9
x2 = x/2
for a in sorted(A):
    if abs(x2 - a) < abs(x2 - y):
        y = a
    else:
        break
print(x, y)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Ai = max(A)
x = float('inf')
for a in A:
    if abs((Ai - a) - a) <= x:
        x = abs((Ai - a) - a)
        Aj = a
print(Ai, Aj)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
a = max(lis)
lis.remove(a)
ans = 100000000000
for i in range(n-1):
	if abs(a/2 - lis[i]) < ans:
		ans = abs(a/2 - lis[i])
		an = lis[i]
print(a,an)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=[int(x) for x in input().split()]
y=sorted(a)
m=y[-1]
i = bisect.bisect_left(y,m/2.0)
if y[i]+y[i-1] >= m:
    print(str(m)+' '+str(y[i-1]))
else:
    print(str(m)+' '+str(y[i]))

Submission status: Accepted

Solution code:
n=int(raw_input())
a=[int(k) for k in raw_input().split(" ")]

mx=max(a)

best=-1
for k in a:
    if k!=mx and min(k,mx-k)>min(best,mx-best):
        best=k
print mx,best

Submission status: Runtime Error

Solution code:
def g(n,r):return f[n]//f[n-r]//f[r]
n,*a=map(int,open(0).read().split())
m=max(a)
f=[1]*-~m
for i in range(m):f[i+1]=f[i]*-~i
o=min(a)
for A in a:
 if g(m,A)>g(m,o):o=A
print(m,o)

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
m=max(a)
f=[1]*-~m
for i in range(m):f[i+1]=f[i]*-~i
def g(n,r):return f[n]//f[n-r]//f[r]
o=min(a)
for A in a:
 if g(m,A)>g(m,o):o=A
print(m,o)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 100000
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)

Submission status: Runtime Error

Solution code:
ｐりんｔ（あ

Submission status: Runtime Error

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

A.sort()
n = A[-1]

r_=11/2

a_before=''
for a in A[:-1]:
    if a >= r_:
        break
    a_before = a
    
if abs(r_-a) >= abs(r_-a_before):
    r = a_before
else:
    r = a
    
print(n,r)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    del A[-1]
    saidai=ans1/2
    num=pow(10,9)
    for n in range(N-2):
        if abs(saidai-A[n])<=num:
            num=abs(saidai-A[n])
        else:
            ans2=n-1
    print(ans1,A[ans2])

Submission status: Runtime Error

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2-1
else:
    ai2=ai//2

jj=bisect(a,ai2)

if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj2=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj2=jj-1
    
if jj2==n-1:
    jj2=jj2-1
    
aj=a[jj2]

print(ai,aj)

Submission status: Runtime Error

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2-1
else:
    ai2=ai//2

jj=bisect(a,ai2)

if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
    jj=jj+1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2-1
else:
    ai2=ai//2

jj=bisect(a,ai2)

if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
    jj=jj+1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
m = 0
for i in itertools.combinations(a,2):
    j = [h for h in itertools.combinations(range(max(i[0],i[1])), min(i[0],i[1]))]
    if m < len(j):
        m = len(j)
        l = i
print(max(l[0],l[1]),min(l[0],l[1]))

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
sl = []
for _ in range(h):
    row = list(input())
    sl.append(row)


dp = [ [10000]*h for _ in range(w) ]
dp[0][0] = 0

for wi in range(w):
    for hi in range(h):
        if wi+1 < w:
            if sl[wi][hi] == '.' and sl[wi+1][hi] == '#':
                dp[wi+1][hi] = min( dp[wi+1][hi], dp[wi][hi]+1 )
            else:
                dp[wi+1][hi] = min( dp[wi+1][hi], dp[wi][hi] )

        if hi+1 < h:
            if sl[wi][hi] == '.' and sl[wi][hi+1] == '#':
                dp[wi][hi+1] = min( dp[wi][hi+1], dp[wi][hi]+1 )
            else:
                dp[wi][hi+1] = min( dp[wi][hi+1], dp[wi][hi] )


ans = dp[w-1][h-1]
if sl[0][0] == '#': ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

N = int(input())
an = [int(input()) for i in range(N)]
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for c in itertools.combinations(an, 2):
    v = comb(swap(c))
    if v > max_v:
        max_v = v
        max_e = swap(c)
    #print(c, comb(*c))

print(max_e)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-i]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Submission status: Runtime Error

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

x = max(a)
m = x/2
a.remove(x)
a.sort()
ans = 10000

for i in a:
    y = abs(i - m)
    if ans >= y:
        ans = y
    else:
        break    
    z = i
      
print(x, z)

Submission status: Runtime Error

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

x = max(a)
m = x/2
a.remove(x)
a.sort()
ans = 10000
for i in a:
    y = abs(i - m)
    if ans >= y:
        ans = y
    else:
        break    
    z = i
      
print(x, z)

Submission status: Runtime Error

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

# nCrにおいてrが一定の時にnが最大の時に場合の数が最大になる
# max_xCrをDPで調べればok

import numpy as np
max_a = a[-1]
max_r = a[-2]+1
dp = np.zeros(max_r)
for i in range(max_r-1):
    if i != 0:
        dp[i+1] = dp[i] * (max_a-i) // (i+1)
    else:
        dp[i+1] = max_a

idx = np.argmax(dp[a[:-1]])
print('{:d} {:d}'.format(max_a, a[idx]))

Submission status: Runtime Error

Solution code:
class Com:
    def __init__(self, MAX = 10000000, MOD = 1000000000007):
        self.MAX = MAX
        self.MOD = MOD
        self._fac = [0]*MAX
        self._finv = [0]*MAX
        self._inv = [0]*MAX
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2,self.MAX):
            self._fac[i] = self._fac[i - 1] * i % self.MOD
            self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
    
    def com(self, n, k):
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD
n = int(input())
A = list(map(int,input().split()))
amax = max(A)
com = Com(amax+10)
ans = -1
MAX = -1
for a in A:
    if a == amax:continue
    if com.com(amax,a) > MAX:
        MAX = com.com(amax,a)
        ans = a
print(amax,ans)

Submission status: Runtime Error

Solution code:
class Com:
    def __init__(self, MAX = 1000000, MOD = 1000000007):
        self.MAX = MAX
        self.MOD = MOD
        self._fac = [0]*MAX
        self._finv = [0]*MAX
        self._inv = [0]*MAX
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2,self.MAX):
            self._fac[i] = self._fac[i - 1] * i % self.MOD
            self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
    
    def com(self, n, k):
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD
n = int(input())
A = list(map(int,input().split()))
amax = max(A)
com = Com()
ans = -1
MAX = -1
for a in A:
    if a == amax:continue
    if com.com(amax,a) > MAX:
        MAX = com.com(amax,a)
        ans = a
print(amax,ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
ma = A[0]

def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i
    return result

def comb(n,r):
    return fact[n] * pow(fact[n-r],-1) * pow(fact[r],-1)

fact = make_factorial_table(ma)
tmp = 0
ans = 0

for a in A[1:]:
    if comb(ma,a) > tmp:
        tmp = comb(ma,a)
        ans = a
    
print(ma,ans)

Submission status: Runtime Error

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

tmp = 0
num = 0
for i in range(1, 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: Runtime Error

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

fact = [1]
for i in range(1, N+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

if N==2:
    print(A[1], A[0])
    exit()

maxA = max(A)
ind = bisect_left(A, maxA//2)
res = 0
ress = -1
for i in range(ind, ind+1):
    if i<0 or N-1<=i:
        continue
    val = cmb(maxA, A[i])
    if res<val:
        res = val
        ress = A[i]
print(maxA, ress)

Submission status: Runtime Error

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

L = sorted(L)

import math

def combination(n, r):
	value = 1
	smaller = min(n-r, r)
	for i in range (0, smaller):
		value = value*(n-i)
	value = value/math.factorial(smaller)
	return value

seikai = 0
Emu = L[-1]
calc = 0

for i in range (0, N-1):
	if combination(Emu, L[i]) > calc:
		calc = combination(Emu, L[i])
		seikai = L[i]

print(L[-1], seikai)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import factorial
from itertools import combinations


def comb(i, j):
    try:
        comb = factorial(i) // factorial(j) // factorial(i - j)
    except Exception:
        return -1
    else:
        return comb


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

# check
if n == 2:
    print(a[0], a[1])
else:
    max_case = sorted(
        [
            (max(c), min(c), comb(max(c), min(c)))
            for c in combinations(a, 2)
            if min(c) == max(a)
        ],
        key=lambda x: x[2],
        reverse=True
    )[0]

    print(max_case[0], max_case[1])

Submission status: Runtime Error

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

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

import bisect
ans=0
(a,b)=(0,0)

for item in aa[:n//2+1]:
    i=bisect.bisect_left(aa,item*2)
    tmp=cmb(aa[min(n-1,i)],item,p)
    #print(aa[min(n-1,i)],item,tmp)
    if ans<tmp:
        ans=tmp
        (a,b)=(aa[min(n-1,i)],item)
    

print(a,b)

Submission status: Runtime Error

Solution code:
import sys
from scipy.special 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: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
tmp = 0
for i in range(n):
    if a[i] == a[-1]:
        break
    if cmb(a[-1],a[i],mod) > ans:
        ans = cmb(a[-1],a[i],mod)
        tmp = a[i]
print(a[-1],tmp)

Submission status: Runtime Error

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

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 a_max - i < ans[1]:
        ans = [i, a_max - i]
print(a_max, ans[0])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
m1 = max(A)
m2 = m // 2 + int(m % 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: Runtime Error

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

def binary(l,i):
  r=N-1
  while l<r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

Submission status: Runtime Error

Solution code:
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
#s2 = abs(k2-a)
print(s,k1,k2,s1,s2)
if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Submission status: Runtime Error

Solution code:
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
a = l[-1]/2
s = bisect.bisect_left(l,a)
k1 = l[s]
if len(l)==2 and l[0]==0:
  print(0)
  exit()

def com(a,b):
  return math.factorial(a)//(math.factorial(b)*math.factorial(a-b))

s1 = com(l[-1],k1)
s2 = com(l[-1],k2)
if s1>=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Submission status: Runtime Error

Solution code:
import bisect

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

l.sort()

r = bisect.bisect_right(l, l[-1]/2)

a = l[r]
b = l[r+1]

a2 = min(a,l[-1]-a)
b2 = min(b,l[-1]-b)

if a2 >= b2:
  c = a
else:
  c = b

print( int( l[-1] ) ,int(c))

Submission status: Runtime Error

Solution code:
import bisect

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

l.sort()

r = bisect.bisect_right(l, l[-1]/2)

a = l[r]
b = l[r+1]

a = min(a,l[-1]-a)
b = min(b,l[-1]-b)

print( int( l[-1] ) ,max(a,b))

Submission status: Runtime Error

Solution code:
import bisect
from functools import lru_cache

@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

def comb(n,r):
    return kaijou(n)/kaijou(r)/kaijou(n-r)

n = input()
A = list(map(int,input().split()))
A.sort()
m = A[-1]
i = bisect.bisect_left(A,m//2)
if i == 0:
    if comb(m,A[i]) >= comb(m,A[i+1]):
        print(m,A[i])
    else:
        print(m,A[i+1])
else:
    if comb(m,A[i-1]) >= comb(m,A[i]):
        print(m,A[i-1])
    else:
        print(m,A[i])

Submission status: Runtime Error

Solution code:
import bisect
from scipy.special import comb

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

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


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)

Submission status: Runtime Error

Solution code:
import itertools

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


base = max(a)
ans = 0
ans_set = []
for x in a:
    if x == base:
        pass
    elif len(list(itertools.combinations(range(base), x))) > ans:
        ans = len(list(itertools.combinations(range(base), x)))
        ans_set = [base, x]
print(*ans_set)

Submission status: Runtime Error

Solution code:
import itertools

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


base = max(a)
ans = 0
ans_set = []
for x in a:
    if x == base:
        pass
    elif len(list(itertools.combinations(range(1, base+1), x))) > ans:
        ans = len(list(itertools.combinations(range(1, base+1), x)))
        ans_set = [base, x]
print(*ans_set)

Submission status: Runtime Error

Solution code:
import bisect
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a.copy()
b.pop()
if len(b) == 1:
    idx = 0
else:
    if abs(a[-1]/2 - b[bisect.bisect_left(b, a[-1]/2)]) < abs(a[-1]/2 - b[bisect.bisect_right(b, a[-1]/2)]):
        idx = bisect.bisect_left(b, a[-1]/2)
    else:
        idx = bisect.bisect_right(b, a[-1]/2)
print(a[-1], b[idx])

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)
f = True
m = 0
hikaku = -1 
syutu = 0
i = 1
while f and i <= n - 1:
    if a[0]//2 == a[i] or a[0]//2 == a[i] + 1:
        f = False
        m = a[i]
    else:
        i += 1

if f == True:
    for i in range(n):
        answer = 1
        syutu = a[i + 1]
        answer = int(math.factorial(a[0]) / (math.factorial(a[i + 1]) * math.factorial(a[0] - m + 1))
        if hikaku < = answer:
            
            hikaku = answer
            m = syutu
        
print(a[0], syutu)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)
f = True
m = 0
hikaku = -1 
syutu = 0

while f or i <= n - 1:
    if a[0]//2 == a[i] or a[0]//2 == a[i] + 1:
        f = False
        m = a[i]
    else:
        i += 1

if f = True:
    for i in range(n):
        answer = 1
        syutu = a[i + 1]
        for j in range(1, a[0] + 1):
            answer *= j
        for j in range(1, m + 1):
            answer = int(answer / j)
        for j in range(1, a[0] - m + 1):
            answer = int (answer / j)
        if hikaku <= answer:
            hikaku = answer
            m = syutu
print(a[0], syutu)

Submission status: Runtime Error

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

if N > 2:
    A.sort()
    num_total = A[-1]
    A.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    
    def meguru_search(l,key): # key以上の値を持つ最小のインデックスを返す
        left = -1
        right = len(l)

        while (right - left) > 1: # 二分探索
            mid = left + (right - left)//2
            if isOK(mid,key,l):
                right = mid
            else:
                left = mid
        
        return right
    
    if num_total%2 == 0:
        Max = num_total//2 
    else:
        Max = num_total//2 + 1
    
    Maxind1 = meguru_search(A,Max) # Max以上の値を持つインデックス
    Maxind2 = Maxind1 - 1 # Max未満の最大の値を持つインデックス
    abs_1 = abs(Max - A[Maxind1])
    abs_2 = abs(Max - A[Maxind2])
    if abs_1 > abs_2: # Maxに近いほどnCrが大きくなる
        r = A[Maxind2]
    else:
        r = A[Maxind1]
    print(num_total,r)

else:
    print(max(A),min(A))

Submission status: Runtime Error

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort()
num_total = a_ls[-1]
a_ls.pop()
def isOK(index, key, l):
    if l[index] >= key:
        return True
    else:
        return False
def meguru_search(l, key):
    '''
    key以上の値を持つ最小のインデックスを返す
    '''
    left = -1
    right = len(l)

    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right

if num_total % 2 == 0:
    Max = num_total // 2
else:
    Max = num_total // 2 + 1
Maxind1 = meguru_search(a_ls, Max)
Maxind2 = Maxind1 - 1
abs_1 = abs(Max - a_ls[Maxind1])
abs_2 = abs(Max - a_ls[Maxind2])
if abs_1 > abs_2:
    r = a_ls[Maxind2]
else:
    r = a_ls[Maxind1]
print(num_total, r)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort()
num_total = a_ls[-1]
a_ls.pop()
def isOK(index, key, l):
    if l[index] >= key:
        return True
    else:
        return False
def meguru_search(l, key):
    '''
    key以上の値を持つ最小のインデックスを返す
    '''
    left = -1
    right = len(l)

    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right

if num_total % 2 == 0:
    Max = num_total // 2
else:
    Max = num_total // 2 + 1
Maxind1 = meguru_search(a_ls, Max)
Maxind2 = Maxind1 - 1
if combinations_count(num_total, a_ls[Maxind1]) > combinations_count(num_total, a_ls[Maxind2]):
    r = a_ls[Maxind1]
else:
    r = a_ls[Maxind2]
print(num_total, r)