Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-raqamlar-yigindisi-s

Numbers with digit sum S

Hard 1000 ms 128 MB 95%
Share

A positive integer $N$ and an integer $S$ are given. How many numbers from $1$ to $N$ (inclusive) have a digit sum of exactly $S$?

A row of numbers: those whose digit sum equals the given number are highlighted

Input

One line with two integers: $N$ and $S$.

Output

One integer — the count of such numbers.

Note

$1 \le N \le 10^{18}$
$0 \le S \le 162$

Examples

Input #1
100 10
Output #1
9
Input #2
9 9
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.