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: Accepted

Solution code:
# D
n = int(input())
a_list = list(map(int, input().split()))

p = max(a_list)
gap = p
q = p
for i in range(n):
    gap_ = abs(a_list[i] - p / 2)
    if gap_ < gap and a_list[i] != p:
        gap = gap_
        q = a_list[i]
print(" ".join([str(p), str(q)]))

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
A.sort()
n = A[-1]
k = 0
for a in A[:-1]:
    if k < min(a, n-a):
        k = a
print(n, k)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
n = a[-1]
k = n/2
#n/2までの距離の最小
for i in range(N-1):
  r = n/2 - a[i]
  if abs(r) < abs(k): k = r
#print(k,n)
print(n,int(n/2-k))

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
x = max(a)
y = a[0]
for t in a:
  if t != x and min(x-t, t) >= min(x-y, y):
    y = t
print x, y

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
best = m
y = -1
for x in a:
    if x == m: continue
    if abs(x - m / 2) < best:
        best = abs(x - m / 2)
        y = x
print(m, y)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    xs = [int(x) for x in input().split()]

    c = max(xs)
    sc, best = c, c
    for d in xs:
        if d == c:
            continue
        if abs(d - c / 2) < sc:
            sc = abs(d - c / 2)
            best = d
    print(c, best)

Submission status: Runtime Error

Solution code:
def comb(a, b):
    if a < b:
        return comb(b, a)

    mul = 1
    for i in range(a, a - b, -1):
        mul *= i
    div = 1
    for i in range(1, b+1):
        div *= i
    return mul / div

n = int(input())
A = list(map(int, input().split()))
A.sort()
max_val = 0
ans = None
for i in range(n-1):
    for j in range(i+1, n):
        if max_val < comb(A[j], A[i]):
            max_val = comb(A[j], A[i])
            ans = (A[j], A[i])
print(*ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

A = sorted(A)

fac = [1]*(A[-1]+1)

for i in range(2,len(fac)) :
    fac[i] = i * fac[i-1]

ans1 = A[-1]
ans2 = 0

c = 0

for i in range(N) :
    a = A[i]
    calc = fac[ans1]//(fac[a] * fac[ans1-a])

    if c < calc :
        ans2 = a
        c = calc

print(ans1,ans2)

Submission status: Runtime Error

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

A = sorted(A)

fac = [1]*(A[-1]+1)

for i in range(2,len(fac)) :
    fac[i] = i * fac[i-1]

ans1 = A[-1]
ans2 = 0

c = 0

for i in range(N) :
    a = A[i]
    calc = fac[ans1]//(fac[a] * fac[ans1-a])

    if c < calc :
        ans2 = a
        c = calc

print(ans1,ans2)

Submission status: Runtime Error

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

index = bisect.bisect_right(a, a[-1]/2)

if abs(a[-1]/2 - a[index]) > abs(a[-1]/2 - a[index+1]) and n > 2:
    index += 1
print(a[-1], a[index])

Submission status: Runtime Error

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

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

index = bisect.bisect_right(a, a[-1]//2)

if cmb(a[-1], a[index]) < cmb(a[-1], a[index+1]):
    index += 1
print(a[-1], a[index])

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    int n = a[N - 1], k = n / 2;
    cout << n << " ";
    auto i = lower_bound(a.begin(), a.end(), k);
    if (*(i + 1) - k < k - *i) cout << *(i + 1) << endl;
    else cout << *i << endl;
    return;
}

int main() {
    solve();
}

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))
a=sorted(a)
a_max=a[n-1]
i=bisect.bisect_left(a,a_max)
l,r=a[i:i+2]
if abs(a_max/2-l)>abs(a_max/2-r):
  ans=r
else:
  ans=l
print(a[n-1],ans)

Submission status: Runtime Error

Solution code:
def C(n,r): # combination
    top = 1
    bot1 = 1
    bot2 = 1
    for i in range(n):
        top *= i + 1
    for i in range(r):
        bot1 *= i + 1
    for i in range(n - r):
        bot2 *= i + 1

    return int(top / (bot1 * bot2))


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

