Problem list
Log in
#coci00035 · COCI 2006/2007 Contest 6

V

Unrated 0.6 s 32 MB

Zvonko is playing with digits again, even though his mother has warned him that he is doing too much math and should go outside to play with his friends.

In his latest game, Zvonko looks for multiples of an integer $D$, composed only of certain digits. A multiple of $D$ is any number divisible by $D$.

In order to ruin Zvonko's fun, his mother decided to get a program that solves the problem. Write a program that calculates how many multiples of $D$ are between $A$ and $B$ (inclusive), such that, when written in decimal, they contain only certain allowed digits.

Input

The first line of input contains three integers $D$, $A$ and $B$ ($1 \le D \le 10,000$, $1 \le A \le B \le 10^{10}$). The second line contains the allowed digits. The digits will be given with no spaces, sorted in increasing order and without duplicates.

Output

Output the number of multiples Zvonko can make on a single line.

Example 1

Input
2 1 20
0123456789
Output
10

Example 2

Input
6 100 9294
23689
Output
111

Example 3

Input
5 4395 9999999999
12346789
Output
0
Source
COCI 2006/2007 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code