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

max_comb = 0
ai = numbers[-1]
ans = [ai, 0]

numerator = 1
denominator = 1

for i in range(1, ai):
    denominator *= i
    numerator *= ai - i + 1
    comb = numerator // denominator
    if i in numbers and comb > max_comb:
        max_comb = comb
        ans = [ai, i]
print(*ans)

Submission status: Time Limit Exceeded

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

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

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

now=0
l=0
r=0
for i in range(n-1):
    for j in range(i+1,n):
        c=cmb(A[j],A[i])
        if now<c:
            now=c
            l=A[i]
            r=A[j]
print(r,l)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod
max_a = max(a)
fac, finv = make_tables(max_a)
ans = [0, 0, 0]
for i in a:
    if nCk(max_a, i) >= ans[0]:
        ans = [nCk(max_a, i), max_a, i]

print(*ans[1:])

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import numpy as np
def comb(n, r):
	return factorial(n) // factorial(r) // factorial(n-r)

def ABC094D(n, a):
	a = sorted(a)[::-1]
	Max = comb(a[0], a[1])
	a0 = a[0]
	a1 = a[1]
	for i in range(n):
		N = a[i]
		#print(f"N = {N}")
		M = N / 2
		left = i
		left_value = a[left] - M
		right = n - 1
		right_value = a[right] - M
		while right-left > 1:
			middle = int((left + right) / 2)
			middle_value = a[middle] - M
			if middle_value == 0:
				comb_value = comb(N, middle_value)
				break
			elif np.sign(middle_value * right_value) == 1:
				right = middle
				right_value = middle_value
			else:
				left = middle
				left_value = middle_value
		temp = comb(N, a[left])
		if temp > Max:
			Max, a0, a1 = temp, N, a[left]
		if left != right:
			temp = comb(N, a[right])
			if temp > Max:
				Max, a0, a1 = temp, N, a[right]
		#print(a0, a1, comb(a0, a1))
	print(a0, a1)


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

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
def comb(n, r):
	return factorial(n) // factorial(r) // factorial(n-r)

def ABC094D(n, a):
	a = sorted(a)[::-1]
	Max = comb(a[0], a[1])
	a0 = a[0]
	a1 = a[1]
	for i in range(n):
		N = a[i]
		M = N / 2
		min_dist = abs(N - M)
		min_pos = i
		if comb(N, int(M)) >= Max or comb(N, int(M) + 1):
			for j in range(i, n):
				dist = abs(a[j] - M)
				if dist < min_dist:
					min_dist, min_pos = dist, j
		#print(f"comb({N}, {a[min_pos]}) = {comb(N, a[min_pos])}")
		Max_value = comb(N, a[min_pos])
		if 	Max_value > Max:
			Max, a0, a1 =  Max_value, N, a[min_pos]
	print(a0, a1)


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

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
def comb(n, r):
	return factorial(n) // factorial(r) // factorial(n-r)

def ABC094D(n, a):
	a = sorted(a)[::-1]
	Max = comb(a[0], a[1])
	a0 = a[0]
	a1 = a[1]
	for i in range(n):
		N = a[i]
		M = N / 2
		min_dist = abs(N - M)
		min_pos = i
		for j in range(i, n):
			dist = abs(a[j] - M)
			if dist < min_dist:
				min_dist, min_pos = dist, j
		#print(f"comb({N}, {a[min_pos]}) = {comb(N, a[min_pos])}")
		Max_value = comb(N, a[min_pos])
		if 	Max_value > Max:
			Max, a0, a1 =  Max_value, N, a[min_pos]
	print(a0, a1)


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

