n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
for i in range(n):
    if a[i] == max_a:
        a[i] = 0
print(max(a))

c3f7f539fd3f9d3c21225a8c9d4bb421bf780d8d
<mask token>

<mask token>
for i in range(n):
    if a[i] == max_a:
        a[i] = 0
print(max(a))

n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
for i in range(n):
    if a[i] == max_a:
        a[i] = 0
print(max(a))