a.sort()

num = 1
for i in range(1,len(a)):
    j = 0
    while j < a.index(a[i]):
        c = C(a[i],a[j])
        if c >= num:
            num = c
            l = a[i]
            r = a[j]
        j += 1



print(l, r)

Submission status: Runtime Error

Solution code:
def C(n,r): # combination
    top = 1
    bot1 = 1
    bot2 = 1
    for i in range(n):
        top *= i + 1
    for i in range(r):
        bot1 *= i + 1
    for i in range(n - r):
        bot2 *= i + 1

    return int(top / (bot1 * bot2))


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

a.sort()

num = 1
for i in range(1,len(a)):
    j = 0
    while j < a.index(a[i]):
        c = C(a[i],a[j])
        if c > num:
            num = c
            l = a[i]
            r = a[j]
        j += 1



print(l, r)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
mid = bisect.bisect_left(y,y[-1]/2)
if y[-1]/2-x[mid]>=x[mid+1]-y[-1]/2:print(y[-1],x[mid+1])
else:print(y[-1],x[mid])

Submission status: Runtime Error

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

def dist(x, y):
    assert 0 <= y <= x
    return min(y, x - y)

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ai = sorted(ai)

    x = ai[-1]
    y = ai[0]
    for i in range(n - 1):
        if dist(x, ai[i]) > dist(x, y):
            y = ai[i]

    print(f"{x} {y}")

main()

Submission status: Runtime Error

Solution code:
input()
da = list(map(int,input().split()))
 
x = max(da)
y = x + 1
for i in da:
	if i == x:
  		continue
    if abs(x/2 - i ) <= abs(x/2 - y):
		y = i
print(x,y)

Submission status: Runtime Error

Solution code:
input()
da = list(map(int,input().split()))
 
x = max(da)
y = x + 1
for i in x:
	if i == x:
  		continue
    if abs(x/2 - i ) <= abs(x/2 - y):
		y = i
print(x,y)

Submission status: Runtime Error

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

x = max(da)
y = x + 1
for i in x
	if i == x:
  		continue
    if abs(x/2 - i ) <= (x/2 - y):
		y = i
print(x,y)

Submission status: Runtime Error

Solution code:
import numpy as np

def get_nearest_val(l, n, side='left'):
    l = sorted(l)
    i = np.searchsorted(l, n, side=side)
    return l[i]

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)

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

max_n = max(A)
key_r = (max_n + 1) / 2
# key_r = int((max_n + 1) / 2)
# print(key_r)

left_r = get_nearest_val(A, key_r, side='left')
# print(left_r)
right_r = get_nearest_val(A, key_r, side='right')
# print(right_r)

left_comb = comb(max_n, left_r)
# print(left_comb)
right_comb = comb(max_n, right_r)
# print(right_comb)

if left_comb >= right_comb:
    print(str(max_n) + ' ' + str(left_r))
else:
    print(str(max_n) + ' ' + str(right_r))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

def get_nearest_val(l, n, side='left'):
    l = sorted(l)
    i = np.searchsorted(l, n, side=side)
    return l[i]

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)

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

max_n = max(A)

key_r = int((max_n + 1) / 2)

left_r = get_nearest_val(A, key_r, side='left')
right_r = get_nearest_val(A, key_r, side='right')

left_comb = comb(max_n, left_r)
right_comb = comb(max_n, right_r)

if left_comb >= right_comb:
    print(str(max_n) + ' ' + str(left_r))
else:
    print(str(max_n) + ' ' + str(right_r))

Submission status: Runtime Error

Solution code:
'''
thinking
comb(n, r)
'''
import numpy as np
import itertools

def get_nearest_val(l, n, side='left'):
    l = sorted(l)
    i = np.searchsorted(l, n, side=side)
    return l[i]

# c = list(itertools.combinations(s,3))

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 get_nearest_val(l, n):
#     i = np.abs(np.asarray(l) - n).argmin()
#     return l[i]

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

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

