Buggy python submission (verdict: Time Limit Exceeded):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()
#nCr % MOD
def cmb(n, r, MOD=0):
    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])
            if MOD != 0:
                result %= MOD
 
    return result

import bisect
ans = []
for i in range(1,min(n,len(str(n))+3)):
    p = a[-i]
    p2 = p/2
    q_i = bisect.bisect_left(a,p2)
    if ((a[q_i]-p2) > (p2 - a[q_i-1])) or p==a[q_i] and q_i != 0:
        q_i -= 1
    q = a[q_i]
    ans.append([cmb(p,q),p,q])

ans.sort(key=lambda x:x[0],reverse=True)
print(*ans[0][1:])

Fixed submission:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
a_i = a[-1]
a_i_2 = a_i / 2.0
b = a[0]
max0 = 0

for i in a:
    if i < a_i_2:
        b = i
    elif i != a_i:
        c = i
        break
    else:
        c = b
        break
from scipy.misc import comb
if comb(a_i, b) > comb(a_i,c):
    max0 = comb(a_i, b)
    a_j = b
else:
    max0 = comb(a_i, c)
    a_j = c

for i in range(1,n-1): 
    b_i = a[i]
    b_i_2 = b_i / 2.0
    b = a[0]
    for i in a:
        if i < b_i_2:
            b = i
        elif i != b_i:
            c = i
            break
        else:
            c = b
            break
    if comb(a_i, b) > comb(a_i,c): 
        max1 = comb(b_i, b)
        b_j = b
    else:
        max1 = comb(b_i, c)
        b_j = c
    if max1 > max0:
        max0 = max1
        a_i = b_i
        a_j = b_j
print("{} {}".format(a_i, a_j))

Fixed submission:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
a_i = a[-1]
a_j = a[0]
max = 0
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

from scipy.misc import comb
for i in range(n):
    if a[i]%2 == 0:
        b_j = getNearestValue(a, a[i]/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
    else:
        b_j = getNearestValue(a, (a[i]-1)/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
        b_j = getNearestValue(a, (a[i]+1)/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
print("{} {}".format(a_i, a_j))

Fixed submission:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)