Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import math
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

le = (math.factorial(ai) // math.factorial(ai -
                                           a[i_left - 1])) // math.factorial(a[i_left - 1])
ri = (math.factorial(ai) // math.factorial(ai - \
      a[i_right])) // math.factorial(a[i_right])

if (le >= ri):
    print(ai, a[i_left - 1])
else:
    print(ai, a[i_right])


Fixed submission:
import bisect
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import defaultdict
d = defaultdict(str)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

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)]


ai = a[0]
ai_fct = math.factorial(ai)
max_fct = 0
for i in range(n):
    if (i == 0):
        continue
    fct = cmb(a[0], a[i])
    d[fct] = str(ai) + ' ' + str(a[i])
    max_fct = max(max_fct, fct)

print(d[max_fct])


Fixed submission:
import bisect
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import defaultdict
d = defaultdict(str)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

ai = a[0]
ai_fct = math.factorial(ai)
max_fct = 0
for i in range(n):
    if (i == 0):
        continue
    fct = (ai_fct // math.factorial(a[i])) // math.factorial(ai - a[i])
    d[fct] = str(ai) + ' ' + str(a[i])
    max_fct = max(max_fct, fct)

print(d[max_fct])


Fixed submission:
import bisect
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])