max_n = max(A)

key_r = (max_n + 1) / 2

left_r = get_nearest_val(A, key_r, side='left')
right_r = get_nearest_val(A, key_r, side='right')

left_comb = comb(max_n, left_r)
right_comb = comb(max_n, right_r)

# left_comb = len(list(itertools.combinations(A, left_r)))
# right_comb = len(list(itertools.combinations(A, right_r)))

if left_comb >= right_comb:
    print(str(max_n) + ' ' + str(left_r))
else:
    print(str(max_n) + ' ' + str(right_r))

Submission status: Runtime Error

Solution code:
def binarySearch(a, i, j, val):
    if abs(j-i) <= 1:
        if abs(a[i]-val) < abs(a[j]-val):
            return a[i]
        else:
            return a[j]
    else:
        pivot = (i+j)//2
        if a[pivot] == val:
            return a[pivot]
        elif a[pivot] > val:
            return binarySearch(a, i, pivot, val)
        else:
            return binarySearch(a, pivot, j, val)

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

n = int(input())
line = input().split(' ')
a = []
score = [0] * n
for element in line:
    a.append(int(element))

a.sort()
for i in range(n):
    if a[i] % 2 == 0:
        closest = binarySearch(a, 0, i, a[i]//2)
        score[i] = [comb(a[i], closest), a[i], closest]
    else:
        closest1 = binarySearch(a, 0, i, (a[i]-1)//2)
        closest2 = binarySearch(a, 0, i, (a[i]+1)//2)
        if abs((a[i]-1)//2 - closest1) < abs((a[i]+1)//2 - closest2):
            closest = closest1
        else:
            closest = closest2
        score[i] = [comb(a[i], closest), a[i], closest]

print (max(score)[1], max(score)[2])

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
if abs((l/2) - a[j-1]) < abs((l/2) - a[j]):
    j -= 1
print(l, a[min(j, len(a)-1)])

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
if abs((l/2) - a[j]) > abs((l/2) - a[j+1]):
    j += 1
print(l, a[min(j, len(a)-1)])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = max(a)
a.remove(i)
k = min(a, key=lambda x: abs(i-x*2))
print(i, j)

Submission status: Runtime Error

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma-num*2)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma//2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma/2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    value = abs(ma/2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    value = abs(ma/2-num)
    if minvalue > value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
def inpl(): return list(map(int, input().split()))
# n! * (m- n + r)! * (m-r)!
def comb(n1, n2):
	a = 1
	for i in range(n1):
		a *= (i+1)
	for i in range(n1-n2):
		a /= (i+1)
	for i in range(n2):
		a /= (i+1)
	return a

N = int(input())
ns = inpl()
nss = sorted(ns)
a1 = 1
a2 = 1
a_max = 0
for i in range(N):
	for j in range(N):
		if i < j:
			max_tmp = comb(nss[j], nss[i])
			if a_max <= max_tmp:
				a_max = max_tmp
				a1 = nss[j]
				a2 = nss[i]
print("{} {}".format(a1, a2))

Submission status: Runtime Error

Solution code:

cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n-1, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))


sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(len(sli) - 2,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n-1, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))


sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(len(sli) - 2,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Runtime Error

Solution code:
import numpy
N = int(raw_input())
A = map(int, raw_input().split())

def mul(x, y):
    return x * y

def nCr(n, r):
    if r == 0:
        return 1
    if n/2 < r:
        return nCr(n, n-r)
    return reduce(mul, range(n, n - r, -1)) / reduce(mul, range(1, r+1))

def nCrMax(n):
    return nCr(n, n/2)

sortedA = sorted(A, reverse = True)

max = -1
for i in range(N - 1):
    n = sortedA[i]
    target = n/2
    newA = sortedA[:i] + sortedA[i+1:]
    r = newA[numpy.argmin(map(lambda x: abs(x - target), newA))]
    ncr = nCr(n, r)
    if(nCr > max):
        max = nCr
    else:
        break
    if nCrMax(sortedA[i+1]) < max:
        break

print n, r

Submission status: Runtime Error

Solution code:
# 再帰制限に引っかかった場合に外す
# import sys
# sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

maxvalue = -1
ans = -1
for num in lsnum:
    val = cmb(ma,num)
    if(ma == num):
        continue
    if maxvalue < val:
        maxvalue = val
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
import numpy
N = int(raw_input())
A = map(int, raw_input().split())

def mul(x, y):
    return x * y

def nCr(n, r):
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) / reduce(mul, range(1, r+1))

