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: Time Limit Exceeded

Solution code:
from math import factorial as fac
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
t = 0
mxf = fac(mx)
for a in A:
    _t = mxf // (fac(mx-a)*fac(a))
    if t < _t:
        t = _t
        mn = a
    else:
        break
print(mx, mn)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = math.factorial(st_r)*math.factorial(st_n-st_r)
for r in range(1,N):
    cn = math.factorial(a[r])*math.factorial(st_n-a[r])
    if cn < m:
        st_r = a[r]
        m = cn
print(st_n,st_r)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
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:
            cn = math.factorial(a[n])//(math.factorial(a[r])*math.factorial(a[n]-a[r]))
            if m < cn:
                st_n = a[n]
                st_r = a[r]
                m = cn

print(st_n,st_r)

Submission status: Time Limit Exceeded

Solution code:
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
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
ans=0
ans_r=0
for i in a:
  if i==l:
    continue
  b=cmb(l,i)
  if ans<b:
    ans=b
    ans_r=i
print(l,ans_r)

Submission status: Time Limit Exceeded

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

L = sorted(L)

import math

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

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

print(L[-1], seikai)

Submission status: Time Limit Exceeded

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

import math

@lru_cache(maxsize=None)
def combi(n,r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

max_combi = 0
l=0
for r in range(1,n):

    while a[l] <= (a[r]+1)//2:
        l+=1
    l-=1
    
    c = combi(a[r], a[l])
    if c > max_combi:
        max_combi = c
        x,y = a[r], a[l]

print(x,y)

Submission status: Time Limit Exceeded

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

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

max_combi = 0
l=0
for r in range(1,n):

    while a[l] <= (a[r]+1)//2:
        l+=1
    l-=1
    
    c = combi(a[r], a[l])
    if c > max_combi:
        max_combi = c
        x,y = a[r], a[l]

print(x,y)

Submission status: Time Limit Exceeded

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

import math
def combi(n,r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
from bisect import bisect_left

max_combi = 0
l=0
r=1
for i in range(1,n):
    idx = bisect_left(a, (a[i]+1)//2)
    if a[idx] > (a[i]+1)//2:
        idx -= 1
    c = combi(a[i], a[idx])
    if c > max_combi:
        max_combi = c
        x,y = a[i], a[idx]

print(x,y)

Submission status: Time Limit Exceeded

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

import math
def combi(n,r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
from bisect import bisect_left

max_combi = 0
for i in range(1,n):
    idx = bisect_left(a[:i], (a[i]+1)//2)
    if a[idx] > (a[i]+1)//2:
        idx -= 1
    c = combi(a[i], a[idx])
    if c > max_combi:
        max_combi = c
        x,y = a[i], a[idx]

print(x,y)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys

mod = 10**9+7

def modInverse(a,p):
    return pow(a,p-2,p)

def nCr(n,r,p=mod):
    num = 1
    den = 1
    for i in range(r):
        num = (num*(n-i)) % p
        den = (den*(i+1)) % p
    return num*modInverse(den,p)% p

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=list(map(int, input().split()))
s=max(L)
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

c=0
for i in range(n):	
	d=cmb(s,L[i])
	if d>=c and L[i]!=s:
		c=d
		a=L[i]
A=[s, a]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=list(map(int, input().split()))
s=max(L)

from math import factorial
c=0
for i in range(n):	
	d=factorial(s)/factorial(L[i])/factorial(s-L[i])
	if d>=c and L[i]!=s:
		c=d
		a=L[i]
A=[s, a]
print(*A)

Submission status: Time Limit Exceeded

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)
        ],
        key=lambda x: x[2],
        reverse=True
    )[0]

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

Submission status: Time Limit Exceeded

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_comb = 0
    i, j = -1, -1
    for c in combinations(a, 2):
        m, n = max(c), min(c)
        comb_val = comb(m, n)
        if max_comb < comb_val:
            max_comb = comb_val
            i, j = m, n

    print(i, j)

Submission status: Time Limit Exceeded

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_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()
maxA = A[-1]

fact = [1]
for i in range(1, maxA+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

ans = [A[1], A[0]]
mcand = cmb(A[1], A[0])
for a in reversed(A):
    even = a%2==0
    div = a//2
    ind = bisect_left(A, div)
    cand1 = cmb(a, A[ind-1])
    cand2 = cmb(a, A[ind])
    # print(a, cand1, cand2)

    upd = False
    for i, can in enu([cand1, cand2]):
        if mcand < can:
            mcand = can
            ans = [a, A[ind-1+i]]
            upd = True
            # print('upd!', mcand)
    if not(upd):
        break

print(*ans)

Submission status: Time Limit Exceeded

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_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()
maxA = A[-1]

fact = [1]
for i in range(1, maxA+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

ans = [A[1], A[0]]
mcand = cmb(A[1], A[0])
for a in A:
    even = a%2==0
    div = a//2
    ind = bisect_left(A, div)
    cand1 = cmb(a, A[ind-1])
    cand2 = cmb(a, A[ind])
    if mcand < cand1:
        ans = [a, A[ind-1]]
    if mcand < cand2:
        ans = [a, A[ind]]

print(*ans)

Submission status: Time Limit Exceeded

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

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p
p=10**9+7

ans = 0
comb = 0
for i in a:
    if mx == i:
        continue
    tmp = ncr(mx, i, p)
    if comb <= tmp:
        ans = i 
        comb = tmp
print(mx, ans, sep=" ")

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
a.sort()
t_max=0
ans=[]
for i in range(n//2,n):
  for j in range(0,n//2+1):
    t=math.factorial(a[i])//math.factorial(a[j])//math.factorial(a[i]-a[j])
    if t > t_max:
      t_max=t
      ans=[a[i],a[j]]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = 0
ans = [0, 0]
for i in range(N):
  for j in range(i+1, N):
    if A[i] < A[j] and (A[j]-A[i])*A[i]>=a:
      ans = [A[j], A[i]]
      a = (A[j]-A[i])*A[i]
    elif (A[i]-A[j])*A[j]>=a:
      ans = [A[i], A[j]]
      a = (A[i]-A[j])*A[j]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from bisect import bisect_left


def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp



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

ans = 0
for a in A:
    tmp = bisect_left(A, a//2)

    aCb = combination(a, A[min(tmp, N - 1)])
    if ans < aCb and a > A[min(tmp, N - 1)]:
        a1 = a
        b1 = A[min(tmp, N - 1)]
        ans = aCb

    aCb = combination(a, A[max(0, tmp - 1)])
    if ans < aCb and a > A[max(0, tmp - 1)]:
        a1 = a
        b1 = A[max(0, tmp - 1)]
        ans = aCb

print (a1, b1)

Submission status: Time Limit Exceeded

Solution code:
import math
import operator
from functools import reduce

def combinations_count(n, r):
  return reduce(operator.mul, [elem for elem in range(n-r+1, n+1)], 1) // math.factorial(r)

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

max_ = 0
arg1, arg2 = 0, 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
      arg1 = max(a1, a2)
      arg2 = min(a1, a2)
print(arg1, arg2)

Submission status: Time Limit Exceeded

Solution code:
# D - Binomial Coefficients

import sys
readline = sys.stdin.readline

n = int(readline())
A = list(int(a) for a in readline().split())
A.sort(reverse=True)

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

tmp = 0
ans = (0, 0)
for i in range(1, n):
    c = comb(A[0], A[i])
    if tmp < c:
        tmp = c
        ans = (A[0], A[i])

print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
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()))
AS = sorted(list(set(A)))
n = AS[-1]
r = AS[0]
combM = cmb(n, r)

for i in range(1,len(AS)):
    tempr = AS[i]
    tempc = cmb(n, tempr)
    if combM >= tempc:
        break
    r = tempr
    combM = tempc


print(str(n) + ' ' + str(r))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

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

maxa = max(A)

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

i = 0
while True:
    if l2-i in A:
        print(maxa, l2-i)
        break
    
    if r2+i in A:
        print(maxa, r2+i)
        break
    
    i += 1

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
def comb(n,k):
    nCk = 1
    mod = 10**9+7
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= mod
    for i in range(1, k+1):
        nCk *= pow(i, mod-2, mod)
        nCk %= mod
    return nCk

n = int(input())
A = list(map(int,input().split()))
A.sort()
y = max(A)
idx = bisect_left(A, y//2)
ans = -1
x = idx
for i in range(max(0, idx-1), min(n+1, idx+1)):
    if comb(y, A[i]) > ans:
        ans = comb(y,A[i])
        x = A[i]
print(y,x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
a_list.sort()
a_max = a_list.pop()
result = []
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for a in a_list:
  result.append(comb(a_max,a))

print(a_max,a_list[result.index(max(result))])

Submission status: Time Limit Exceeded

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

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

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
maximum=0
for i in range(N-1):
  c = binary(i+1,A[i]/2)
  cmb_i=cmb(A[i],c)
  if maximum<cmb_i:
    ans1=A[i];ans2=c
    maximum=cmb_i

print(ans1,ans2)

Submission status: Time Limit Exceeded

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(l[-1],0)
  exit()
k2 = l[s+1]
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: Time Limit Exceeded

Solution code:
import math

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

A.sort()

max_cmb = 0
m = A[-1]
r = 0
for a in A[: -1]:
    cmb = math.factorial(m) // (math.factorial(m - a) * math.factorial(a))
    if max_cmb < cmb:
        max_cmb = cmb
        r = a

print(m, r)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)
# hex_str = hex(i)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()
	A.sort()
	AA = A[::-1]

	ans1 = AA[0]
	ans2 = AA[-1]
	mmm = combination(ans1, ans2)
	for i,val in enumerate(AA):
		ans11 = val
		tmp = val // 2
		ind = bisect_left(A, tmp)
		tmp = A[ind]

		if tmp == val:
			continue

		ans = combination(val, tmp)

		#print("{} {} {}".format(ans11, tmp, ans))
		if mmm < ans:
			mmm = ans
			ans1 = ans11
			ans2 = tmp

	print("{} {}".format(ans1,ans2))



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
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):
    s1 = max(arr)

    if n % 2 == 0:
        mid1, mid2 = s1 // 2, s1 // 2
    else:
        mid1, mid2 = s1 // 2, s1 // 2 + 1

    offset = 0
    find = False
    while find == False:
        find = (mid1 - offset) in arr
        if find == True:
            return s1, mid1 - offset
        find = (mid2 + offset) in arr
        if find == True:
            return s1, mid2 - offset
        offset = offset + 1


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

Submission status: Time Limit Exceeded

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()))
num_total = max(a_ls)
a_ls.remove(num_total)
Max = 0
for a in a_ls:
    c = combinations_count(num_total,a)
    if Max <= c:
        Max = c
        r = a
print(num_total,r)

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a_ls = list(map(int, input().split()))
num_total = max(a_ls)
a_ls.remove(num_total)
Max = 0
for a in a_ls:
    c = combinations_count(num_total,a)
    if Max <= c:
        Max = c
        r = a
print(num_total,r)

Submission status: Time Limit Exceeded

Solution code:
from 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: Time Limit Exceeded

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()
A.sort()

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

max = max(A)
index = bisect_left(A, max / 2)
if cmb(max, A[index]) > cmb(max, A[index - 1]):
    ans = [max, A[index]]
else:
    ans = [max, A[index - 1]]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
ama = A[-1]
ama2 = (ama + 1)//2

for i in range(ama2 + 1):
    a = ama2 + i
    b = ama2 - i

    if b in A:
        print(ama, end=' ')
        print(b)
        exit()
    if a in A:
        print(ama, end=' ')
        print(a)
        exit()

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))

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

cand = 0
for i in range(n):
    big_num = A[-1 - i]
    th_max = combinations_count(big_num, big_num // 2)
    if cand >= th_max:
        break
    else:
        near_mid_pointer = bisect.bisect_left(A, big_num / 2)
        dif1 = 10**9 + 1
        if near_mid_pointer != 0:
            dif1 = big_num / 2 - A[near_mid_pointer - 1]
        dif2 = A[near_mid_pointer] - big_num / 2
        if dif1 <= dif2:
            if cand < combinations_count(big_num, A[near_mid_pointer - 1]):
                num1 = big_num
                num2 = A[near_mid_pointer - 1]
                cand = combinations_count(big_num, A[near_mid_pointer - 1])

        else:
            if cand < combinations_count(big_num, A[near_mid_pointer]):
                num1 = big_num
                num2 = A[near_mid_pointer]
                cand = combinations_count(big_num, A[near_mid_pointer])

print(num1, num2)

Submission status: Time Limit Exceeded

Solution code:
dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n=int(input())
a=sorted(list(map(int,input().split())))
def f(n,r):
  return factorial(n) // factorial(r) // factorial(n - r)
ans=0
n=a[-1]
for j,i in enumerate(a):
  b=f(n,i)
  ans=max(ans,b)
  if b<ans:
    print(n,a[max(0,j-1)])
    exit()
print(n,a[-2])

Submission status: Time Limit Exceeded

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = -1
nck = 0

for i in range(n):
    tmp = comb(ai, a[i])
    if nck <= tmp:
        nck = tmp
        aj = a[i]

print(str(ai) + " " + str(aj))

Submission status: Time Limit Exceeded

Solution code:
import math


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


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

ans = 0
a_i = a[0]
a_j = a[1]
for idx in range(1, n):
    if ans < combinations_count(a_i, a[idx]):
        ans = combinations_count(a_i, a[idx])
        a_j = a[idx]

print("%d %d" % (a_i, a_j))

Submission status: Time Limit Exceeded

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

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

def main():
    A_max = max(A)
    kaijo_table = [1 for _ in range(A_max + 1)]
    tmp = 1
    for i in range(1, A_max + 1):
        tmp *= i
        kaijo_table[i] = tmp
    my_max = 0
    for a in A:
        if a != A_max:
            tmp = (kaijo_table[A_max] // 
            (kaijo_table[a] * kaijo_table[A_max - a]))
            if my_max <= tmp:
                my_max = tmp
                ans = (A_max, a)
    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n - i
        ans /= (i + 1)
    return ans

def main():
    A_max = max(A)
    my_max = 0
    for a in A:
        if a != A_max:
            if my_max <= binomial_coefficients(A_max, a):
                my_max = binomial_coefficients(A_max, a)
                ans = (A_max, a)
    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

n = numbers[-1]
if n % 2 == 0:
    rl = n // 2
    rr = n // 2
else:
    rl = n // 2
    rr = n // 2 + 1

while not rr in numbers and not rl in numbers:
    rl -= 1
    rr += 1
if rl in numbers:
    ans = [n, rl]
else:
    ans = [n, rr]

print(*ans)