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 scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
a_i = a[0]
comb = 0
for i in range(1, n):
    c = scm.comb(a_i, a[i])
    if comb > c:
        comb = c
        a_j = a[i]
print(a_i, a_j)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
m = a[0]
ans = a[0]
if a[0]%2 == 0:
    b = a[0]//2
    for i in range(n):
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

else:
    b = a[0]//2 + 0.5
    for i in a:
        if m >= abs(b-a[i]):
            m = abs(b-a[i])
            ans = a[i]
    print(a[0], ans)

Submission status: Runtime Error

Solution code:
#coding:utf-8

def fact(n):
    x = 1
    for i in range(2, n + 1):
        x *= i
    return x

N = int(raw_input())

X = map(int, raw_input().split())

a = max(X)

#fact_list = [0 for i in range(a)]
#is_list = [False for i in range(a + 1)]

multi_flag = False
b = 0

min_num = 1000000000000

for i in X:
    if(i != a):
        tmp1 = fact(i)
        tmp2 = fact(a - i)

        if (min_num > tmp1*tmp2):
            b = i
            min_num = tmp1*tmp2
            #is_list[i] = True

print str(a) + " " + str(b)

Submission status: Runtime Error

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

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


# solve
# def comb(n, r):
#     if n < 0 or r < 0 or n < r:
#         return 0
#     elif n == 0 or r == 0:
#         return 1
#     return comb(n-1, r-1) + comb(n-1, r)

def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r


A = sorted(A)[::-1]
max_num = 0
for i in range(len(A)-1):
    for j in range(i+1, len(A), 1):
        if (max_num <= comb(A[i], A[j])):
            max_num = comb(A[i], A[j])
            pair = []
            pair.append(A[i])
            pair.append(A[j])

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

Submission status: Runtime Error

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

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


# solve
# def comb(n, r):
#     if n < 0 or r < 0 or n < r:
#         return 0
#     elif n == 0 or r == 0:
#         return 1
#     return comb(n-1, r-1) + comb(n-1, r)

def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r


A = sorted(A)[::-1]
max_num = 0
for i in range(len(A)-1):
    for j in range(i+1, len(A), 1):
        if (max_num < comb(A[i], A[j])):
            max_num = comb(A[i], A[j])
            pair = []
            pair.append(A[i])
            pair.append(A[j])

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

Submission status: Runtime Error

Solution code:
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - maxl/2)**2
com = Xed[np.where(np.min(Xed))]
print(X)
print(Xed)
print(com)
print(maxl,Xed[com[0]])

Submission status: Runtime Error

Solution code:
import math
n = int(input())
alist = list(map(int, input().split()))

asort = sorted(alist)

output_a_i = alist[0]
output_a_j = alist[1]
combmax = -1.0
for i in range(1, n):
  candlist = asort[:i]
  ncand = len(candlist)
  a_i = asort[i]
  if ncand == 1:
    a_j = candlist[0]
  else:
    a_j = candlist[int(ncand/2)] if (a_i - candlist[int(ncand/2)] < a_i - candlist[int(ncand/2) - 1]) else candlist[int(ncand/2) - 1]
  	
    comb = math.factorial(a_i) / math.factorial(a_j) / math.factorial(a_i-a_j)
    if comb > combmax:
      combmax = comb
      output_a_i = a_i
      output_a_j = a_j

print(output_a_i, output_a_j)

Submission status: Runtime Error

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

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


# solve
# def comb(n, r):
#     if n < 0 or r < 0 or n < r:
#         return 0
#     elif n == 0 or r == 0:
#         return 1
#     return comb(n-1, r-1) + comb(n-1, r)

def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r


A = sorted(A)[::-1]
max_num = 0
pair = []
for i in range(len(A)-1):
    for j in range(i, len(A), 1):
        if (i == j):
            continue
        if (max_num < comb(A[i], A[j])):
            max_num = comb(A[i], A[j])
            pair = []
            pair.append(A[i])
            pair.append(A[j])

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

Submission status: Runtime Error

Solution code:
import itertools


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

if n == 2:
    print(max(a), min(a))
else:
    a = list(set(a))
    num = 0
    for x in itertools.combinations(a, 2):
        if num < len(list(itertools.combinations(range(max(x)), min(x)))):
            num = len(list(itertools.combinations(range(max(x)), min(x))))
            x1 = max(x)
            x2 = min(x)
    print(x1, x2)

Submission status: Runtime Error

