Description

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

Examples

Input:n = 13
Output:6
Explanation:

Digit 1 appears in: 1, 10, 11, 12, 13. Count: 1+1+2+1+1 = 6.

Input:n = 0
Output:0
Explanation:

No positive integers ≤ 0.

Input:n = 25
Output:9
Explanation:

Digit 1 appears in: 1, 10, 11 (twice), 12, 13, 14, 15, 16, 17, 18, 19, 21. The total count of digit 1 across all numbers from 1 to 21 is 13.

Constraints

  • 0 ≤ n ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!