N = int(eval(input()))

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

dp = {}

dp[0] = True



for s in S:

    keys = list(dp.keys())

    for k in keys:

        dp[k + s] = True



res = 0

for k in list(dp.keys()):

    if k % 10 == 0:

        continue

    res = max(res, k)



print(res)

N = int(eval(input()))

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

T = list([x for x in S if x % 10 > 0])

res = sum(S)

if res % 10 == 0:

    if len(T) == 0:

        res = 0

    else:

        res -= min(T)



print(res)

N = int(eval(input()))
S = [int(eval(input())) for i in range(N)]
dp = {}
dp[0] = True
for s in S:
    keys = list(dp.keys())
    for k in keys:
        dp[k + s] = True
res = 0
for k in list(dp.keys()):
    if k % 10 == 0:
        continue
    res = max(res, k)
print(res)

N = int(eval(input()))
S = [int(eval(input())) for i in range(N)]
T = list([x for x in S if x % 10 > 0])
res = sum(S)
if res % 10 == 0:
    if len(T) == 0:
        res = 0
    else:
        res -= min(T)
print(res)

-dp = {} -dp[0] = True -for s in S: -    keys = list(dp.keys()) -    for k in keys: -        dp[k + s] = True -res = 0 -for k in list(dp.keys()): -    if k % 10 == 0: -        continue -    res = max(res, k) +T = list([x for x in S if x % 10 > 0]) +res = sum(S) +if res % 10 == 0: +    if len(T) == 0: +        res = 0 +    else: +        res -= min(T)