Sum of digits

Sum every digit that appears in the decimal representations of 0 through n, where n can be as large as 10^16.

Medium6MathImplementationDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

The sum of the numbers from 0 to nn is easy to compute with the formula n(n+1)/2n(n+1)/2. That is, 0+1+2++n=n(n+1)/20 + 1 + 2 + \cdots + n = n(n+1)/2.

This problem is a little harder. What is the sum of the digits that appear in the sequence [0,1,,n][0, 1, \ldots, n]?

Write a program that computes the sum of every digit seen while counting from 0 to nn.

For n=15n = 15 you add up the digits appearing in the sequence [0,1,2,,14,15][0, 1, 2, \ldots, 14, 15]. The result is 1+2+3+4+5+6+7+8+9+1+0+1+1+1+2+1+3+1+4+1+5=661 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 + 1 + 1 + 1 + 2 + 1 + 3 + 1 + 4 + 1 + 5 = 66.

Input

A single line with an integer nn (1n10161 \le n \le 10^{16}).

Output

Print the sum of the digits in the sequence [0,1,,n1,n][0, 1, \ldots, n-1, n] on a single line.