x=gets.split puts x.inject(0){|s,e| d=e.to_i s+([e.length,4,4,8][(d%5==0?2:0)+(d%3==0?1:0)]) }