n = int(eval(input()))

s = [int(eval(input())) for _ in range(n)]

dp = [[-1 for _ in range(n*100+1)] for _ in range(n+1)]

dp [0][0] = 0

for i in range(n):

    for j in range(n*100+1):

        if dp[i][j] != -1:

            dp[i+1][j] = dp[i][j]

            dp[i+1][j+s[i]] = dp[i][j] + s[i]

res = 0

for i in range(n*100+1)[::-1]:

    if dp[n][i] > res and i % 10 != 0:

        res = dp[n][i]

        break

print(res)

n = int(eval(input()))

s = [int(eval(input())) for _ in range(n)]

dp = [[-1 for _ in range(sum(s)+1)] for _ in range(n+1)]

dp [0][0] = 0

for i in range(n):

    for j in range(sum(s)+1):

        if dp[i][j] != -1:

            dp[i+1][j] = dp[i][j]

            dp[i+1][j+s[i]] = dp[i][j] + s[i]

res = 0

for i in range(sum(s)+1)[::-1]:

    if dp[n][i] > res and i % 10 != 0:

        res = dp[n][i]

        break

print(res)

n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(n * 100 + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
    for j in range(n * 100 + 1):
        if dp[i][j] != -1:
            dp[i + 1][j] = dp[i][j]
            dp[i + 1][j + s[i]] = dp[i][j] + s[i]
res = 0
for i in range(n * 100 + 1)[::-1]:
    if dp[n][i] > res and i % 10 != 0:
        res = dp[n][i]
        break
print(res)

n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(sum(s) + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
    for j in range(sum(s) + 1):
        if dp[i][j] != -1:
            dp[i + 1][j] = dp[i][j]
            dp[i + 1][j + s[i]] = dp[i][j] + s[i]
res = 0
for i in range(sum(s) + 1)[::-1]:
    if dp[n][i] > res and i % 10 != 0:
        res = dp[n][i]
        break
print(res)

-dp = [[-1 for _ in range(n * 100 + 1)] for _ in range(n + 1)] +dp = [[-1 for _ in range(sum(s) + 1)] for _ in range(n + 1)] -    for j in range(n * 100 + 1): +    for j in range(sum(s) + 1): -for i in range(n * 100 + 1)[::-1]: +for i in range(sum(s) + 1)[::-1]: