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:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

res = 0
big = 0
small = 0

for i in range(n-1):
    if a[i:][0] <= a[i] / 2:
        t = a[i:][0]
        comb = 1
        for k in range(t, a[i]+1):
            comb *= k
        for k in range(1, a[i]-t+2):
            comb /= k
        if comb >= res:
            res = comb
            big = a[i]
            small = t
    elif a[-1] >= a[i] / 2:
        t = a[-1]
        comb = 1
        for k in range(t, a[i]+1):
            comb *= k
        for k in range(1, a[i]-t+2):
            comb /= k
        if comb >= res:
            res = comb
            big = a[i]
            small = t
    else:
        left = i+1
        right = n-1
        while True:
            j = (left + right) // 2
            if n == 2:
                t = a[1]
                break
            elif left == right:
                t = a[left]
                break
            elif a[i]/2 >= a[j+1] and a[i]/2 <= a[j]:
                if abs(a[j+1]-a[i]/2) >= abs(a[j]-a[i]/2):
                    t = a[j]
                else:
                    t = a[j+1]
                break
            elif a[i]/2 > a[j]:
                right = j
            else:
                left = j

        comb = 1
        for k in range(t, a[i]+1):
            comb *= k
        for k in range(1, a[i]-t+2):
            comb /= k
        if comb >= res:
            res = comb
            big = a[i]
            small = t

