Under construction

Still being built. Things may change

Digit frequency

Interview

Time limit2sMemory limit512 MB

Summary
Count how many times a given digit d appears when writing every integer from 1 to n.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Write down every integer from 1 to nn in order. Write a program that counts how many times the single digit dd appears in what you wrote.

For example, with n=11n = 11 and d=1d = 1 you write 1 2 3 4 5 6 7 8 9 10 11. The digit 1 appears once in 1, once in 10, and twice in 11, so its frequency is 4.

Input

The first line contains a natural number nn (1≤n≤1000001 \le n \le 100000) and a single digit dd (0≤d≤90 \le d \le 9), separated by one space.

Output

Print on the first line how many times the digit dd appears across all the numbers written from 1 to nn.

Examples2

  1. Example 1

    Input
    11 1
    
    Expected output
    4
    
  2. Example 2

    Input
    100 3
    
    Expected output
    20