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: Runtime Error

Solution code:
import bisect
n = int(input())
A = sorted(list(map(int,input().splitfrom math import factorial
import bisect
import sys
n = int(input())
A = sorted(list(map(int,input().split())))
           
max1 = A[-1]
half = A[-1]//2

point = bisect.bisect_left(A, half)

if A[point] == A[-1]:
  print(A[-1],A[-2])
  sys.exit()

a1 = factorial(max1) / factorial(A[point]) / factorial(max1 - A[point])
a2 = factorial(max1) / factorial(A[point+1]) / factorial(max1 - A[point+1])
if a1>=a2:
  print(max1,A[point])
else:
  print(max1,A[point+1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)


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

a.sort()
nn=a[-1]

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 = 998244353
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)
#cmb(n-1, pair, p)

result=0
for i in range(1,len(a)):
    if a[i-1]<nn//2 and a[i]>=nn//2:
        if a[i]==nn:
            print(nn,a[i-1])
            exit()
        if cmb(nn,a[i-1],1)>cmb(nn,a[i],1):
            print(nn,a[i-1])
        else:
            print(nn,a[i])

        exit()

Submission status: Runtime Error

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

a.sort()
nn=a[-1]

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 = 998244353
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)
#cmb(n-1, pair, p)

result=0
for i in range(1,len(a)):
    if a[i-1]<nn//2 and a[i]>=nn//2:
        if a[i]==nn:
            print(nn,a[i-1])
            exit()
        if cmb(nn,a[i-1],1)>cmb(nn,a[i],1):
            print(nn,a[i-1])
        else:
            print(nn,a[i])

        exit()

Submission status: Runtime Error

Solution code:
import sys
from bisect import bisect_left

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


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = max(A)
    A = A[:-1]
    target = MAX // 2
    idx = bisect_left(A, target)

    if idx == 0:
        print(MAX, A[0])
    else:
        if abs(target - A[idx]) < abs(target - A[idx - 1]):
            print(MAX, A[idx])
        else:
            print(MAX, A[idx - 1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
ama = A[-1]
print(ama, end=' ')
ama2 = (ama + 1)//2
w = bisect.bisect_left(A, ama2)

a = A[w]
b = A[w+1]
if abs(a-ama2) > abs(b-ama2):
    print(b)
else:
    print(a)

Submission status: Runtime Error

Solution code:
def fact(n):
    ans  = 1
    for i in range(1, n+1):
        ans *= i
    return ans
n = int(input())
nums = list(map(int, input().split()))
ans = []
tp = 0
temp = 0
for f in range(n):
    for l in range(n):
        if(nums[f]!= nums[l]):
            temp = fact(nums[f])/(fact(nums[f]-nums[l])*fact(nums[l]))
            if(temp > tp):
                ans = [nums[f], nums[l]]
                tp = temp
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
conb = [0]*a[0]
conb[0] = a[0]
for j in range(1,a[0]):
    conb[j] = conb[j-1]*(a[0]-j)

for i in range(1,n):
    b = conb[a[i]-1] / math.factorial(a[i])
    if b >= ans:
        ans1 = a[i]
        ans = b
print(a[0],ans1)

Submission status: Runtime Error

Solution code:
#from scipy.misc import comb
from scipy.special import comb
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
for i in range(1,n):
    b = comb(a[0],a[i])
    if b >= ans:
        ans1 = a[i]
        ans = b
print(a[0],ans1)

Submission status: Runtime Error

Solution code:
import math
import bisect


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())

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

ncr = 0
ans = [0, 0]

id = bisect.bisect_left(a[:n-1], a[n-1]//2)
if abs(a[-1]/2 - a[id]) <= abs(a[-1] - a[id+1]):
    ans = id
else:
    ans = id+1

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

Submission status: Runtime Error

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

if sai%2==0:
  b=sai//2
  hantei=10**9+1
  suuji=0
  for i in a:
    if abs(b-i)<hantei and i!=sai:
      hantei=abs(b-i)
      suuji=i
  print(sai,suuji)
else:
  b1=sai//2
  b2=sai//2+1
  hantei=10**9
  suuji=0
  for i in a:
    if min(abs(b1-i),abs(b2-i))<hantei:
      hantei=abs(b-i)
      suuji=i
  print(sai,suuji)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2+1)
if index == 0:
    r = A[0]
elif index == N-2:
    r = A[N-2]
else:
    if abs(n//2+1-A[index]) <= abs(n//2+1-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
mod = (10 ** 9 + 7) ** 2
MAX = 2 * (10 ** 5) + 1 # これは変動するので注意。せいぜい10 ** 6くらいまでがTLEの限界

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

t = -float('inf')
MAX = max(nums)
ans = None
for num in nums:
    if num == MAX:
        continue
    r = nCr(MAX, num)
    if r > t:
        t = r
        ans = (MAX, num)
print(*ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans1 = max(a)
diff = min(ans1//2, ans1//2 + 1)
ans2 = ans1
for x in a:
  if x == ans1:
      continue
  d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x))
  if d <= diff:
    diff = d
    ans2 = x
print('{} {}'.format(ans1, ans2)

Submission status: Runtime Error

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

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == N-1:
    index -= 1
    
print(a[-1],a[index])

Submission status: Runtime Error

Solution code:
import math

def main2():
    input()
    t = sorted(list(map(int, input().split())))
    c = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2]) * math.factorial(t[len(t)//2]))
    c2 = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2 + 1]) * math.factorial(t[len(t)//2 + 1]))
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Submission status: Runtime Error

Solution code:
import math

def main2():
    input()
    t = sorted(list(map(int, input().split())))
    combs = {}
    comb(t[-1], t[len(t)//2], exact=True)
    c = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2]) * math.factorial(t[len(t)//2]))
    c2 = math.factorial(t[-1]) // (math.factorial(t[-1] - t[len(t)//2 + 1]) * math.factorial(t[len(t)//2 + 1]))
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Submission status: Runtime Error

Solution code:
from scipy.misc import comb


def main2():
    input()
    t = sorted(list(map(int, input().split())))
    combs = {}
    c = comb(t[-1], t[len(t)//2], exact=True)
    c2 = comb(t[-1], t[len(t)//2 + 1], exact=True)
    if c < c2:
        print(t[-1], t[len(t) // 2 + 1])
    else:
        print(t[-1], t[len(t) // 2])



if __name__ == '__main__':
    main2()

Submission status: Runtime Error

Solution code:
from scipy.misc import comb

url = "https://atcoder.jp//contests/abc094/tasks/arc095_b"

def main():
    input()
    t = list(map(int, input().split()))
    combs = {}
    for i in range(len(t) - 1, len(t) - 1):
        for j in range(i + 1, len(t)):
            tmp = sorted([t[i], t[j]], reverse=True)
            combs[comb(tmp[0], tmp[1], exact=True)] = tmp[::]
    key = max(combs.keys())
    print(' '.join([str(v) for v in combs[key]]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb

url = "https://atcoder.jp//contests/abc094/tasks/arc095_b"

def main():
    input()
    t = list(map(int, input().split()))
    combs = {}
    for i in range(len(t)):
        for j in range(i + 1, len(t)):
            tmp = sorted([t[i], t[j]], reverse=True)
            combs[comb(tmp[0], tmp[1], exact=True)] = tmp[::]
    key = max(combs.keys())
    print(' '.join([str(v) for v in combs[key]]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

n = max(A)

A_sorted = sorted(A)

max_nCr = 0
r = 0

import bisect

index = bisect.bisect_left(A_sorted, n/2)

from operator import mul
from functools import reduce

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

# print(A_sorted[index], A_sorted[index-1:index+1])
min_diff = float('inf')
for a in A_sorted[index-1:index+1]:
    if min_diff > abs(n/2 - a) and a != n:
        r = a

print(n, r

Submission status: Runtime Error

Solution code:

n=int(input())
A=sorted(list(map(int, input())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now:
    now=abs(a-half)
    ans=a
print(amax, ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n=int(input())
A=sorted(list(map(int, input())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now:
    now=abs(a-half)
    ans=a
print(amax, ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n=int(input())
A=sorted(list(map(int, input())))
amax=max(A)
m=bisect_left(A,amax/2)
a,b=A[m],A[m+1]
if a-amax/2<=amax-b-amax/2:
  print(amax, a)
else:
  print(amax,b)

Submission status: Runtime Error

Solution code:
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * (n + 1)

# nC1 = n
memo[1] = n

for i in range(2, n):
  # memo[i] = memo[i - 1] * (n - i + 1) // i
  memo[i] = 2

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i

print(n, max_at)

Submission status: Runtime Error

Solution code:
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * (n + 1)

# nC1 = n
memo[1] = n

for i in range(2, n):
  memo[i] = memo[i - 1] * (n - i + 1) // i

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i

print(n, max_at)

Submission status: Runtime Error

Solution code:
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * n

# nC1 = n
memo[1] = n

for i in range(2, n):
  memo[i] = memo[i - 1] * (n - i + 1) // i

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i
          
print(n, max_at)

Submission status: Runtime Error

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

b=len(a)
Z=a[-1]
X=0
for i in range(1,N-1):
  if abs((Z/2)-A[X])>abs((Z/2)-A[i]):
    X=i



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

Submission status: Runtime Error

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

b=len(a)
Z=a[-1]
X=0
for i in range(1,N-1):
  if abs((Z/2)-A[X])>abs((Z/2)-A[i]):
    X=i



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

Submission status: Runtime Error

Solution code:
n = float(input())
a = list(map(float, input().split()))
a.sort()
max = a[int(n)-1]
ans = 0
answer = [0,0]

def kai(p):
    if p == 0:
        return 1
    return kai(p-1)*p


for i in range(0,int(n)-1):
    b = kai(max) / ((kai(a[i]))*(kai(max-(a[i]))))
    if (b > ans):
        ans = b
        answer = [int(max),int(a[i])]
print(*answer)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[n-1]
ans = 0
answer = [0,0]

def kai(p):
    if p == 0:
        return 1
    return kai(p-1)*p


for i in range(0,n-1):
    b = kai(max) / ((kai(a[i]))*(kai(max-(a[i]))))
    if (b > ans):
        ans = b
        answer = [max,a[i]]
print(*answer)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[n-1]
ans = 0
answer = [0,0]

def kai(p):
    if p == 0:
        return 1
    return kai(p-1)*p


for i in range(0,n-1):
    b = kai(max) / ((kai(a[i]))*(kai(max-(a[i]))))
    if (b > ans):
        ans = b
        answer = [max,a[i]]
print(answer)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if A[-1]%2 == 0:
        if abs(A[k-1]-M) <= abs(M-A[k]) and abs(A[k-1]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    else:
        if abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if N == 2:
        print(*reversed(A))
        exit()
    if abs(A[k-1]-M) < abs(M-A[k]) and abs(A[k-1]-M) < abs(A[k+1]-M):
        ans = [A[-1],A[k-1]]
    elif abs(A[k+1]-M) < abs(M-A[k]) and abs(A[k+1]-M) < abs(A[k-1]-M):
        ans = [A[-1],A[k+1]]
    elif abs(A[k-1]-M) > abs(M-A[k]) and abs(A[k]-M) < abs(A[k+1]-M):
        ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from scipy import special
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
l=list(map(int,input().split()))
l.sort()
mm=l[-1];ans=0;p=0
for i in range(max(0,bl(l,l[-1]//2)-2),min(n,l[-1]//2+3)):
    g=scipy.special.comb(mm, l[i], exact = False)
    if ans<g:
        ans=g
        p=i
print(mm,l[p])

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
ma = max(A)
mid = ma / 2
l = 10000000000
for i in rage(n):
  l = min(l, abs(A[i]-mid))
print(ma, mid-l)

Submission status: Runtime Error

Solution code:
from bisect import bisect

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

x=a[-1]

if n%2==0:
  mid=x//2
else
  mid=x//2+1

if mid in a:
  print(x,mid)
else:
  inx=bisect(a,mid)
  if a[inx]-mid>=mid-a[inx-1]:
    print(x,a[inx-1])
  else:
    print(x,a[inx])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans_bigger = max(a)
ans_half = a / 2
dif = float("inf")
for i in range(n):
  x = abs(a[i]-ans_half)
  if dif > x:
    dif = x
    ans_smaller = a[i]
print(ans_bigger,ans_smaller)

Submission status: Runtime Error

Solution code:
import bisec
n = int(input())
a = sorted(list(map(int,input().split())))
t = bisec.bisec_left(a,a[n-1]//2)
if t == 0:
    print(a[n-1],a[t])
else:
    if abs(a[n-1]//2-a[t]) > abs(a[n-1]//2-a[t-1]):
        print(a[n-1],a[t-1])
    else:
        print(a[n-1],a[t])

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=[]
K=[max(A)]
def kaijou(N):
    if N<1:
        return 1
    else:
        return N*kaijou(N-1)
zantei=K[0]/(kaijou(A[0])*kaijou(K[0]-A[0]))
for i in range(n):
    zantei=max(zantei,K[0]/(kaijou(A[i])*kaijou(K[0]-A[i])))
    if zantei==K[0]/(kaijou(A[i])*kaijou(K[0]-A[i])):
        ans.append([K[0],A[i]])
print(*ans[-1])

Submission status: Runtime Error

Solution code:
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer

n = int(input())
alist = list(map(int, input().split()))
m = max(alist)
ans = 0
ans_ = (0, 0)
sbn = 10**10
for a in alist:
    if a == b:
        continue
    sbn_ = abs(m//2-a)
    if sbn_ < sbn :
        sbn = sbn_
        nck = nCk(m, a)
        # print(nck)
        ans = nck
        ans_ = (m, a)
print(ans_[0], ans_[1])

Submission status: Runtime Error

Solution code:
import bisect as b
from math import factorial


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


n = int(input().strip())
a = list(map(int, input().split()))
a.sort()
ans = []
comb = 0

if n == 2:
    print(" ".join([str(a[1]), str(a[0])]))
    exit()

for i in range(len(a)):
    r1 = a[b.bisect_left(a, (a[i] // 2))]
    r2 = a[b.bisect_right(a, (a[i] // 2))]
    r = 0
    rep = 0
    if n < r2:
        rep = combinations_count(a[i], r1)
        r = r1
    else:
        comb_r1 = combinations_count(a[i], r1)
        comb_r2 = combinations_count(a[i], r2)
        if comb_r1 < comb_r2:
            rep = comb_r2
            r = r2
        else:
            rep = comb_r1
            r = r1
    if comb < rep and a[i] != r:
        comb = max(comb, rep)
        ans = [a[i], r]
print(" ".join(map(str, ans)))

Submission status: Runtime Error

Solution code:
from math import factorial
import bisect

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

lst = sorted(lst)

ans = (-1,-1)
val = -1

def nCr(n,r):
    return factorial(n)/factorial(n-r) * factorial(r)

if n == 2:
    print(max(lst), min(lst))
else:
    for i in range(1, n):
        num = lst[i]
        pos = bisect.bisect_left(lst, num//2)
        r = lst[pos]
        
        tmp_val = nCr(num, r)
        if tmp_val > val:
            val = tmp_val
            ans = (num, r)
    
    print(max(ans), min(ans))

Submission status: Runtime Error

Solution code:
from math import factorial
import bisect

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

lst = sorted(lst)

ans = (-1,-1)
val = -1

def nCr(n,r):
    return factorial(n)/factorial(n-r) * factorial(r)

if n == 2:
    print(max(lst), min(lst))
else:
    for i in range(1, n):
        num = lst[i]
        pos = bisect.bisect_left(lst, num//2)
        r = lst[pos]
        
        tmp_val = nCr(num, r)
        if tmp_val > val:
            val = tmp_val
            ans = (num, r)
    
    print(max(ans), min(ans)

Submission status: Runtime Error

Solution code:

from math import factorial
import bisect

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

lst = sorted(lst)

ans = (-1,-1)
val = -1

def nCr(n,r):
    return factorial(n)/factorial(n-r) * factorial(r)

if n==2:
    print(*lst)
    exit()

for i in range(1, n):
    n = lst[i]
    r1 = bisect.bisect_left(lst, n//2)
    r2 = bisect.bisect_right(lst, n//2)
    
    v1 = nCr(n, lst[r1])
    v2 = nCr(n, lst[r2])
    
    if v1 > val and n!=lst[r1]:
        val = v1
        ans = (n, lst[r1])
    if v2 > val and n!=lst[r2]:
        val = v2
        ans = (n, lst[r2])
    
print(*ans)

Submission status: Runtime Error

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

a.sort()
m = a[-1] // 2 + a[-1] % 2

i = bisect_left(a, m)

if i == 0:
    ans = str(a[-1]) + " " + str(a[0])
elif i == len(a)-1:
    ans = str(a[-1]) + " " + str(a[-2])
else:
    k = [a[i] - m, m - a[-1] % 2 - a[i-1]]
    s = min(m - a[-1] % 2 - a[i-1], a[i] - m)
    k.index(s)
    ans = str(a[-1]) + " " + str(a[i-s])     

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
aa = sorted(list(map(int,input().split())))
a_max = max(aa)

half = a_max/2
p = bisect_left(aa, half)
if abs(half - aa[p]) >= abs(half - aa[p-1]):
  print(a_max,aa[p-1])  
else:
  print(a_max,aa[p])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1]
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
d={}
for i in range(n-1):
    d[i]=cmb(m,a[i])
print(a[-1],a[max(d,key=d.get)])

Submission status: Runtime Error

Solution code:
#094d
from scipy.special import comb
from bisect import bisect_left, bisect_right

n = int(input())
a_list = [int(e) for e in input().split()]

#n 個のものから順番を無視して r 個を選ぶ場合の数を comb(n,r) と書くことにします。 
#n 個の非負の整数 a1,a2,...,an から 2 つの数 ai > aj を comb(ai,aj) が最大になるように選んで下さい。 
#最大になる組が複数ある場合、どれを選んでも構いません。

#全組み合わせはn*(n-1)≒10**10 地球爆発

#comb = n*(n-1)*…*(n-r) / r
#from scipy.special import combすれば = comb(n, r, exact=True) で計算可能
#nに最大の値、rにその半分の値(nが奇数なら±0.5)を使った時に大きい値をとることを下記で確認した。
#from scipy.special import comb

#for i in range(101):
#    max_comb = 0
#    max_comb_j = 1 
#    for j in range(1,i):
#        ij_comb = comb(i, j, exact=True) 
#        if ij_comb > max_comb:
#            max_comb = ij_comb
#            max_comb_j = j
#            
#    print(i,max_comb_j,max_comb)


#が、丁度良く半分の値があるとは限らない。
#∴n側は全探索して、rはbisectで半分の値を探る

a_list.sort(reverse=False)

#仮値を入れる
max_comb = comb(a_list[1], a_list[0], exact=True) 
max_comb_ai = a_list[1]
max_comb_aj = a_list[0]

#n側を全探索
for ai in a_list: #10**5
    aj_left = bisect_left(a_list, ai/2) #O(log N)…17回で探れる　∴17*10**5なので間に合いそう
    
    #半分に近い値を算出
    if a_list[aj_left] == ai/2:
        aj_list = [a_list[aj_left]]
    elif a_list[aj_left] < ai/2:
        if aj_left != n-1:
            aj_list = [a_list[aj_left],a_list[aj_left + 1]]
        else:
            aj_list = [a_list[aj_left]]
    elif a_list[aj_left] > ai/2:
        if aj_left != 0:
            aj_list = [a_list[aj_left],a_list[aj_left - 1]]
        else:
            aj_list = [a_list[aj_left]]
    
    #combを計算
    for aj in aj_list:
        temp_comb = comb(ai, aj, exact=True)
        if temp_comb > max_comb:
            max_comb = temp_comb
            max_comb_ai = ai
            max_comb_aj = aj
        
print(max_comb_ai,max_comb_aj)

Submission status: Runtime Error

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

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(len(A)-1,len(A)//2,-1):
  bunshi=A[i]
  target=A[i]//2
  tarp=bisect.bisect_left(A,target)
  for j in (-1,0):
    if tarp+j>=0 and tarp+j<len(A):
      c=cmb(bunshi,A[tarp+j])
      if c>maxval:
        maxval=c
        maxpair=[bunshi,A[tarp+j]]

print(*maxpair)

Submission status: Runtime Error

Solution code:
# nCr的にn//2に近いほうがいいに決まっている
# まあnCrは計算しなくていい

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


def lower_bound(arr, t):
    l, r = 0, len(arr)
    while l < r:
        mid = (l + r) // 2
        if arr[mid] < t:
            l = mid + 1
        else:
            r = mid
    return l


lb = lower_bound(arr[:-2], arr[-1] // 2)
lb_left = max(0, lb - 1)
if lb == lb_left:
    raise ValueError("omg")
if arr[lb] <= arr[lb_left]:
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Runtime Error

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

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2
ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(ans[bi]))

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
N = int(input())
A = sorted(list(map(int, input().split())), reverse = True)

if N == 2:
	print(A[0], A[1])
else:
	q = max(A)
	B = list(map(lambda x : abs(q // 2 - x),  A))
	print(q, A[B.index(min(B))])

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N = int(input())
A = sorted(list(map(int, input().split())), reverse = True)

if N == 2:
	print(A[0], A[1])
else:
	q = max(A)
	B = list(map(lambda x : abs(q // 2 - x),  A))
	print(q, A[B.index(min(B))])

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
tmp = 0
r = 0
for a in A:
    if maxA == a:
        continue
    combA = comb(maxA, a)
    if tmp < combA:
        tmp = combA
        r = a

print(maxA, r)

Submission status: Runtime Error

Solution code:
import bisect as bi

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

ai=a[-1]
j=bi.bisect_left(a,ai/2)

if ai/2-a[j]<=a[j+1]-ai/2:
    print(ai,a[j])
else:
    print(ai,a[j+1])

Submission status: Runtime Error

Solution code:
def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

n = int(input())
a = list(int(x) for x in input().split())
a.sort()
key = []
key1 = a[0]
key2 = 1000000007
for i in range(1, n):
    key3 = a[i] - a[i-1]
    if key3 < key1 and key3 < key2:
        key2 = key3
        key.append([a[i], a[i-1]])
key.append([a[1], a[0]])
ans = 0
answer = 0
for value in key:
    i, j = value[0], value[1]
    k = nCr(i, j)
    if ans:
        if k < ans:
            ans = k
            answer = [i, j]
    else:
        ans = k
        answer = [i, j]
for i in range(2):
    print(answer[i], end=" ")

Submission status: Runtime Error

Solution code:
def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

n = int(input())
a = list(int(x) for x in input().split())
a.sort()
ans = 0
for i in range(1, n):
    value = a[i]
    key = min([value-a[0], value-a[i-1]])
    judge = nCr(value, key)
    if ans:
        if judge < ans:
            ans = judge
    else:
        ans = judge
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

A=sorted(A)
maxA=max(A)
limit=math.ceil(maxA/2)
comb=min(A)
for i in range(N):
    if(limit<A[i]):
        if(abs(limit-A[i+1])<abs(limit-A[i])):
            comb=A[i+1]
        break
    comb=A[i]

print(maxA,comb)

Submission status: Runtime Error

Solution code:
import math

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

A=sorted(A)
maxA=max(A)
limit=math.ceil(maxA/2)
comb=min(A)
for i in range(N):
    if(limit<A[i]):
        if(abs(limit-A[i+1])<abs(limit-A[i])):
            comb=A[i+1]
    comb=A[i]

print(maxA,comb)