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:
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 = 1
        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:
from bisect import bisect_left

N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

def takeClosest(myList, myNumber):
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

ans = takeClosest(sorteddata, sorteddata[-1] / 2)
print(sorteddata[-1] + ' ' + ans)

Submission status: Runtime Error

Solution code:
from scipy.misc import comb

i = int(input())
c = 0
a = 0
b = 0
l = list(input().split())
for j  in l:
 for k in l:
  if (int(comb(int(j),int(k))) > c) and j!=k:
   c = int(comb(int(j),int(k)))
   a = j
   b = k

print("{0} {1}".format(a, b))

Submission status: Runtime Error

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


# def comb(n1, n2):
# 	result = 1
# 	for x in range(n1-n2+1,n1+1):
# 		result = result * x
# 	for x in range(1,n2+1):
# 		result = result / x
# 	return int(result)

numList = sorted(numList)
lastNum = numList[len(numList)-1]

if n > 2:
	if n%2 == 0:
		medIndex = medIndex1 - 1
		medNum = numList[medIndex]
		print(str(lastNum)+" "+str(medNum))
	else:
		medIndex = int((n)/2)
		medNum = numList[medIndex]
		print(str(lastNum)+" "+str(medNum))
else:
	print(str(numList[1])+" "+str(numList[0]))

Submission status: Runtime Error

Solution code:
def comb(n, r):
    return f(n) / (f(n - r) * f(r)) 
 
def f(n):
    if n == 0:
        return 1
    else:
        return n * f(n - 1)
 
n = input()
a = map(int, raw_input().split())
 
a.sort()
a.reverse()
max = 0
ai = 0
aj = 0
for i in range(0, len(a)):
    for j in range(i + 1, len(a)):
        c = comb(a[i], a[j])
        if c > max:
            max = c
            ai = a[i]
            aj = a[j]
print(str(ai) + " " + str(aj))

Submission status: Runtime Error

Solution code:
def comb(n, r):
    return f(n) / (f(n - r) * f(r)) 
 
def f(n):
    if n == 1:
        return 1
    else:
        return n * f(n - 1)

n = input()
a = map(int, raw_input().split())
 
a.sort()
a.reverse()
max = 0
ai = 0
aj = 0
for i in range(0, len(a)):
    for j in range(i + 1, len(a)):
        c = comb(a[i], a[j])
        if c > max:
            max = c
            ai = a[i]
            aj = a[j]
print(str(ai) + " " + str(aj))

Submission status: Runtime Error

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

    a.sort()
    a.reverse()
    max = 0
    ai = 0
    aj = 0
    for i in range(0, len(a)):
        for j in range(i + 1, len(a)):
            c = comb(a[i], a[j])
            if c > max:
                max = c
                ai = a[i]
                aj = a[j]
    print(str(ai) + " " + str(aj))
    
def comb(n, r):
    return f(n) / (f(n - r) * f(r)) 

def f(n):
    if n == 1:
        return 1
    else:
        return n * f(n - 1)

Submission status: Runtime Error

Solution code:
bigger_num=max(list_num)
smaller_num=int(bigger_num/2)

for i in range(0, smaller_num):
    if smaller_num + i in list_num:
        smaller_num = smaller_num + i
        break
    elif smaller_num - i in list_num:
        smaller_num = smaller_num - i
        break

print(bigger_num, smaller_num)

Submission status: Runtime Error

Solution code:
import bisect
import math

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
m=0
ans1=max(a)
ams2=min(a)

for i in range(1,n):
  b = bisect.bisect_left(a[:i],a[i]/2)
  r = math.factorial(a[i])/(math.factorial(a[b])*math.factorial(a[i]-a[b]))
  if b-1<=0:
    j=b
  else:
    if abs(a[b]-a[i]/2)<=abs(a[b-1]-a[i]/2):
      j=b
    else:
      j=b-1
      
  r = math.factorial(a[i])/(math.factorial(a[j])*math.factorial(a[i]-a[j]))
  if r>m:
    ans1=a[i]
    ans2=a[j]
print(ans1,ans2)

Submission status: Runtime Error

Solution code:
import bisect
import math
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
m=0
for i in range(1,n):
  b=bisect.bisect_left(a[:i],a[i]/2)

  r=math.factorial(a[i])/(math.factorial(a[b])*math.factorial(a[i]-a[b]))
  if b-1>=0:
    l=math.factorial(a[i])/(math.factorial(a[b-1])*math.factorial(a[i]-a[b-1]))
  else:
    l=0
  if max(r,l)>m:
    m=max(r,l)
    ans1=a[i]
    if r>l:
      ans2=a[b]
    else:
      ans2=a[b-1]
