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


def calc_comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans = 0
    max_comb = 0
    sub_set = set()
    for i in range(n - 1):
        sub = a[-1] - a[i]
        if not sub in sub_set:
            sub_set.add(sub)
            comb = calc_comb(a[-1], a[i])
            if comb > max_comb:
                max_comb = comb
                ans = a[i]
    print(f'{a[-1]} {ans}')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    half_val = -(-a[-1] // 2)
    dist_list = [abs(half_val - an) for an in a[:-1]]
    min_index = dist_list.index(min(dist_list))
    print(f'{a[-1]} {a[min_index]}')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# from math import factorial
from operator import mul
from functools import reduce


def calc_comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans1 = 0
    ans2 = 0
    max_comb = 0
    for i in range(1, n):
        sub_set = set()
        for j in range(i):
            sub = a[i] - a[j]
            if not sub in sub_set:
                sub_set.add(sub)
                # comb = factorial(a[i]) // (factorial(sub) * factorial(a[j]))
                comb = calc_comb(a[i], a[j])
                if comb > max_comb:
                    max_comb = comb
                    ans1 = a[i]
                    ans2 = a[j]
    print(f'{ans1} {ans2}')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    half_val = -(-a[-1] // 2)
    dist_list = [abs(half_val - an) for an in a[:-1]]
    min_index = dist_list.index(min(dist_list))
    print(f'{a[-1]} {a[min_index]}')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial


def calc_comb(n, r):
    return factorial(n) // (factorial(n - r) + factorial(r))


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans1 = 0
    ans2 = 0
    max_comb = 0
    for i in range(1, n):
        sub_set = set()
        for j in range(i):
            sub = a[i] - a[j]
            if not sub in sub_set:
                sub_set.add(sub)
                comb = factorial(a[i]) // (factorial(sub) * factorial(a[j]))
                if comb > max_comb:
                    max_comb = comb
                    ans1 = a[i]
                    ans2 = a[j]
    print(f'{ans1} {ans2}')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    half_val = -(-a[-1] // 2)
    dist_list = [abs(half_val - an) for an in a[:-1]]
    min_index = dist_list.index(min(dist_list))
    print(f'{a[-1]} {a[min_index]}')


if __name__ == '__main__':
    main()