Ответ:
s = 0
for i in range(int(input())):
a = int(input())
if a % 3 == 0 and a % 10 == 4:
s += a
print(s)