N = int(eval(input()))

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

MAX = 10**4

dp = [0] * (MAX+1)

dp[0] = 1

for num in nums:

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

    if dp[i] == 1 and (i + num) <= MAX*MAX:

      dp[i+num] = 1

ans = 0

for i in range(MAX+1):

  if dp[i] == 1 and i%10 != 0:

    ans = i

print(ans)

N = int(eval(input()))

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

MAX = 10**4

dp = [0] * (MAX+1)

dp[0] = 1

for num in nums:

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

    if dp[i] == 1 and (i + num) <= MAX+1:

      dp[i+num] = 1

ans = 0

for i in range(MAX+1):

  if dp[i] == 1 and i%10 != 0:

    ans = i

print(ans)

N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX + 1)
dp[0] = 1
for num in nums:
    for i in range(MAX + 1)[::-1]:
        if dp[i] == 1 and (i + num) <= MAX * MAX:
            dp[i + num] = 1
ans = 0
for i in range(MAX + 1):
    if dp[i] == 1 and i % 10 != 0:
        ans = i
print(ans)

N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX + 1)
dp[0] = 1
for num in nums:
    for i in range(MAX + 1)[::-1]:
        if dp[i] == 1 and (i + num) <= MAX + 1:
            dp[i + num] = 1
ans = 0
for i in range(MAX + 1):
    if dp[i] == 1 and i % 10 != 0:
        ans = i
print(ans)

-        if dp[i] == 1 and (i + num) <= MAX * MAX: +        if dp[i] == 1 and (i + num) <= MAX + 1: