Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n-1,n):
    di = ls[:i]
    di.append(ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Fixed submission:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
di = ls[:]
di.append(ls[-1]//2)
di.sort()
ind = di.index(ls[-1]//2)
il,ir = -1,-1
if ind > 0:
    il = ind - 1 
if ind < n-1:
    ir = ind + 1
if il < 0 or ir < 0:
    now = max(ir,il)
else:
    if ls[-1] % 2 == 0:
        if abs(ls[-1]//2 - di[ir]) < abs(ls[-1]//2 - di[il]):
            now = di[ir]
        else:
            now = di[il]
    else:
        if min(abs(ls[-1]//2 - di[ir]),abs(ls[-1]//2 + 1 - di[ir])) < min(abs(ls[-1]//2 - di[il]),abs(ls[-1]//2 + 1 - di[il])):
            now = di[ir]
        else:
            now = di[il]
print(ls[-1],now)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    di = ls[:i]
    di.append(ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Fixed submission:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
di = ls[:]
di.append(ls[-1]//2)
di.sort()
ind = di.index(ls[-1]//2)
il,ir = -1,-1
if ind > 0:
    il = ind - 1 
if ind < n-1:
    ir = ind + 1
if il < 0 or ir < 0:
    now = max(ir,il)
else:
    if ls[-1] % 2 == 0:
        if abs(ls[-1]//2 - di[ir]) < abs(ls[-1]//2 - di[il]):
            now = di[ir]
        else:
            now = di[il]
    else:
        if min(abs(ls[-1]//2 - di[ir]),abs(ls[-1]//2 + 1 - di[ir])) < min(abs(ls[-1]//2 - di[il]),abs(ls[-1]//2 + 1 - di[il])):
            now = di[ir]
        else:
            now = di[il]
print(ls[-1],now)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import heapq
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    di = ls[:i]
    heapq.heapify(di)
    heapq.heappush(di,ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Fixed submission:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
di = ls[:]
di.append(ls[-1]//2)
di.sort()
ind = di.index(ls[-1]//2)
il,ir = -1,-1
if ind > 0:
    il = ind - 1 
if ind < n-1:
    ir = ind + 1
if il < 0 or ir < 0:
    now = max(ir,il)
else:
    if ls[-1] % 2 == 0:
        if abs(ls[-1]//2 - di[ir]) < abs(ls[-1]//2 - di[il]):
            now = di[ir]
        else:
            now = di[il]
    else:
        if min(abs(ls[-1]//2 - di[ir]),abs(ls[-1]//2 + 1 - di[ir])) < min(abs(ls[-1]//2 - di[il]),abs(ls[-1]//2 + 1 - di[il])):
            now = di[ir]
        else:
            now = di[il]
print(ls[-1],now)