N=int(eval(input()))

S=set([0])

for i in range(N):

    T=set(S)

    s=int(eval(input()))

    for t in T:

        S.add(t+s)

S=list(S)

S.sort()

for i in S[::-1]:

    if i%10!=0:

        print(i)

        quit()

print((0))

N=int(eval(input()))

S=[]

for i in range(N):

    s=int(eval(input()))

    S.append(s)

t=set([0])

for i in range(N):

    t_=set()

    for s in t:

        t_.add(s)

        t_.add(s+S[i])

    t=t_

ans=0

for s in t:

    if s%10==0:

        continue

    ans=max(s,ans)

print(ans)

N = int(eval(input()))
S = set([0])
for i in range(N):
    T = set(S)
    s = int(eval(input()))
    for t in T:
        S.add(t + s)
S = list(S)
S.sort()
for i in S[::-1]:
    if i % 10 != 0:
        print(i)
        quit()
print((0))

N = int(eval(input()))
S = []
for i in range(N):
    s = int(eval(input()))
    S.append(s)
t = set([0])
for i in range(N):
    t_ = set()
    for s in t:
        t_.add(s)
        t_.add(s + S[i])
    t = t_
ans = 0
for s in t:
    if s % 10 == 0:
        continue
    ans = max(s, ans)
print(ans)

-S = set([0]) +S = [] -    T = set(S) -    for t in T: -        S.add(t + s) -S = list(S) -S.sort() -for i in S[::-1]: -    if i % 10 != 0: -        print(i) -        quit() -print((0)) +    S.append(s) +t = set([0]) +for i in range(N): +    t_ = set() +    for s in t: +        t_.add(s) +        t_.add(s + S[i]) +    t = t_ +ans = 0 +for s in t: +    if s % 10 == 0: +        continue +    ans = max(s, ans) +print(ans)