Submission status: Time Limit Exceeded

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 ** 6) + 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: Time Limit Exceeded

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa
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


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


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)
    ans = 0
    best = 0
    for a in A:
        res = cmb(max_A, a)
        if best < res and max_A > a:
            best = res
            ans = a

    print(max_A, ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as f


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


def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  
  max_comb = 0
  r = 0
  for i in range(n-1):
    tmp = nCr(a[-1], a[i])
    if tmp > max_comb:
      max_comb = tmp
      r = a[i]
  ans = "{} {}".format(a[-1], r)
  print(ans)

  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce


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


sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7


def main():
    def cmb(N, A):
        num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
        den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
        # pow(den,MOD-2,MOD)はdenの逆元
        return num * pow(den, MOD - 2, MOD) % MOD

    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    C = 0
    ans = -1
    for a in A:
        if a == 0:
            c = 1
        else:
            c = cmb(n, a)
        if c > C:
            C = c
            ans = a
        elif c < ans:
            break

    print(n, ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = max(a)
half_idx = bisect.bisect_left(a, m//2)

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 

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

if 1 <= half_idx < n-1:
    if ncr(m, a[half_idx-1], p) >= max(ncr(m, a[half_idx], p), ncr(m, a[half_idx+1], p)):
        print(m, a[half_idx-1])
    elif ncr(m, a[half_idx], p) >= max(ncr(m, a[half_idx-1], p), ncr(m, a[half_idx+1], p)):
        print(m, a[half_idx])
    elif ncr(m, a[half_idx+1], p) >= max(ncr(m, a[half_idx], p), ncr(m, a[half_idx-1], p)):
        print(m, a[half_idx+1])
elif half_idx == 0:
    if ncr(m, a[half_idx], p) >= ncr(m, a[half_idx+1], p):
        print(m, a[half_idx])
    elif ncr(m, a[half_idx+1], p) >= ncr(m, a[half_idx], p):
        print(m, a[half_idx+1])
elif half_idx == n-1:
    if ncr(m, a[half_idx], p) >= ncr(m, a[half_idx-1], p):
        print(m, a[half_idx])
    elif ncr(m, a[half_idx-1], p) >= ncr(m, a[half_idx], p):
        print(m, a[half_idx-1])

Submission status: Time Limit Exceeded

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

def closest(x):
    res = None
    min_diff = None
    for k in a:
        if k == m:
            continue
        diff = abs(k - x)
        if res is None or min_diff > diff:
            min_diff = diff
            res = k
    return res

def comb(n, k):
    if n-k < k:
        return comb(n, n-k)
    res = 1
    for i in range(n, n-k):
        res *= i
    for i in range(2, k):
        res //= i
    return res


if m % 2 == 0:
    print(m, closest(m // 2))
else:
    x1 = closest(m // 2)
    x2 = closest(m // 2 + 1)
    if comb(m,x1) > comb(m,x2):
        print(m, x1)
    else:
        print(m, x2)

Submission status: Time Limit Exceeded

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

Solution code:
import math
N = int(input())
ListA = list(map(int,input().split()))
Maxcomb = 0
Maxij = []
for i in range(N):
    for j in range(N):
        if ListA[i]<ListA[j] or i==j:
            continue
        else:
            Comb = (math.factorial(ListA[i])//(math.factorial(ListA[i]-ListA[j])*math.factorial(ListA[j])))
            if Maxcomb<Comb:
                Maxij = [ListA[i],ListA[j]]
                Maxcomb = max(Comb,Maxcomb)

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

Submission status: Time Limit Exceeded

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-1:index+1])
for a in A_sorted[index-1:index+1]:
    nCr = cmb(n, a)
    if max_nCr < nCr:
        r = a
        max_nCr = nCr
    elif max_nCr >= nCr:
        break

print(n, r)

Submission status: Time Limit Exceeded

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

n = max(A)

max_nCr = 0
r = 0

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

for a in sorted(A):
    nCr = cmb(n, a)
    if max_nCr < nCr:
        r = a
        max_nCr = nCr
    elif max_nCr >= nCr:
        break

print(n, r)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

n = int(input())
A = sorted(set(map(int, input().split())))


def comb(m, n):
    ans = factorial(m) / factorial(n) / factorial(m-n)
    return ans


max_num = A[-1]
answer = 0
for i in range(n):
    comb_num = comb(max_num, A[i])
    if answer >= comb_num:
        break
    answer = comb_num

print(max_num, A[i-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort()
max_value = max(list_A)
cnt = 0
hight = 1
hight_num = max_value
low = 1
low_num = 1
cnt = 0
ans = 0
b = 0
num = 1
for i in range(max_value):
    hight = hight_num - i
    low = low_num + i
    num = num*hight//low
    if list_A[cnt] == low_num + i:
        ans = max(ans, num)
        cnt += 1
        if ans == num:
            b = low_num + i

print(max_value, b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort()
max_value = max(list_A)
cnt = 0
hight = 1
hight_num = max_value
low = 1
low_num = 1
cnt = 0
ans = 0
b = 0
for i in range(max_value):
    hight *= hight_num - i
    low *= low_num + i
    if list_A[cnt] == low_num + i:
        ans = max(ans, hight//low)
        cnt += 1
        if ans == hight//low:
            b = low_num + i

print(max_value, b)

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())
list_A = list(map(int, input().split()))
max_value = max(list_A)
ans = 0
a = 0
for i in list_A:
    c = cmb(max_value, i)
    ans = max(ans, c)
    if ans == c:
        a = i

print(max_value, a)

Submission status: Time Limit Exceeded

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

@lru_cache(maxsize=None)
def frac(n):
    return math.factorial(n)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n=int(input())
a=sorted(list(map(int,input().split())))
b=a[n-1]
a.pop(n-1)
ans=[0,comb(b,a[0])]
for i in range(n-1):
    #print(a[i])
    if ans[1]<comb(b,a[i]):
        ans=[i,comb(b,a[i])]
print(str(b)+" "+str(a[ans[0]]))

Submission status: Time Limit Exceeded

Solution code:
import math

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


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

ans = 0
for i in range(10):
    for j in range(i, n):
        if i != j:
            c = comb(a[i], a[j])
            if ans < c:
                ans = c
                ansij = (i, j)
print(a[ansij[0]],a[ansij[1]])

Submission status: Time Limit Exceeded

Solution code:
def comb(n,r):
    r=min(r,n-r)
    h,k=1,1
    for i in range(1,r+1):
        h*=(n-r+i)
        k*=i
    return h//k
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)-1),min(n,l[-1]//2+2)):
    g=comb(mm,l[i])
    if ans<g:
        ans=g
        p=i
print(mm,l[p])

Submission status: Time Limit Exceeded

Solution code:
def comb(n,r):
    r=min(r,n-r)
    h,k=1,1
    for i in range(1,r+1):
        h*=(n-r+i)
        k*=i
    return h//k
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=comb(mm,l[i])
    if ans<g:
        ans=g
        p=i
print(mm,l[p])

Submission status: Time Limit Exceeded

Solution code:
def comb(n,r):
    r=min(r,n-r)
    h,k=1,1
    for i in range(1,r+1):
        h*=(n-r+i)
        k*=i
    return h//k
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)):
    if ans<comb(mm,l[i]):
        ans=comb(mm,l[i])
        p=i
print(mm,l[p])

Submission status: Time Limit Exceeded

Solution code:
import math

def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)


n=int(input())

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

a1 = max(t)

ans = 0

memo = 0

for i in t:
    if ans <= combination(a1,i):
        ans = combination(a1,i)
        memo = i
print(a1, memo)

Submission status: Time Limit Exceeded

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

a.sort()

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
  

sMAX = 1
memo=[a[1],a[0]]
memo2=[a[1],a[0]]
for i in range(n):
  MAX = 1
  for j in range(0, i):
    temp = cmb(a[i], a[j])
            
    if MAX <= temp:
      MAX = temp
      memo = [a[i], a[j]]
    else:
      break
      
  if sMAX < MAX:
    sMAX = MAX
    memo2 = memo
    
for i in range(2):
  print(memo2[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

ans = [-1, 0, 0]

from math import factorial

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

import bisect

for i in a[1:]:
    idx = [bisect.bisect_left(a, i // 2), bisect.bisect_left(a, i // 2) - 1]
    for j in idx:
        if i == a[j]:
            continue
        else:
            if i < a[j]:
                continue
            elif comb(i, a[j]) > ans[0]:
                ans = [comb(i, a[j]), i, a[j]]

print(*ans[1:])

Submission status: Time Limit Exceeded

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans = []
max_num = 0
for i in range(0,n):
    for j in range(i+1,n):
        if max_num < combinations_count(a[i],a[j]):
            ans.append([a[i],a[j]])
            max_num = combinations_count(a[i],a[j])
print(*ans[-1])

Submission status: Time Limit Exceeded

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

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)
for a in alist:
    nck = nCk(m, a)
    if nck >= ans:
        # print(nck)
        ans = nck
        ans_ = (m, a)
print(ans_[0], ans_[1])

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 = [int(_) for _ in input().split()]
a.sort()
#print(a)

ans_a = a[n-1]
maxi = 0
idx = 0
for i in enumerate(a):
    val = max(maxi, combinations_count(ans_a, i[1]))
    if maxi < val:
        idx = i[0]
        maxi = val
    #print(idx, maxi)
    else:
        break

ans_b = a[idx]
print(ans_a, ans_b)

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 = [int(_) for _ in input().split()]
a.sort()
#print(a)

ans_a = a[n-1]
maxi = 0
idx = 0
for i in enumerate(a):
    val = max(maxi, combinations_count(ans_a, i[1]))
    if maxi < val:
        idx = i[0]
        maxi = val
    #print(idx, maxi)

ans_b = a[idx]
print(ans_a, ans_b)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import bisect

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

a.sort()

def comb(x,y):
    return factorial(x) // factorial(y) // factorial(x-y)

count = 0
max1 = 0
ans = [0,0]

for i in a:
    j = bisect.bisect_left(a,i/2)
    if j-1 >= 0:
        if max1 < comb(i,a[j-1]) and i != a[j-1]:
            max1 = comb(i,a[j-1])
            ans = [i,a[j-1]]

    if j >= 0:
        if max1 < comb(i,a[j]) and i != a[j]:
            max1 = comb(i,a[j])
            ans = [i,a[j]]
    if j+1 < n:
        if i >= a[j+1]:
            if max1 < comb(i,a[j+1]) and i != a[j+1]:
                max1 = comb(i,a[j+1])
                ans = [i,a[j+1]]

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

Submission status: Time Limit Exceeded

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

n = int(input())
l = list(map(int, input().split()))
l.sort()
n = l.pop()
ans = 0
M = 0
for r in l:
  if com(n, r) > M:
    M = com(n, r)
    ans = r
print(n, ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
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 = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2
i = bisect_left(a, X)
j = i-1 if i>0 else 0
h = i+1 if i<N-1 else N-1
I = a[i]
J = a[j]
H = a[h]
ci = cmb(a[-1],I)
cj = cmb(a[-1],J)
ch = cmb(a[-1],H)
if max(ci,cj,ch)==ci and i!= N-1:
  print(a[-1],a[i])
elif max(ci,cj,ch)==ch and h!=N-1:
  print(a[-1],a[h])
else:
  print(a[-1],a[j])

Submission status: Time Limit Exceeded

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

def comb(a, b):
  s = 1
  for i in range(a, b, -1):
    s *= i
  return s/2
import math

MA = max(A)
ans = (0, 0)
AL = 0
A.remove(MA)
upper = statistics.median_high(A)
lower = statistics.median_low(A)

r1 = math.factorial(MA) // (math.factorial(MA-upper) * math.factorial(upper))
r2 = math.factorial(MA) // (math.factorial(MA-lower) * math.factorial(lower))

if upper == lower:
  print(MA, upper)
  exit()
  
if r1 > r2:
  print(MA, upper)
else:
  print(MA, lower)

Submission status: Time Limit Exceeded

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

def comb(a, b):
  s = 1
  for i in range(a, b, -1):
    s *= i
  return s/2
import math

MA = max(A)
ans = (0, 0)
AL = 0
for i in A:
  if i == MA:
    continue
  r = math.factorial(MA) // (math.factorial(MA-i) * math.factorial(i))
  if AL < r:
    AL = r
    ans = (MA, i)
    
print(ans[0], ans[1])

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc

N=int(input())
X=list(map(int,input().split()))
SX=sorted(X)
M=SX.pop()
MV=0
ANS=0
for x in SX:
  if (M - x) in SX:
    continue
  else:
    cb = scipy.misc.comb(M,x)
    if MV < cb:
      MV = cb
      ANS = x
print("{} {}".format(M,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())
X=list(map(int,input().split()))
SX=sorted(X)
M=SX.pop()
MV=0
ANS=0
for x in SX:
  if (M - x) in SX:
    continue
  else:
    cb = cmb(M,x)
    if MV < cb:
      MV = cb
      ANS = x
print("{} {}".format(M,ANS))

Submission status: Time Limit Exceeded

Solution code:
def comb(n, k):
    ret = 1
    for i in range(k):
        ret *= (n-i)
        ret //= (i+1)
    return ret

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

n, r = a[0], a[1]
t = -1
for aa in a[1:]:
    if comb(n, aa) >= t:
        r = aa
        t = comb(n, aa)

print(n, r)

Submission status: Time Limit Exceeded

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 = sorted(list(set(map(int, input().split()))))[::-1]
a, b = 0, 0
ans = 0
for i in range(n - 1):
    ai = alist[i]
    for j in range(i + 1, n):
        com = nCk(ai, alist[j])
        if com > ans:
            ans = com
            a, b = ai, alist[j]
print(a, b)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

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

n = int(input())
A = list(map(int, input().split()))
max_val = float('-inf')
max_comb = None
for c in itertools.combinations(A, 2):
    # print(c)
    if c[0] < c[1]:
        tmp = (c[1], c[0])
    else:
        tmp = c
    comb_val = comb(tmp[0], tmp[1])

    # print(comb_val)
    if max_val < comb_val:
        max_val = comb_val
        max_comb = tmp
print(*max_comb)

Submission status: Time Limit Exceeded

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

def comb(a, b):
  s = 1
  for i in range(a, b, -1):
    s *= i
  return s/2
import math

ans = (0, 0)
AL = 0
for i in A:
  for j in A:
    if i == j:
      continue
    if i < j:
      continue
    r = math.factorial(i) // (math.factorial(i-j) * math.factorial(j))
    if AL < r:
      AL = r
      ans = (i, j)
    
print(ans[0], ans[1])

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import bisect

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

lst = sorted(lst)

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

if n == 2:
    print(max(lst), min(lst))
else:
    num = max(lst)
    r1 = bisect.bisect_left(lst, num//2)
    r2 = bisect.bisect_right(lst, num//2)
    
    val1 = nCr(num, lst[r1])
    val2 = nCr(num, lst[r2])
    
    if val1 >= val2:
        ans = (max(num, lst[r1]), min(num, lst[r1]))
    else:
        ans = (max(num, lst[r2]), min(num, lst[r2]))
    
    print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
x = a.pop(-1)
kj = [1,1]
for i in range(2,x+1):
  kj.append(kj[-1]*i)
ans_val = []
ans_list = []
for i in a:
  ans_val.append(kj[x]/(kj[x-i]*kj[i]))
  ans_list.append(i)
print(x,ans_list[ans_val.index(max(ans_val))])

Submission status: Time Limit Exceeded

Solution code:
import math
from itertools import combinations
def comb(a,b):
    a2 = math.factorial(a)
    b2 = math.factorial(b)
    ab = math.factorial(a-b)
    return a2//(b2*ab)
N = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
ans = []
array = []
for x,y in combinations(a,2):
    ans.append(comb(x,y))
    array.append([x,y])
print(*array[ans.index(max(ans))])

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
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 = [int(i) for i in input().split()]
a.sort()
ans = [0, 0]
c = 0
for i in range(1, n):
    j = min(bisect_left(a, a[i]//2, 0, i), i-1)
    if a[i] <= a[j]:
        continue
    tmp = cmb(a[i], a[j])
    if tmp > c:
        ans[0], ans[1] = a[i], a[j]
        c = tmp
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from scipy.misc import comb
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = [0, 0]
c = 0
for i in range(1, n):
    j = min(bisect_left(a, a[i]//2, 0, i), i-1)
    if a[i] <= a[j]:
        continue
    tmp = comb(a[i], a[j])
    if tmp > c:
        ans[0], ans[1] = a[i], a[j]
        c = tmp
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=0
y=0
m=round(max(a)/2)
for i in range(m,max(a)):
    if a.count(i)>=1:
        x=i
        break
for j in reversed(range(0,m)):
    if a.count(j)>=1:
        y=j
        break

if abs(max(a)/2-x)<abs(max(a)/2-y):
    print(max(a),x)
else:
    print(max(a),y)

Submission status: Time Limit Exceeded

Solution code:
def comb(x,y):
    a=1
    b=1
    for i in range(1,y+1):
        a*=(x-i+1)
        b*=i
    return a//b

n=int(input())
a=list(map(int,input().split()))
x=0
y=0
m=round(max(a)/2)
for i in range(m,max(a)):
    if a.count(i)>=1:
        x=i
        break
for j in reversed(range(0,m)):
    if a.count(j)>=1:
        y=j
        break
if comb(max(a),x)>comb(max(a),y):
    print(max(a),x)
else:
	print(max(a),y)

Submission status: Time Limit Exceeded

Solution code:
def comb(x,y):
    a=1
    b=1
    for i in range(1,y+1):
        a*=(x-i+1)
        b*=i
    return a//b

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

ans=0
answer=0
for i in range(n):
    if ans<comb(max(a),a[i]) and max(a)!=a[i]:
        ans=comb(max(a),a[i])
        answer=a[i]
print(max(a),answer)