a = []
while 1:
n = int(input())
if not n: break # n == 0
a.append(n)
print(sum(i for i in a if not i%4 and i%10==8))
a = []
while 1:
n = int(input())
if not n: break # n == 0
a.append(n)
print(sum(i for i in a if not i%4 and i%10==8))