N = int(eval(input()))

s = []

for i in range(N):

    s.append(int(eval(input())))

s.sort()

ssum = sum(s)

dp = [[-(10**5) for i in range(ssum+1)] for j in range(N+1)]

dp[0][0] = 0

for i in range(1,N+1):

    for j in range(ssum+1):

        if j-s[i-1] >= 0:

            dp[i][j] = max(dp[i-1][j],dp[i-1][j-s[i-1]]+s[i-1])

        else:

            dp[i][j] = dp[i-1][j]



maxa = 0

for j in range(N+1):

    for i in range(ssum+1):

        if (dp[j][i])%10 == 0:

            continue

        else:

            now = dp[j][i]

            maxa = max(maxa,now)



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

s = []

for i in range(N):

    s.append(int(eval(input())))



ssum = sum(s)

dp = [[-(10**5) for i in range(ssum+1)] for j in range(N+1)]

dp[0][0] = 0

for i in range(1,N+1):

    for j in range(ssum+1):

        if j-s[i-1] >= 0:

            dp[i][j] = max(dp[i-1][j],dp[i-1][j-s[i-1]]+s[i-1])

        else:

            dp[i][j] = dp[i-1][j]



maxa = 0

for j in range(N+1):

    for i in range(ssum+1):

        if (dp[j][i])%10 == 0:

            continue

        else:

            now = dp[j][i]

            maxa = max(maxa,now)



print(maxa)
N = int(eval(input()))
s = []
for i in range(N):
    s.append(int(eval(input())))
s.sort()
ssum = sum(s)
dp = [[-(10**5) for i in range(ssum + 1)] for j in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(ssum + 1):
        if j - s[i - 1] >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - s[i - 1]] + s[i - 1])
        else:
            dp[i][j] = dp[i - 1][j]
maxa = 0
for j in range(N + 1):
    for i in range(ssum + 1):
        if (dp[j][i]) % 10 == 0:
            continue
        else:
            now = dp[j][i]
            maxa = max(maxa, now)
print(maxa)

N = int(eval(input()))
s = []
for i in range(N):
    s.append(int(eval(input())))
ssum = sum(s)
dp = [[-(10**5) for i in range(ssum + 1)] for j in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(ssum + 1):
        if j - s[i - 1] >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - s[i - 1]] + s[i - 1])
        else:
            dp[i][j] = dp[i - 1][j]
maxa = 0
for j in range(N + 1):
    for i in range(ssum + 1):
        if (dp[j][i]) % 10 == 0:
            continue
        else:
            now = dp[j][i]
            maxa = max(maxa, now)
print(maxa)

-s.sort()