N = int(eval(input()))

res = set([0])

for _ in range(N):

    s = int(eval(input()))

    res |= set([r + s for r in res])

res = list(res)

res.sort()

n = len(res)

for i in range(n-1, -1, -1):

    if res[i] % 10 == 0:

        continue

    print((res[i]))

    break

else:

    print((0))
N = int(eval(input()))

S = [int(eval(input())) for _ in range(N)]

S.sort()

total = sum(S)

T = [s for s in S if s % 10 != 0]

if total % 10 != 0:

    print(total)

elif len(T) > 0:

    print((total - T[0]))

else:

    print((0))
N = int(eval(input()))
res = set([0])
for _ in range(N):
    s = int(eval(input()))
    res |= set([r + s for r in res])
res = list(res)
res.sort()
n = len(res)
for i in range(n - 1, -1, -1):
    if res[i] % 10 == 0:
        continue
    print((res[i]))
    break
else:
    print((0))

N = int(eval(input()))
S = [int(eval(input())) for _ in range(N)]
S.sort()
total = sum(S)
T = [s for s in S if s % 10 != 0]
if total % 10 != 0:
    print(total)
elif len(T) > 0:
    print((total - T[0]))
else:
    print((0))

-res = set([0]) -for _ in range(N): -    s = int(eval(input())) -    res |= set([r + s for r in res]) -res = list(res) -res.sort() -n = len(res) -for i in range(n - 1, -1, -1): -    if res[i] % 10 == 0: -        continue -    print((res[i])) -    break +S = [int(eval(input())) for _ in range(N)] +S.sort() +total = sum(S) +T = [s for s in S if s % 10 != 0] +if total % 10 != 0: +    print(total) +elif len(T) > 0: +    print((total - T[0]))