Solution code:
from math import factorial
from itertools import permutations
n = int(input())
a = list(map(int, input().split()))
result = [[n, r, factorial(n) / factorial(r) / factorial(n-r)] for n, r in permutations(a, 2) if n >= r]
print(*sorted(result, key=lambda x: x[2], reverse=True)[0][0:2])

Submission status: Runtime Error

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

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


# solve
def comb(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    elif n == 0 or r == 0:
        return 1
    return comb(n-1, r-1) + comb(n-1, r)


A = sorted(A)[::-1]
max_num = 0
pair = []
for i in range(len(A)-1):
    for j in range(i, len(A), 1):
        if (i == j):
            continue
        if (max_num < comb(A[i], A[j])):
            max_num = comb(A[i], A[j])
            pair = []
            pair.append(A[i])
            pair.append(A[j])

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

Submission status: Runtime Error

Solution code:
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if scm.comb(a[i], int(a[i]/2)) <= comb:
        break
    else:
        r_list = a[i+1:]
        for r in r_list:
            c = scm.comb(a[i], r)
            if tmp_c < c:
                tmp_c = c
                tmp_r = r
        if tmp_c > comb:
            a_i = a[i]
            a_j = tmp_r
            comb = tmp_c
print(a_i, a_j)

Submission status: Runtime Error

Solution code:
# mondai D

N = int(input())
A = list(map(int, input().split(" ")))
Ad = A[:]
ai = 0
aj = 0
ans = 0

def comb(n,r):
    ans = 1
    for i in range(n+1-r,n+1):
        ans *= i
    for i in range(r):
        ans /= (i+1)

    return ans

for index, i in enumerate(A):
    for j in A[index+1:]:
        if i != j:
            if i > j:
                if ans < comb(i,j):
                    ans = comb(i,j)
                    ai = i
                    aj = j
            else:
                if ans < comb(j,i):
                    ans = comb(j,i)
                    ai = j
                    aj = i

print("{} {}".format(ai, aj))

Submission status: Runtime Error

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

# input
N = int(input())
A = list(map(int, input().split()))
# N = 5
# A = [6, 9, 4, 2, 11]


# solve
def comb(n,r):
    if n < 0 or r < 0 or n < r:
        return 0
    elif n == 0 or r == 0:
        return 1
    return comb(n-1,r-1)+comb(n-1,r)


A = sorted(A)[::-1]
max_num = 0
pair = []
for i in range(len(A)-1):
    for j in range(i, len(A), 1):
        if (i == j):
            continue
        if (max_num < comb(A[i], A[j])):
            max_num = comb(A[i], A[j])
            pair = []
            pair.append(A[i])
            pair.append(A[j])

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

Submission status: Runtime Error

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


temp=0
z=0
for i in range(int((n+1)/2)):
    for j in range(i+1,n):
        temp=comb(a[i],a[j])
        if z<temp:
            z=temp
            x,y=a[i],a[j]

def comb(m, r):
    if m-r<r:
        k=m-r
    else:
        k=r
    x=1
    for i in range(m,m-k,-1):
        x*=i
    for j in range(1,k+1):
        x/=j
    return int(x)
print(x, y)

Submission status: Runtime Error

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


temp=0
z=0
for i in range((n+1)//2):
    for j in range(i+1,n):
        temp=comb(a[i],a[j])
        if z<temp:
            z=temp
            x,y=a[i],a[j]

def comb(m, r):
    if m-r<r:
        k=m-r
    else:
        k=r
    x=1
    for i in range(m,m-k,-1):
        x*=i
    for j in range(1,k+1):
        x/=j
    return int(x)
print(x, y)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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

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

if A[-1]%2==0:
    T = Ai//2
    k = bisect_left(A[:-1], T)
    if k==N-1:
        k -= 1
        ans = (Ai, A[k])
else:
    T = Ai//2
    k = bisect_left(A[:-1], T)
    if k==N-1:
        k -= 1

    T += 1
    k2 = bisect_left(A[:-1], T)
    if k2==N-1:
        k2 -= 1

    if abs(A[k]-(T-1))<abs(A[k2]-T):
        ans = (Ai, A[k])
    else:
        ans = (Ai, A[k2])

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

Submission status: Runtime Error

Solution code:
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - maxl/2)**2
com = X[np.where(np.min(Xed))]
print(X)
print(Xed)
print(com)
print(maxl,X[com[0]])

Submission status: Runtime Error

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

for i in range(n):
    #2/a[i]に最も近いものを探す
    net = 0
    ans = 0
    res = 10000
    for j in range(i):
        if abs((a[i]/2)-a[j])< res:
            ans = j
            res = abs((a[i]/2)-a[j])

    d = math.factorial(a[i])/math.factorial(a[ans])
    d = d/math.factorial(a[i]-a[ans])
    if d > net:
        final = [a[i],a[ans]]
        net = d

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

Submission status: Runtime Error

Solution code:
def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r 


N = int(input())
X = [int(d) for d in input().split()]

max_ = 0
comb_ = []

X.sort(reverse=True)
for i,v in enumerate(X):
	for h in range(1,len(X)-i):
		#print(v,X[i+h])
		comb_value = comb1(v,X[i+h])
		if max_<comb_value:
			max_ = comb_value
			comb_ = [v,X[i+h]]


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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
n = max(a)
maxcomb = -1
maxr = -1
for r in a:
    tmp = 1
    for i in range(n, n-r, -1):
        tmp *= i
    for j in range(1, r+1):
        tmp /= j
    if maxcomb < tmp:
        maxcomb = tmp
        maxr = r

print(n, maxr)

Submission status: Runtime Error

Solution code:
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - int(maxl/2))**2
com = X[np.where(np.min(Xed))]
print(maxl,X[com[0]])