print(ans1,ans2)

Submission status: Runtime Error

Solution code:
# coding:utf-8

def comb(n, r):
    n, r = max(n, r), min(n, r)
    nume = 1
    deno = 1
    for i in range(n-r+1, n+1):
        nume *= i
    for i in range(1, r+1):
        deno *= i
    return int(nume/deno)

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

MAX = 0
n = 0
r = 0
for ni in range(0, len(a)):
    for ri in range(ni + 1, len(a)):
        buf = comb(a[ni], a[ri])
        if buf > MAX:
            MAX = buf
            n = a[ni]
            r = a[ri]

print(n, r)

Submission status: Runtime Error

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

import math
def comb(n,r):
  return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
  
max_comb = [comb(i, i // 2) for i in range(n-1)]

mid_dis = [abs(a[n-1] / 2 - a[i]) for i in range(n-1)]
arg_max_i = [i for i in range(n-1) if mid_dis[i] == min(mid_dis)][0]

print(a[n-1], a[arg_max_i])

Submission status: Runtime Error

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

import math
def comb(n,r):
  return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
  
max_comb = [comb(i, i // 2) for i in range(n-1)]

mid_dis = [abs(a[n-1] / 2 - a[i]) for i in range(n-1)]
arg_max_i = [i for i in range(n-1) if mid_dis[i] == min(mid_dis)][0]

print(a[n-1], a[arg_max_i])

Submission status: Runtime Error

Solution code:
n=int(input())
arr=[int(x) for x in input().split()]
pairs = []
for i in range(n):
    for j in range(i+1, n):
        if arr[i] > arr[j]:
            pairs.append([arr[i], arr[j]])
        else:
            pairs.append([arr[j], arr[i]])
m = 0
max_index = -1
for index, pair in enumerate(pairs):
    cur = comb(pair[0], pair[1])
    print(cur)
    if cur > m:
        m = cur
        max_index = index
res = pairs[max_index]
print(res[0], res[1])

Submission status: Runtime Error

Solution code:
n=int(input())
arr=[int(x) for x in input().split()]
pairs = []
for i in range(n):
    for j in range(i+1, n):
        if arr[i] > arr[j]:
            pairs.append([arr[i], arr[j]])
        else:
            pairs.append([arr[j], arr[i]])
print(pairs)
m = 0
max_index = -1
for index, pair in enumerate(pairs):
    cur = comb(pair[0], pair[1])
    print(cur)
    if cur > m:
        m = cur
        max_index = index
res = pairs[max_index]
print(res[0], res[1])

Submission status: Runtime Error

Solution code:
import math
def combi(m,r):
    return math.factorial(m)/(math.factorial(r)*math.factorial(m-r))
n = int(input())
x = sorted(list(map(int,input().split())))
s = 0
for i in range(n):
    for j in range(i,n):
        if i==j:
            continue
        k=combi(x[j],x[i])
        if k > s:
            s=k
            a,b = x[j],x[i]
print(a,b)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(filiter(lambad x: x!=ai, a), key=lambda x: abs(x-ai//2))
print("{} {}".format(ai, aj))

Submission status: Runtime Error

Solution code:

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

    def comb(x, y):
        c = 1
        p = 1
        for i in range(y, 0, -1):
            c = c * i
        for i in range(x, x - y, -1):
            p = p * i
        return p / c

    p = max(a)
    want_near = p // 2
    tmp = 1
    tmpdiff = 9999999
    for i in a:
        diff = abs(i - want_near)
        if diff < tmpdiff:
            tmpdiff = diff
            tmp = i

    return "{0} {1}".format(p, tmp)


print(m())

Submission status: Runtime Error

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

a.sort()

old = 0
for item in a[-1]:
    if abs(old - a[-1]/2) <= abs(item - a[-1]/2):
        print(a[-1], old)
        break
    old = item

Submission status: Runtime Error

Solution code:
from decimal import *
n = int(input())

number_list = list(int,map(input().split()))
number_list.sort()
max_number = max(number_list)
middle_number = Decimal(max_number) / Decimal(2)
for i in range(len(number_list)-1):
    if (number_list[i]-middle_number)*(number_list[i+1]-middle_number) < 0:
        if abs(number_list[i]-middle_number) <= abs(number_list[i+1]-middle_number):
            print(max_number,number_list[i])
            break
        else:
            print(max_number,number_list[i+1])
            break
    else:
        pass

Submission status: Runtime Error

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

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right
    from itertools import combinations

    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    if max(a) == 0:
        print(str(a_max) + ' ' + str(a[0]))
        exit()

    if (n - 1) % 2 == 0:
        left = bisect_left(a, a_max // 2)
        right = n - bisect_right(a, a_max // 2)
        a_right = combinations(range(1, a_max + 1), a[right])
        a_left = combinations(range(1, a_max + 1), a[left])

        if len(list(a_left)) > len(list(a_right)):
            print(str(a_max) + ' ' + str(a[left]))
        else:
            print(str(a_max) + ' ' + str(a[right]))
    else:
        center = bisect_left(a, a_max // 2)

        if center >= len(a):
            center -= 1

        a_center = combinations(range(1, a_max + 1), a[center])
        print(str(a_max) + ' ' + str(a[center]))

Submission status: Runtime Error

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

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right
    from itertools import combinations

    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    if max(a) == 0:
        print(str(a_max) + ' ' + str(a[0]))
        exit()

    left = bisect_left(a, a_max // 2)
    right = n - bisect_right(a, a_max // 2)
    a_right = combinations(range(1, a_max + 1), a[right])
    a_left = combinations(range(1, a_max + 1), a[left])

    if len(list(a_left)) > len(list(a_right)):
        print(str(a_max) + ' ' + str(a[left]))
    else:
        print(str(a_max) + ' ' + str(a[right]))

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))
 
def bin_search(in_list, val):
    cnt = len(in_list)
    mid = int(round(cnt/2))
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val
 
n = int(input())
A = sorted(list(map(int, input().split())))
 
m_combo = 0
ai = 0
aj = 0
 
for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    upper = A[A.index(val) + 1]
    if abs(val - round(a/2)) > abs(upper - round(a/2)):
      val = upper
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val
 
print('{} {}'.format(ai, aj))

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    upper = A[A.index(val) + 1]
    if abs(val - round(a/2)) > abs(upper - round(a/2)):
      val = upper
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
	import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    upper = A[A.index(val) + 1]
    if abs(val - round(a/2)) > abs(upper - round(a/2)):
      val = upper
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    upper = A[A.index(val) + 1]
    val = min(abs(val - round(a/2), upper - round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:(mid + 1)], val)
    if in_list[mid] < val:
        return bin_search(in_list[(mid - 1):], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = cnt/2 + cnt%2
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = int(round(cnt/2))
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid+1], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid-1:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/math.factorial(r) * math.factorial(n-r)

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math
def cal(n ,r):
    print('n:{} r:{}'.format(n, r))
    if n == r:
        return 1
    return math.factorial(n)/math.factorial(r) * math.factorial(n-r)

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

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

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

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

Submission status: Runtime Error

Solution code:
import math

def comb(a, b):
	return int(math.factorial(a) / math.factorial(b) / math.factorial(a-b))

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

	sa = sorted(a)

	oldcmb = -float('inf')
	oldi, oldj = (-1, -1)
	i, j = (-1, -1)
	for i in range(n):
		for j in range(n):
			if i == j or i < j:
				break
			cmb = comb(sa[i], sa[j])
			# print('old:{} new:{}[{}][{}]'.format(oldcmb, cmb, i, j))
			if cmb > oldcmb:
				oldcmb = cmb
				oldi, oldj = (i, j)
		if j == n-1:
			break

	print('{} {}'.format(sa[oldi], sa[oldj]))
	# print('{}:{} {}:{}'.format(oldi, sa[oldi], oldj, sa[oldj]))

Submission status: Runtime Error

Solution code:
import math

def comb(a, b):
	return int(math.factorial(a) / math.factorial(b) / math.factorial(a-b))

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

	sa = sorted(a)

	oldcmb = -math.inf
	oldi, oldj = (-1, -1)
	i, j = (-1, -1)
	for i in range(n):
		for j in range(n):
			if i == j or i < j:
				break
			cmb = comb(sa[i], sa[j])
			# print('old:{} new:{}[{}][{}]'.format(oldcmb, cmb, i, j))
			if cmb > oldcmb:
				oldcmb = cmb
				oldi, oldj = (i, j)
		if j == n-1:
			break

	print('{} {}'.format(sa[oldi], sa[oldj]))
	# print('{}:{} {}:{}'.format(oldi, sa[oldi], oldj, sa[oldj]))

Submission status: Runtime Error

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

m_combo = 0
ai = 0
aj = 0

for i in range(n):
  a = A[i]
  val = bin_search(list[:i])
  combo = cal(a, val)
  if combo > m_combo:
    m_combo = combo
    ai = a
    aj = val

print('{} {}'.format(ai, aj))
  
def cal(n ,r):
  if n == r:
    return 1
  return math.factorial(n)/math.factorial(r) * math.factorial(n-r)

def bin_search(list, val):
  cnt = list.cnt
  mid = round(cnt/2)
  if cnt == 1:
    return val
  if list[mid] > val:
    bin_search(list[:mid], val)
  if list[mid] < val:
    bin_search(list[mid:], val)
  if list[mid] == val:
    return val

Submission status: Runtime Error

Solution code:
n = int(input())
A = map(int, input().split())
 
ai = max(A)
A.remove(ai)
 
Asub = [abs(ai/2 -a) for a in A]
aj = A[Asub.index(min(Asub))]
 
print('{} {}'.format(ai, aj))

Submission status: Runtime Error

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

ai = max(A)
A.remove(ai)

Asub = [abs(ai/2 -a) for a in A]
aj = A[Asub.index(min(Asub))]

print(ai + " " + aj)

Submission status: Runtime Error

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

a.sort(reverse=True)
ans1 = a[0]
count = 0

if ans1 % 2 == 0:
    mid = int(ans1 / 2)
    if mid in a:
        j = mid

    elif:
        while 1:
            count += 1
            if (mid + count) in a:
                j = mid + count
                break
            elif:
                (mid - count) in a:
                j = mid + count
                break

else:
    while 1:
        count += 1
        if (mid + count) in a:
            j = mid + count
            break
        elif:
            (mid - count) in a:
            j = mid + count
            break

print(ans1, j)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10000)

def search(a, b, left, right):
    mid = int(left + (left - right) / 2)
    if(b[mid] == a):
        return b[mid]
    if(b[mid] >= a and a >= b[mid+1]):
        if(b[mid]- a >= a - b[mid+1]):
            return  b[mid+1]
        else:
            return b[mid]
    if(b[mid] >= a):
        return search(a, b, 0, mid)
    else:
        return search(a, b, mid, right)

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

b = sorted(a, reverse=True)
for i in b:
    m = i/2
    j = search(m, b, 0, len(b))
    print("%d %d" %(i, j))
    break

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(' '))))

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

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

def search(a, b, left, right):
    mid = int(left + (left - right) / 2)
    if(b[mid] == a):
        return b[mid]
    if(b[mid] >= a and a >= b[mid+1]):
        if(b[mid]- a >= a - b[mid+1]):
            return  b[mid+1]
        else:
            return b[mid]
    if(b[mid] >= a):
        return search(a, b, 0, mid)
    else:
        return search(a, b, mid, right)

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

b = sorted(a, reverse=True)
for i in b:
    m = i/2
    j = search(m, b, 0, len(b))
    print("%d %d" %(i, j))
    break

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(' '))))

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

    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 = comb1(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 math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	#return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )
	if N-R>=R: t=R
	else:	t=N-R

	bunbo=1
	bunshi=1
	for i in range(1,t+1):
		bunbo*=(N-i+1)
		bunshi*=i
	return bunbo/bunshi


l=1
r=n-1
c=a[0]
for i in range(20):
	if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
		r=(l+r*2)/3
	else:
		l=(l*2+r)/3


if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
	print c,a[(l*2+r)/3]
else:
	print c,a[(l+r*2)/3]

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):
        if(is_list[a - i] == False):
            tmp1 = fact(i)
            tmp2 = fact(a - i)

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

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

Submission status: Runtime Error

Solution code:
import math
import numpy

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

max_num=max(a)
middle_num=math.ceil(max_num/2)
middle_num_up=middle_num
middle_num_down=middle_num

if n>2:
    while True:
        if middle_num_up in a:
            ans=middle_num_up
            break
        if middle_num_down in a:
            ans=middle_num_down
            break
        else:
            middle_num_up+=1
            middle_num_down-=1
else:
    ans=min(a)

print("{} {}".format(max_num,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) and (is_list[a - i] == False):
        tmp1 = fact(i)
        tmp2 = fact(a - i)

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

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

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]
    else:
        break
print(a_i, 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
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])