n = int(input())
ch1 = 0
ch2 = 0
maxs = 0
ost = [0, 0] * 5
for i in range(n):
x = int(input())
y = x%5; y1 = (5 - y)%5
if x % 2 == 0:
if x + ost[y1][0] > maxs and ost[y1][0] != 0:
ch1 = ost[y1][0]
ch2 = x
maxs = ch1 + ch2
if x > ost[y][0]:
ost[y][0] = x
else:
if x + ost[y1][1] > maxs and ost[y1][1] != 0:
ch1 = ost[y1][1]
ch2 = x
maxs = ch1 + ch2
if x > ost[y][1]:
ost[y][1] = x
print(ch1, ch2)