Submission status: Runtime Error

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


temp=0
z=0
for i in range((n+1)//2):
    for j in range(i+1,n):
        temp=comb(a[i],a[j])
        if z<temp:
            z=temp
            x,y=a[i],a[j]

def comb(m, r):
    if m-r<r:
        k=m-r
    else:
        k=r
    x=1
    for i in range(m,m-k,-1):
        x*=i
    for j in range(1,k+1):
        x//=j
    return x
print(x, y)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    max_num = max(a)
    dif = 99999.
    for num in a:
        if(num != max_num and dif > abs((max_num/2) - num)):
            dif = abs((max_num/2) - num)
            ansnum = num
            
    print("{} {}".format(max_num, ansnum))
        
if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r

    @lru_cache(None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        buf_val1 = ele[0]
        buf_val2 = ele[1]
        if ele[1] > ele[0]:
            buf_val1 = ele[1]
            buf_val2 = ele[0]
#        print(buf_val1, buf_val2)
        val = comb2(buf_val1, buf_val2)
        if val >= max:
            max = val
            comb_val1 = buf_val1
            comb_val2 = buf_val2
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[n-1]
a.remove(max_a)
result = bisect.bisect_left(a, max_a // 2)
print(max_a, a[result])

Submission status: Runtime Error

Solution code:
from itertools import combinations
n = int(input())
a = list(map(int, input().split()))
ans = -1
ansi = -1
ansj = -1
for i, j in combinations(a, 2):
    if i > j:
        pass
    else:
        tmp = i
        i = j
        j = tmp
    tmp = 1
    for x in range(i, i-j, -1):
        tmp *= x
    for x in range(1,j+1):
        tmp /= x
    if tmp > ans:
        ans = tmp
        ansi = i
        ansj = j
print(ansi, ansj)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(1000000)

max_comb = None
max_value = 0


def memorize(c, value, memo, a):
    global max_comb
    global max_value

    memo[c] = value

    # for answer
    if c[0] != c[1] and \
            c[0] in a and \
            c[1] in a and \
            max_value < memo[c]:
        max_value = memo[c]
        max_comb = c


def comb(a_i, a_j, memo, a):
    c = (a_i, a_j)
    # print(a_i, a_j)

    if c in memo:
        return memo[c]

    if a_j == 1:
        memorize(c, a_i, memo, a)
        return a_i

    if a_i == a_j or a_j == 0:
        memorize(c, 1, memo, a)
        return 1

    value = comb(a_i - 1, a_j, memo, a) + comb(a_i - 1, a_j - 1, memo, a)
    memorize(c, value, memo, a)
    return memo[c]


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

    # n = 5
    # a = [6, 9, 4, 2, 11]

    # find 1st, 2nd
    # max_a, second_max_a = -1, -2
    # for a_i in a:
    #     if max_a < a_i:
    #         second_max_a = max_a
    #         max_a = a_i
    #     elif second_max_a < a_i:
    #         second_max_a = a_i

    max_a = max(a)
    memo = dict()

    for a_i in a:
        if max_a != a_i:
            comb(max_a, a_i, memo, a)
            # comb(max_a, second_max_a, memo, a)
    #
    # for i in range(n - 1):
    #     for j in range(i + 1, n):
    #         comb(a_sorted[i], a_sorted[j], memo, a)
    #
    #         # print("comb:", a_sorted[i], a_sorted[j])

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

Submission status: Runtime Error

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

nb=0
b=0
def comb(n, r):
    if n == 0 or r == 0: 
        return 1
    return comb(n, r-1) * (n-r+1) / r
mn=max(a)
for i in a:
    if comb(mn,i) >b:
        b=comb(mn,i)
        nb=i
print(max(a),nb)

Submission status: Runtime Error

Solution code:
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = sorted(X)
maxl = np.max(X)
com = X[np.where(np.min(X-int(maxl/2)))]
 
print(maxl,com[0])

Submission status: Runtime Error

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

nb=0
b=0
def comb(n, r):
    if n == 0 or r == 0: 
        return 1
    return comb(n, r-1) * (n-r+1) / r
mn=max(a)
for i in a:
    if comb(mn,i) >b:
        b=comb(mn,i)
        nb=i
print(max(a),nb)

Submission status: Runtime Error

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

nb=0
b=0
def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) // r
mn=max(a)
for i in a:
    if comb(mn,i) >b:
        b=comb(mn,i)
        nb=i
print(max(a),nb)

Submission status: Runtime Error

Solution code:
from math import factorial
from bisect import bisect_left

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

A.sort()

comb = lambda n,r: factorial(n)/(factorial(r)*factorial(n-r))

#for i in range(9):
#    print(8,i,comb(8,i))
#
#exit()

maxsofar = 0
for i in range(1, N):
    Ai = A[i]
    if Ai%2==0:
        j = Ai//2
        k = bisect_left(A[:i], j)
        if k==i:
            k -= 1
        c = comb(Ai, A[k])
        if maxsofar<c:
            ans = (Ai, A[k])
        #print(j, (Ai, A[k]), c)

        if A[k]!=j and k+1<i:
            k += 1
            c = comb(Ai, A[k])
            if maxsofar<c:
                ans = (Ai, A[k])
            #print(Ai, A[k], comb(Ai, A[k]))
    else:
        j = Ai//2
        k = bisect_left(A[:i], j)
        if k==i:
            k -= 1
        c = comb(Ai, A[k])
        if maxsofar<c:
            ans = (Ai, A[k])
        #print(j, (Ai, A[k]), comb(Ai, A[k]))
        j = Ai//2 + 1
        k = bisect_left(A[:i], j)
        if k==i:
            k -= 1
        c = comb(Ai, A[k])
        if maxsofar<c:
            ans = (Ai, A[k])
        #print(j, (Ai, A[k]), comb(Ai, A[k]))

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

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    max_num = max(a)
    dif = 99999
    for num in a:
        if(num != max_num and dif > abs((max_num/2) - num)):
            dif = abs((max_num/2) - num)
            ansnum = num
            
    print("{} {}".format(max_num, ansnum))
        
if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if a[i] % 2 == 0:
        max_r = int(a[i]/2)
        if max_r in a:
            c = scm.comb(a[i], max_r)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r
                comb = c
        else:
            r_list = a[i+1:]
            tmp_c = -1
            for r in r_list:
                c = scm.comb(a[i], r)
                if tmp_c < c:
                    tmp_c = c
                    tmp_r = r
                else:
                    break
            if c > comb:
                a_i = a[i]
                a_j = tmp_r
                comb = c
            else:
                break
    else:
        max_r1 = int(a[i]/2)
        max_r2 = int(a[i]/2)+1
        if max_r1 in a:
            c = scm.comb(a[i], max_r1)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r1
        elif max_r2 in a:
            c = scm.comb(a[i], max_r2)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r2
                comb = tmp_c
        else:
            r_list = a[i+1:]
            tmp_c = -1
            for r in r_list:
                c = scm.comb(a[i], r)
                if tmp_c < c:
                    tmp_c = c
                    tmp_r = r
                else:
                    break
            if c > comb:
                a_i = a[i]
                a_j = tmp_r
                comb = tmp_c
            else:
                break
print(a_i, a_j)

Submission status: Runtime Error

Solution code:
import sys
import itertools
from functools import lru_cache
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))