def nCrMax(n):
    return nCr(n, n/2)

sortedA = sorted(A, reverse = True)

max = -1
for i in range(N - 1):
    n = sortedA[i]
    target = n/2
    newA = sortedA[:i] + sortedA[i+1:]
    r = newA[numpy.argmin(map(lambda x: abs(x - target), newA))]
    ncr = nCr(n, r)
    if(nCr > max):
        max = nCr
    else:
        break
    if nCrMax(sortedA[i+1]) < max:
        break

print n, r

Submission status: Runtime Error

Solution code:


cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]
    return n * permutuation(n - 1)


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x / (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(len(sli) - 1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Runtime Error

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

import sys
n = int(sys.stdin.readline().rstrip()) # n個の自然数
a_list = list(map(int, sys.stdin.readline().rstrip().split()))
a_list.sort(reverse = True) #要素を降順にソート
max = 0
ans_comb = []
for i in range(n):
    for j in range(n-i):
        temp_max = comb(a_list[i], a_list[i + j])
        if temp_max > max:
            max = temp_max
            ans_comb = [a_list[i], a_list[i + j]]
print(str(ans_comb[0]) + ' ' + str(ans_comb[1]))

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input());
v = list(map(int, input().split()))
best = -1
a = -1
b = -1
v.sort()
for i in range(0, n):
  l = 0
  r = n-1
  ans = -1
  while(l <= r):
    m = int((l+r)//2)
    if v[m] <= v[i]//2:
      ans = m
      l = m+1
    else:
      r = m-1
  if ans == -1:
    continue
  if v[ans] > v[i]:
    continue
  if ans != i and factorial(v[i])/(factorial(v[ans])*factorial(v[i] - v[ans])) > best:
    a = v[i]
    b = v[ans]
    best = factorial(v[i])/(factorial(v[ans])*factorial(v[i] - v[ans]))
    
  if ans+1 < n and ans+1 != i and v[i] > v[ans+1] and factorial(v[i])/(factorial(v[ans+1])*factorial(v[i] - v[ans+1])) > best:
    a = v[i]
    b = v[ans+1]
    best = factorial(v[i])/(factorial(v[ans+1])*factorial(v[i] - v[ans]))
print('%d %d\n' % (a,b))

Submission status: Runtime Error

Solution code:


cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]
    return n * permutuation(n - 1)


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x / (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Runtime Error

Solution code:
from bisect import *

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect_left(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect_left(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def fun(a,b):
    if b==-1:
        return -1
    elif b==0:
        return 0
    return (b+1)*(2*a-b)/2 - b*(b+1)/2

N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
ans=[-1,0,0]
if len(Y)==2:
    print Y[1],Y[0]

else:
    for y in Y[::-1]:
        qry=y/2
        tmp1=find_ge(Y, qry)
        tmp2=find_le(Y, qry)
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp1),y,tmp1]
        if ans[0]<fun(y,tmp2):
            ans=[fun(y,tmp2),y,tmp2]
    print ans[1], ans[2]

Submission status: Runtime Error

Solution code:


cache = {0: 1, 1: 1, 2: 2}


def permutuation(n):
    if n in cache:
        return cache[n]
    return n * permutuation(n - 1)


def combo(n, r):
    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    return int(x / (y * z))


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Runtime Error

Solution code:
def permutuation(n):
    if n < 2: return 1
    return n * permutuation(n - 1)


def combo(n, r):
    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    return int(x / (y * z))


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))