atcoder#ARC127A. [ARC127A] Leading 1s

[ARC127A] Leading 1s

Score : 300300 points

Problem Statement

For an integer xx, let f(x)f(x) be the number of leading ones in the decimal notation of xx. For example, we have f(1)=1,f(2)=0,f(10)=1,f(11)=2,f(101)=1f(1)=1,f(2)=0,f(10)=1,f(11)=2,f(101)=1.

Given an integer NN, find f(1)+f(2)++f(N)f(1)+f(2)+\cdots+f(N).

Constraints

  • 1N10151 \leq N \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

Output

Print the answer.

11
4

We have f(2)=f(3)==f(9)=0f(2)=f(3)=\cdots =f(9)=0. The answer is f(1)+f(10)+f(11)=4f(1)+f(10)+f(11)=4.

120
44
987654321
123456789