#    def comb1(n, r):
#        if n == 0 or r == 0: return 1
#        return comb1(n, r - 1) * (n - r + 1) / r

    @lru_cache(None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n - 1, r - 1) + comb2(n - 1, r)

    max = 0
    comb_val1 = 0
    comb_val2 = 0
    for ele in itertools.combinations(A, 2):
        val = comb2(ele[1], ele[0])
        if val >= max:
            max = val
            if ele[1] > ele[0]:
                comb_val1 = ele[1]
                comb_val2 = ele[0]
            else:
                comb_val1 = ele[0]
                comb_val2 = ele[1]
#    print(max)
    print(str(comb_val1) + ' ' + str(comb_val2))

Submission status: Runtime Error

Solution code:
def fact(n):
    if n==0:
        return 1
    return n*fact(n-1)
ans=0    
N=int(input())
s=list(map(int,input().split()))
t=max(s)
for i in s:
    c=fact(t)/(fact(i)*fact(t-i))
    if ans<c and t!=i:
        ans=c
        an=i
print(str(t)+" "+str(an))

Submission status: Runtime Error

Solution code:
def comb(a, b):
    ans, x, y = 0, a, b
    for i in range(1, b):
        x *= a-i
        y *= b-i
    ans = int(x/y)
    return ans
    
