Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
from bisect import bisect_left
from sys import stdin


def solve(a):
    a.sort()
    max_cmb = cmb(a[1], a[0])
    ans = [a[1], a[0]]
    for ai in a[n-1:1:-1]:
        divided_ai = ai//2
        ak = a[bisect_left(a, divided_ai)]
        q = cmb(ai, ak)
        if a[1] <= ai//2:
            aj = a[bisect_left(a, divided_ai)-1]
            p = cmb(ai, aj)
            if q < p and max_cmb < p:
                ans = [ai, aj]
                max_cmb = p
            elif max_cmb < q:
                ans = [ai, ak]
                max_cmb = q
            else:
                return str(ans[0]) + ' '+str(ans[1])

        else:
            if max_cmb < q:
                ans = [ai, ak]
                max_cmb = q
            else:
                return str(ans[0]) + ' '+str(ans[1])

    return str(ans[0]) + ' '+str(ans[1])


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


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, stdin.readline().split()))
    print(solve(a))


Fixed submission:
from bisect import bisect_left
from sys import stdin



def solve(a):
    a.sort()
    mid = a[n-1]/2
    ai = a[bisect_left(a, mid)-1]
    aj = a[bisect_left(a, mid)]
    am = ai if abs(mid-ai) <= abs(mid-aj) else aj

    print(a[n-1], am)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, stdin.readline().split()))
    solve(a)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
from bisect import bisect_left


def solve(a):
    a.sort()
    max_cmb = cmb(a[1], a[0])
    ans = [a[1], a[0]]
    for ai in a[n-1:1:-1]:
        divided_ai = ai//2
        ak = a[bisect_left(a, divided_ai)]
        q = cmb(ai, ak)
        if a[1] <= ai//2:
            aj = a[bisect_left(a, divided_ai)-1]
            p = cmb(ai, aj)
            if q < p and max_cmb < p:
                ans = [ai, aj]
                max_cmb = p
            elif max_cmb < q:
                ans = [ai, ak]
                max_cmb = q
            else:
                return str(ans[0]) + ' '+str(ans[1])

        else:
            if max_cmb < q:
                ans = [ai, ak]
                max_cmb = q
            else:
                return str(ans[0]) + ' '+str(ans[1])

    return str(ans[0]) + ' '+str(ans[1])


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


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


Fixed submission:
from bisect import bisect_left
from sys import stdin



def solve(a):
    a.sort()
    mid = a[n-1]/2
    ai = a[bisect_left(a, mid)-1]
    aj = a[bisect_left(a, mid)]
    am = ai if abs(mid-ai) <= abs(mid-aj) else aj

    print(a[n-1], am)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, stdin.readline().split()))
    solve(a)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
from bisect import bisect_left


def solve(a):
    a.sort()
    max_cmb = cmb(a[1], a[0])
    ans = [a[1], a[0]]
    for ai in a[2:]:
        divided_ai = ai//2
        ak = a[bisect_left(a, divided_ai)]
        q = cmb(ai, ak)
        if a[1] <= ai//2:
            aj = a[bisect_left(a, divided_ai)-1]
            p = cmb(ai, aj)
            if q < p and max_cmb < p:
                ans = [ai, aj]
                max_cmb = p
            elif max_cmb < q:
                ans = [ai, ak]
                max_cmb = q
            else:
                pass

        else:
            if max_cmb < q:
                ans = [ai, ak]
                max_cmb = q

    return str(ans[0]) + ' '+str(ans[1])


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


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


Fixed submission:
from bisect import bisect_left
from sys import stdin



def solve(a):
    a.sort()
    mid = a[n-1]/2
    ai = a[bisect_left(a, mid)-1]
    aj = a[bisect_left(a, mid)]
    am = ai if abs(mid-ai) <= abs(mid-aj) else aj

    print(a[n-1], am)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, stdin.readline().split()))
    solve(a)