Under construction

Still being built. Things may change

N-Concatenation

Interview

Time limit1.5sMemory limit1024 MB

Summary
Given N and K, find the remainder when the concatenation 123...N of the integers 1 through N is divided by K.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

In base 10, the number 123⋯N‾\overline{123\cdots N} formed by writing the positive integers 11, 22, 33, ⋯\cdots, NN in order is called the NN-concatenation. For example, 1234512345 is the 55-concatenation, and 1234567891011121312345678910111213 is the 1313-concatenation. Given NN and an integer KK, find the remainder when the NN-concatenation is divided by KK.

Input

The first line contains integers NN and KK separated by a space. (1≤N≤1071 \le N \le 10^7, 1≤K≤1091 \le K \le 10^9)

Output

Print the remainder when the NN-concatenation is divided by KK on the first line.

Examples3

  1. Example 1

    Input
    5 7
    
    Expected output
    4
    
  2. Example 2

    Input
    10000000 1
    
    Expected output
    0
    
  3. Example 3

    Input
    10000000 12341234
    
    Expected output
    11927308