print(big, small)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
mm = a.pop()
ind = bisect.bisect_left(a,mm/2)
print(mm,a[ind])

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
A = list(map(int, input().split()))
a = np.array(A)
amax = a[np.argmax(a)]
a[np.argmax(a)] = 0
print(amax, a[np.abs(a-amax//2).argmin()])

Submission status: Runtime Error

Solution code:
import numpy as np

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

print(a[np.argmax(a)], a[np.abs(a-imax//2).argmin()])

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;cin>>n;
    set<int> a;
    for(int i=0,p;i<n;i++){
        cin>>p;
        a.insert(p);
    }
    int p,q;
    set<int>::iterator itr;
    itr=a.end();
    itr--;
    p=*itr;

    a.erase(p);
    float x=p*0.5,dif=100000000;

    itr=a.begin();
    while(itr!=a.end()){
        if(dif>abs(*itr-x)){
            dif=abs(*itr-x);
            q=*itr;
        }
        itr++;
    }

    cout<<p<<" "<<q<<endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0

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

for i in range(1,N):
    for j in range(0,i):
        if ans < combination(a[i], a[j]):
            ans = combination(a[i], a[j])
            n = a[i]
            r = a[j]
print(n, r)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
temp = 0
for j, i in enumerate(a):
    k = bisect.bisect_left(a[:j], (i / 2) + 1) - 1
    if (i - a[k]) > 0:
        if math.factorial(i) // (math.factorial(a[k]) * (math.factorial(i - a[k]))) > temp:
            ans = [i, a[k]]
print(*ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

large =0
inum = 0
jmum = 0
for i in range(n-1):
   for j in range(n-i):
      a = comb(sornum[i],sornum[i+j])
      if a>=large:
         large = a
         inum = sornum[i]
         jnum =sornum[i+j]


print(inum,jnum)

Submission status: Runtime Error

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

def cmb(n, r):
    nCr = {}
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if n%2==1:
    print(a[-1],a[k])
elif n==2:
    print(a[1],a[0])
else:
    if cmb(a[-1],a[k])>cmb(a[-1],a[k+1]):
        print(a[-1],a[k])
    else:
        print(a[-1],a[k+1])

Submission status: Runtime Error

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest -> bisect
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    cand = [abs(A[i] - n / 2), A[i] for i in (idx - 1, idx, idx + 1)]
    r = min(cand)[1]
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())

a = sorted(list(map(int, input())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
from scipy.misc import perm
from scipy.misc import comb
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########
n = i_inpl()
a = l_inpl()
max_v = max(a)/2

an = INF
for ai in a:
    if abs(an-max_v) > abs(ai-max_v):
        an = ai
# print(an)
print(max(a), an)

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb
from scipy.special import perm
from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########
n = i_inpl()
a = l_inpl()
max_v = max(a)/2

an = INF
for ai in a:
    if abs(an-max_v) > abs(ai-max_v):
        an = ai
# print(an)
print(max(a), an)

Submission status: Runtime Error

Solution code:

n = int(input())
num_list = sorted([ int(v) for v in input().split() ])

x = num_list[-1]
x_half = x / 2
y = bisect.bisect_left(num_list,x_half)
if y != 0:
    if y == n-1:
        y -= 1
    else:
        if abs(num_list[y] - x_half) >= abs(num_list[y-1] - x_half):
            y -= 1
print(x,num_list[y])

Submission status: Runtime Error

Solution code:
import math
import sys


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

    max_comb = - sys.maxsize
    answer1 = -1
    answer2 = -1
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if a_list[i] < a_list[j]:
                continue
            comb = math.factorial(a_list[i])/(math.factorial(a_list[j]) * math.factorial(a_list[i] - a_list[j]))

            if max_comb < comb:
                max_comb = comb
                answer1 = a_list[i]
                answer2 = a_list[j]

    print(str(answer1) + " " + str(answer2))

Submission status: Runtime Error

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

comb1 = max(a)
comb2 = comb1//2
a.sort()
p = 0
keep = float("inf")
for i in range(n):
    if abs(a[i] - comb2) <= keep:
        p = a[i]
        keep = abs(a[i]-comb2)

def factorial(i):
    if i == 0:
        return 1
    else:
        return factorial(i-1)*i
ans = factorial(comb1)//((factorial(p))*(factorial(comb1-p)))
if comb1 == p:
    print(comb1,0)
else:
    print(comb1,p)

Submission status: Runtime Error

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

a = sorted(a)

import numpy as np
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
  
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
  
ans = 0
for i in range(1,n):
    tmp0 = a[i] / 2
    tmp1 = getNearestValue(a[0:i], check)
    tmp2 = cmb(a[i], tmp1)
    if tmp2 > ans:
        ans = tmp2
        ans1 = a[i]
        ans2 = tmp1
print(ans1, ans2)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
A.pop(N-1)
ans = 0
ans_a = 0
for a in A:
    tmp = comb(max_a, a, exact=True)
    if tmp > ans:
        ans = tmp
        ans_a = a
print(max_a, ans_a)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
A.pop(N-1)
ans = 0
ans_a = 0
for a in A:
    tmp = comb(max_a, a)
    if tmp > ans:
        ans = tmp
        ans_a = a
print(max_a, ans_a)

Submission status: Runtime Error

Solution code:
from itertools import combinations
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
A.pop(N-1)
ans = 0
ans_a = 0
for a in A:
    tmp = len(list(combinations(range(max_a), a)))
    if tmp > ans:
        ans = tmp
        ans_a = a
print(max_a, ans_a)

Submission status: Runtime Error

Solution code:
from itertools import combinations
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
A.pop(N-1)
ans = 0
for a in A:
    tmp = len(list(combinations(range(max_a), a)))
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
aj = max(A)
temp = 100000
for a in A:
    if a != aj:
        if temp > abs(int(aj/2+0.5)-a):
            ai = a
            temp = abs(int(aj/2+0.5)-a)
            
print(aj,ai)

Submission status: Runtime Error

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

max_comb = -1
for i in range(N):
    if max_comb > scipy.misc.comb(lst[i], lst[i]//2, exact=1):
        break
    k = lst[i]
    mid = k/2
    high = i
    low = N-1
    dif = abs(mid - lst[low])
    #print(mid)
    while abs(high - low) > 1:
        if dif > abs(mid - lst[(high+low)//2]):
            dif = abs(mid - lst[(high+low)//2])
            low = (high+low)//2
        else:
            high = (high+low)//2
        #print(high, low)
    p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
    comb = scipy.misc.comb(k, p, exact=1)
    if max_comb < comb:
        ans = (k, p)
        #print(ans, comb)
        max_comb = comb

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**5
for i in range(1,n):
    if k>abs(a[0]//2-a[i]):
        k=abs(a[0]//2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**5
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
import bisect
import math
def combinations_count(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ret = 0
for i in range(10):
    k = bisect.bisect_left(a_,a[i]//2)
    if a[i]//2-a_[k]>a_[k+1]-a[i]//2:
        k += 1
    cmb = combinations_count(a[i],a_[k])
    if ret<cmb:
        ans = [a[i],a_[k]]
        ret = cmb
print(ans[0],ans[1])

Submission status: Runtime Error

Solution code:
input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))

Submission status: Runtime Error

Solution code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_left(lst,n/2)
if n/2 - lst[m] <= lst[m+1] -n/2:
  print(n,lst[m])
else:
  print(n,lst[m+1])

Submission status: Runtime Error

Solution code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
m=bs.bisect_left(lst,n/2)
print(m)

if n/2 - lst[m] <= lst[m+1] -n/2:
  print(n,lst[m])
else:
  print(n,lst[m+1])

Submission status: Runtime Error

Solution code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
m=bs.bisect_left(lst,n)
if n/2 - lst[m] <= lst[m+1] -n/2:
  print(n,lst[m])
else:
  print(n,lst[m+1])

Submission status: Runtime Error

Solution code:
a = int(input())
N= map(int, input().split())
x = list(map(int, input().split()))
m = max(x)
M = m/2
s = float("INF")
for i in x:
    s = min(s,abs(M-i))
print(m,s)

Submission status: Runtime Error

Solution code:
import fileinput

factorials = [0, 1]


def factorial(n):
    global factorials
    if n < len(factorials):
        r = factorials[n]
    else:
        r = n * factorial(n-1)
        factorials.append(r)
    return r


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


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = sa[n-1]
    for i in range(1, n-2):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
import fileinput


def ncr(n, r):
    if r > n:
        result = 0
    elif 1 <= r <= n-1:
        result = ncr(n-1, r-1) + ncr(n-1, r)
    else:
        result = 1
    return result


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = 0
    for i in range(1, n-2):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
import fileinput


def ncr(n, r):
    if r > n:
        result = 0
    elif 1 <= r <= n-1:
        result = ncr(n-1, r-1) + ncr(n-1, r)
    else:
        result = 1
    return result


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = 0
    for i in range(1, len(sa)-1):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
N = int(input())
a = tuple(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a:
 if n = i: continue
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Submission status: Runtime Error

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

def binary_search(l, value):
    low = 0
    high = len(l)-1
    while low <= high:
        mid = (low + high)//2
        if l[mid] == value:
            print(m, l[mid])
            exit()
        elif l[mid] < value:
            low = mid + 1
        else:
            high = mid - 1
    return low

k = binary_search(a, m//2)
print(m, a[k])

Submission status: Runtime Error

Solution code:
from math import factorial
N = int(input())
A = sorted(list(map(int, input().split())))
ret = []

pos = 1
maxn = 0
for i, a in enumerate(A):
    if a == 0:
        maxn = 1
        ans = (a, A[pos])
        continue
    minn = [abs(A[pos] / a - 2), (a, A[pos])]
    while pos < N:
        if minn[0] < abs(A[pos] / a - 2):
            break
        minn[0] = abs(A[pos] / a - 2)
        pos += 1
    if maxn < factorial(minn[1][1]) / factorial(minn[1][0]):
        maxn = factorial(minn[1][1]) / factorial(minn[1][0])
        ans = minn[1]
    if i == pos:
        pos += 1
    if pos >= N:
        break
print(ans[1], ans[0])

Submission status: Runtime Error

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

sa = sorted(A)
import math
from bisect import *
hv = sa[-1] / 2
hl, hr = math.floor(hv), math.ceil(hv)
ri = bisect_right(sa, hv)

import operator
import functools
def dist(x):
    if x <= hl:
        return functools.reduce(operator.imul, range(hl, x, -1)) / functools.reduce(operator.imul, range(hr, hr + (hl - x) + 1))
    else:
        return functools.reduce(operator.imul, range(hr, hr + (x - hr) + 1)) / functools.reduce(operator.imul, range(x, hl, -1))

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if dist(sa[ri - 1]) > dist(sa[ri]) else sa[ri])

Submission status: Runtime Error

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

t = max(a)
b = []

for i in range(n):
  u = abs(n / 2 - a[i])
  b.append(u)

v = a[u.index(min(b))]
print(t, v)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
d=0
e=0
for i in [n//2-1,n//2]:
    c=1
    A=a[i]
    for j in range(i+1)[A:i+1]:
        c*=j
    for k in range(1,A+1):
        c/=k
    if d < c:
        d=c
        e=A
print(b,e)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
d=0
for i in [n//2-1,n//2]:
    c=1
    A=a[i]
    for j in range(i+1)[A:i+1]:
        c*=j
    for k in range(1,A+1):
        c/=k
    if d < c:
        d=c
print(b,d)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
d=0
for i in b:
    c=1
    A=a[i]
    for j in range(i+1)[A:i+1]:
        c*=j
    for k in range(1,A+1):
        c/=k
    if d < c:
        d=c
print(b,d)

Submission status: Runtime Error

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

t = 7+10*9
if M%2 == 0:
    m = M//2
    p = 0
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
    print(M,A[p])
else:
    m = M//2
    l = 1 + M//2
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
        elif abs(l-A[k]) < t:
            t = abs(l-A[k])
            p = k
    print(M,A[p])

Submission status: Runtime Error

Solution code:
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)

Submission status: Runtime Error

Solution code:
# 再帰制限に引っかかった場合に外す
import sys
sys.setrecursionlimit(1000000)

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

def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if n == 2:
    print("{0} {1}" .format(N, min(a)))
else:
    nCr = {}
    A = sorted(a[:-1])
    r1 = A[n // 2 - 1]
    r2 = A[n // 2]

    work1 = cmb(N, r1)
    work2 = cmb(N, r2)

    if work1 > work2:
        print("{0} {1}".format(N, r1))
    else:
        print("{0} {1}".format(N, r2))

Submission status: Runtime Error

Solution code:
# 再帰制限に引っかかった場合に外す
import sys
sys.setrecursionlimit(100000)

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

def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if n == 2:
    print("{0} {1}" .format(N, min(a)))
else:
    nCr = {}
    A = sorted(a[:-1])
    r1 = A[n // 2 - 1]
    r2 = A[n // 2]

    work1 = cmb(N, r1)
    work2 = cmb(N, r2)

    if work1 > work2:
        print("{0} {1}".format(N, r1))
    else:
        print("{0} {1}".format(N, r2))

Submission status: Runtime Error

Solution code:
n = int(input().split())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a.copy()
b=sorted(b,reverse=True)
comb_n=max(b)
b.pop(0)
c=b
comb_list=[]
ind_list=[]
for i in c:
    comb_list.append(comb(comb_n,i))
    ind_list.append(i)
max_num=max(comb_list)
for i in range(len(comb_list)):
    if comb_list[i]==max_num:
        print(comb_n,ind_list[i])

Submission status: Runtime Error

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

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(sortA-half_of_a_large))]
print(a_large,a_small)a

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
mx=0
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=0
  comb=1
  for i in range(1,asmall+1): comb*=alarge-i+1
  for i in range(1,asmall+1): comb/=i
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
  comb=1
  for i in range(1,asmall+1): comb*=alarge-i+1
  for i in range(1,asmall+1): comb/=i
print("{} {}".format(alarge,asmall))

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)

Submission status: Runtime Error

Solution code:
import itertools
from scipy.special import comb

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

ans = [0, 0]
max_comb = 0
combs = {}
for a_i, a_j in itertools.combinations(a, 2):
    if a_j > a_i:
        tmp = a_j
        a_j = a_i
        a_i = tmp

    if (a_i, a_i - a_j) in combs:
        continue

    c = comb(a_i, a_j, exact=True)
    combs[(a_i, a_j)] = c
    # print(a_i, a_j, c)
    if c > max_comb:
        max_comb = c
        ans[0], ans[1] = a_i, a_j

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

Submission status: Runtime Error

Solution code:
import itertools

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

ans = [0, 0]
max_comb = 0
for a_i, a_j in itertools.combinations(a, 2):
    if a_j > a_i:
        tmp = a_j
        a_j = a_i
        a_i = tmp

    comb = len(list(itertools.combinations(range(a_i), a_j)))
    if comb > max_comb:
        max_comb = comb
        ans[0], ans[1] = a_i, a_j

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

Submission status: Runtime Error

Solution code:
import scipy.misc as scm
N = int(input())
nums = list(map(int, input().split(' ')))
nums.sort(reverse=True)
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        s = int(scm.comb(nums[i], nums[j]))
        if ans < s:
            ans = s
            res = '{} {}'.format(nums[i], nums[j])
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a_n = list(map(int, input().split()))
def UF(num):
    if num==0:
        return 1
    else:
        return num*UF(num-1)
def comb(a1, a2):
    return UF(a1)/(UF(a2)*UF(a1-a2))
result = np.zeros([n, n])
for i in range(n):
    for ii in range(n):
        if a_n[i] > a_n[ii]:
            result[i, ii] = comb(a_n[i], a_n[ii])
a = np.argmax(result)
res1 = a//n
res2 = a%n

print(a_n[res1], a_n[res2])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a_n = list(map(int, input().split()))
def UF(num):
    if num==1:
        return 1
    else:
        return num*UF(num-1)
def comb(a1, a2):
    return UF(a1)/(UF(a2)*UF(a1-a2))
result = np.zeros([n, n])
for i in range(n):
    for ii in range(n):
        if a_n[i] > a_n[ii]:
            result[i, ii] = comb(a_n[i], a_n[ii])
a = np.argmax(result)
res1 = a//n
res2 = a%n

print(a_n[res1], a_n[res2])

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
a = []
b = []
d = []
for i in range(1,n):
    c = l[i]
    if l[0] >= int((c+1)/2):
        a.append(comb(c,l[0]))
        b.append(c)
        d.append(l[0])
    else:
        j = 0
        while l[j] < int((c+1)/2):
            j += 1
        else:
            if l[j] == int((c+1)/2):
                a.append(comb(c,int((c+1)/2)))
                b.append(c)
                d.append(int((c+1)/2))
            else:
                if l[j] - int((c+1)/2) < int((c+1)/2) -l[j-1]:
                    a.append(comb(c,l[j]))
                    b.append(c)
                    d.append(l[j])
                else:
                    a.append(comb(c,l[j-1]))
                    b.append(c)
                    d.append(l[j-1])
I = a.index(max(a))
print("{} {}".format(b[I],d[I]))

Submission status: Runtime Error

Solution code:
def fact(i):
    a = 1
    for i in range(2,i+1):
        a *= i
    return a
def comb(i,j):
    if j != 0 and j != i
        return int(fact(i)/(fact(j)*fact(i-j)))
    else:
        return 1

n = int(input())
l = list(map(int,input().split()))
l.sort()
a = []
b = []
d = []
for i in range(1,n):
    c = l[i]
    if l[0] >= int((c+1)/2):
        a.append(comb(c,l[0]))
        b.append(c)
        d.append(l[0])
    else:
        j = 0
        while l[j] < int((c+1)/2):
            j += 1
        else:
            if l[j] == int((c+1)/2):
                a.append(comb(c,int((c+1)/2)))
                b.append(c)
                d.append(int((c+1)/2))
            else:
                if l[j] - int((c+1)/2) < int((c+1)/2) -l[j-1]:
                    a.append(comb(c,l[j]))
                    b.append(c)
                    d.append(l[j])
                else:
                    a.append(comb(c,l[j-1]))
                    b.append(c)
                    d.append(l[j-1])
I = a.index(max(a))
print("{} {}".format(b[I],d[I]))

Submission status: Runtime Error

Solution code:
def fact(i):
    a = 1
    for i in range(2,i+1):
        a *= i
    return a
def comb(i,j):
    return int(fact(i)/(fact(j)*fact(i-j)))

n = int(input())
l = list(map(int,input().split()))
l.sort()
a = []
b = []
d = []
for i in range(1,n):
    c = l[i]
    if l[0] >= int((c+1)/2):
        a.append(comb(c,l[0]))
        b.append(c)
        d.append(l[0])
    else:
        j = 0
        while l[j] < int((c+1)/2):
            j += 1
        else:
            if l[j] == int((c+1)/2):
                a.append(comb(c,int((c+1)/2)))
                b.append(c)
                d.append(int((c+1)/2))
            else:
                if l[j] - int((c+1)/2) < int((c+1)/2) -l[j-1]:
                    a.append(comb(c,l[j]))
                    b.append(c)
                    d.append(l[j])
                else:
                    a.append(comb(c,l[j-1]))
                    b.append(c)
                    d.append(l[j-1])
I = a.index(max(a))
print("{} {}".format(b[I],d[I]))