n= int(input())
a = [int(i) for i in input().split()]
m = max(a)

t = 0
t2 = 0
b = a[:]
b.remove(m)
for j in b:
    if j == 0:
        continue
    t3 = comb(m, j)
    if t < t3:
        t = t3
        t2 = j
print(str(m)+" "+str(t2))

Submission status: Runtime Error

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

nb=0
b=0
def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r
mn=max(a)
for i in a:
    if i==0:
        continue
    if comb(mn,i) >b:
        b=comb(mn,i)
        nb=i
print(max(a),nb)

Submission status: Runtime Error

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

nb=0
b=0
def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r
mn=max(a)
for i in a:
    if comb(mn,i) >b:
        b=comb(mn,i)
        nb=i
print(max(a),nb)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

    A.sort()
    n = A[-1]
    maxc = 0
    for r in A[:-1]:
        cmb = comb(n, r)
        if maxc < cmb:
            ans = r
            maxc = cmb
    print(n, ans)

main()

Submission status: Runtime Error

Solution code:
from itertools import *
from bisect import *
from operator import *

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

a_item = sorted(a)
a_max = a_item[-1]
a_item = a_item[:-1]
bisect_l_item = bisect_left(a_item, a_max//2)
#import pdb; pdb.set_trace()
bisect_r = a_item[bisect_l_item - 1]
if bisect_l_item < n - 1:
    bisect_l = a_item[bisect_l_item]
else:
    bisect_l = bisect_r
#print(bisect_l_item, bisect_l, bisect_r)
idea_l = len(list(combinations(range(a_max), bisect_l)))
idea_r = len(list(combinations(range(a_max), bisect_r)))

if idea_l >= idea_r:
    print(a_max, bisect_l)
else:
    print(a_max, bisect_r)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
Ad = A[:]
ai = 0
aj = 0
ans = 0

def comb(n,r):
    ans = 1
    for i in range(n+1-r,n+1):
        ans *= i
    for i in range(r):
        ans /= (i+1)

    return ans

for i in A:
    for j in Ad:
        if i != j:
            if i > j:
                if ans < comb(i,j):
                    ans = comb(i,j)
                    ai = i
                    aj = j
            else:
                if ans < comb(j,i):
                    ans = comb(j,i)
                    ai = j
                    aj = i

print("{} {}".format(ai, aj))

Submission status: Runtime Error

Solution code:
from itertools import *
from bisect import *
from operator import *

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

a_item = sorted(a)
a_max = a_item[-1]
#a_item = a_item[:-1]
bisect_l_item = bisect_left(a_item, a_max//2)
#import pdb; pdb.set_trace()
bisect_l = a_item[bisect_l_item]
bisect_r = a_item[bisect_l_item - 1]
#print(bisect_l_item, bisect_l, bisect_r)
idea_l = len(list(combinations(range(a_max), bisect_l)))
idea_r = len(list(combinations(range(a_max), bisect_r)))

if idea_l >= idea_r:
    print(a_max, bisect_l)
else:
    print(a_max, bisect_r)

Submission status: Runtime Error

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

N = int(input())
a = tuple(map(int, input().split()))

n = max(a)
M = 0
for x in a:
    if x == n:
        continue
    res = comb(n, x)
    if M < res:
        M = res
        r = x

print(n, r)

Submission status: Runtime Error

Solution code:
import itertools

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

nb=0
b=0
rl=range(max(a))
for i in a:
    if len(list(itertools.combinations(rl,i))) >b:
        b=len(list(itertools.combinations(rl,i)))
        nb=i
print(max(a),nb)

Submission status: Runtime Error

Solution code:
def fact(n):
    if n==0:
        return 1
    return n*fact(n-1)
ans=0    
N=int(input())
s=list(map(int,input().split()))
t=max(s)
for i in s:
    c=fact(t)/(fact(i)*fact(t-i))
    if ans<c and c!=i:
        ans=c
        an=i
print(str(t)+" "+str(an))        
print(fact(0))

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(100000 + 2)

max_comb = None
max_value = 0


def memorize(c, value, memo):
    global max_comb
    global max_value

    memo[c] = value
    if max_value < memo[c]:
        max_value = memo[c]
        max_comb = c


def comb(a_i, a_j, memo):
    c = (a_i, a_j)
    # print(a_i, a_j)

    if c in memo:
        return memo[c]

    if a_j == 1:
        memorize(c, a_i, memo)
        return a_i

    if a_i == a_j or a_j == 0:
        memorize(c, 1, memo)
        return 1

    value = comb(a_i - 1, a_j, memo) + comb(a_i - 1, a_j - 1, memo)
    memorize(c, value, memo)
    return memo[c]


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

    # n = 5
    # a = [6, 9, 4, 2, 11]
    a_sorted = sorted(a, reverse=True)

    memo = dict()
    for i in range(n - 1):
        for j in range(i + 1, n):
            comb(a_sorted[i], a_sorted[j], memo)

            # print("comb:", a_sorted[i], a_sorted[j])

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

Submission status: Runtime Error

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

N = int(input())
a = tuple(map(int, input().split()))

Max = 0
for i in range(0, N):
    for j in range(i + 1, N):
        M = max(a[i], a[j])
        m = min(a[i], a[j])
        res = comb(M, m)
        if Max < res:
            Max = res;
            n = M
            r = m

print(n, r)

Submission status: Runtime Error

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

n = 5
a = [6, 9, 4, 2, 11]

n = max(a)
a.remove(n)
res = 0
for k in a:
    buf = (math.factorial(n) / (math.factorial(k) * math.factorial(n-k)))
    if buf < res:
        res = buf

print(n, res)

Submission status: Runtime Error

Solution code:
def fact(n):
    if n==0:
        return 1
    return n*fact(n-1)
ans=0    
N=int(input())
s=list(map(int,input().split()))
t=max(s)
for i in s:
    c=fact(t)/(fact(i)*fact(t-i))
    if ans<c:
        ans=c
        an=i
print(str(t)+" "+str(an))

Submission status: Runtime Error

Solution code:
import math
n int(input())
a = input().split(' ')
a = [int(aa) for aa in a]

n = max(a)
a.remove(n)
res = []
for k in a:
    res.append(math.factorial(n) / (math.factorial(k) * math.factorial(n-k)))

mm = max(res)
print(n, [a[i] for i in range(len(res)) if res[i] == mm][0])

Submission status: Runtime Error

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

k=(enu)/2
sa=100000

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

print(enu,aru)

Submission status: Runtime Error

Solution code:
from math import factorial

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

A.sort()

comb = lambda n,r: factorial(n)/(factorial(r)*factorial(n-r))

tmp = 0
for i in range(1, N):
    Ai = A[i]
    if i%2==1:
        j = (i-1)//2
        c = comb(Ai, A[j])
        if tmp<c:
            tmp = c
            ans = (Ai, A[j])
    else:
        j = i//2
        c = comb(Ai, A[j])
        if tmp<c:
            tmp = c
            ans = (Ai, A[j])
        j = i//2 - 1
        c = comb(Ai, A[j])
        if tmp<c:
            tmp = c
            ans = (Ai, A[j])


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

Submission status: Runtime Error

Solution code:
import re
import doctest
from itertools import combinations


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(3)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    buf = IO_for_Contest.read_from_input()
    n = buf[0]
    a = IO_for_Contest.read_n_int(n)
    b = sorted(a, key=lambda x: -x)

    maximum = 0
    x, y = 0, 0
    for w in combinations(b, 2):
        temp = len(list(combinations(list(range(w[0])), w[1])))
        if maximum < temp:
            maximum = temp
            x, y = w[0], w[1]
    print('{0:d} {1:d}'.format(x, y))


if __name__ == '__main__':
    # doctest.testmod()
    solve()