100 atcoder#ABC129F. [ABC129F] Takahashi's Basics in Education and Learning

[ABC129F] Takahashi's Basics in Education and Learning

Score : 600600 points

Problem Statement

There is an arithmetic progression with LL terms: s0,s1,s2,...,sL1s_0, s_1, s_2, ... , s_{L-1}.

The initial term is AA, and the common difference is BB. That is, si=A+B×is_i = A + B \times i holds.

Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3,7,11,15,193, 7, 11, 15, 19 would be concatenated into 3711151937111519. What is the remainder when that integer is divided by MM?

Constraints

  • All values in input are integers.
  • 1L,A,B<10181 \leq L, A, B < 10^{18}
  • 2M1092 \leq M \leq 10^9
  • All terms in the arithmetic progression are less than 101810^{18}.

Input

Input is given from Standard Input in the following format:

LL AA BB MM

Output

Print the remainder when the integer obtained by concatenating the terms is divided by MM.

5 3 4 10007
5563

Our arithmetic progression is 3,7,11,15,193, 7, 11, 15, 19, so the answer is 3711151937111519 mod 1000710007, that is, 55635563.

4 8 1 1000000
891011
107 10000000000007 1000000000000007 998244353
39122908