var n,i,s,a: integer;
begin
readln(n);
s:=0;
for i:=1 to n do begin
readln (a);
if (a div 7 <> 0) and (a mod 10 = 3) then
s:=s+a;
end;
writeln(s);
end.
var n,i,s,a: integer;
begin
readln(n);
s:=0;
for i:=1 to n do begin
readln (a);
if (a div 7 <> 0) and (a mod 10 = 3) then
s:=s+a;
end;
writeln(s);
end.