If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
--------------------------------------------------------------------------------------------------------------------------------------
d={1:3,2:3,3:5,4:4,5:4,6:3,7:5,8:5,9:4,10:3,20:6,30:6,40:5,50:5,60:5,70:7,80:6,90:6,11:6,12:6,13:8,14:8,15:7,16:7,17:9,18:8,19:8}
L=[]
for i in range(1,1000):
m=0
if 20>=i>=1:
m=d[i]
elif 99>=i>=21:
if i%10==0:
m=d[i]
else :
a=int(i/10)
b=int(i%10)
m=d[a*10]+d[b]
d[i]=m
else :
c=i%100
e=int(i/100)
if c==0:
m=7+d[e]
else :
m=10+d[e]+d[c]
L.append(m)
a=sum(L)+11
print a
print L
print len(L)