<reponame>Ekalaivanpj/codechef<gh_stars>1-10
n=int(input())
arr=[int(input()) for _ in range(n)]
s=0
arr.sort()
for i in range(n):
    s=max(s,arr[i]*(n-i))
print(s)

n=int(input())
arr=[int(input()) for _ in range(n)]
s=0
arr.sort()
for i in range(n):
    s=max(s,arr[i]*(n-i))
print(s)