a=list(map(int,input().split()));l=0 for i in range(5): f=False;b=False if not a[i]%3: f=True if not a[i]%5: b=True if f or b: l+=4*(f+b) else: l+=len(str(a[i])) print(l)