B. Fraction Conversion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a decimal fraction, that is, a number containing an integer part and a fractional part, in which both parts are written in the decimal number system. Unfortunately it may have a repeating decimal (fraction period) and working with fractions with repeating decimals is not very convenient.

A fraction with a repeating decimal is written in the format $$$a.b(c)$$$, which corresponds to $$$a.bccc\ldots$$$, where $$$c$$$ is repeated infinitely. For example, $$$1.25(13)$$$ represents the number $$$$$$1 + \tfrac{2}{10} + \tfrac{5}{10^2} + \tfrac{1}{10^3} + \tfrac{3}{10^4} + \tfrac{1}{10^5} + \tfrac{3}{10^6} + \ldots$$$$$$

Find the minimum positive base of the number system in which the same number is represented by a non-repeating fraction.

A number is represented as a non-repeating fraction in the number system with base $$$c$$$ if it can be represented as a finite sum $$$\sum\limits_{i} \frac{a_i}{c^i}$$$. In particular, we consider that for an integer the answer to the problem will be $$$c = 1$$$.

Input

The first line of input contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ separated by a space — the number of digits in the integer part, non-repeating fractional part, and the repeating part, respectively ($$$1 \le n \le 12$$$; $$$0 \le m, k \le 12$$$).

The second, third, and fourth lines contain integers $$$a$$$, $$$b$$$, and $$$c$$$ — the integer part, fractional part, and period of the number, respectively ($$$0 \le a, b, c \le 10^{12}$$$).

Note that the representation of each part can be either an empty string or a number with leading zeros, as the number of occupied positions in the number is important ($$$1.01 \neq 1.1$$$).

Output

Output a single integer — the minimum base of the number system in which the given number is represented without a repeating decimal. Print the answer by modulo $$$10^9 + 7$$$.

Scoring

Points for each subtask are awarded only if all the tests of this subtask and the required subtasks are successfully passed.

SubtaskPointsConstraintsRequired Subtasks
0examples from the statement
110$$$m = 0$$$, $$$k \le 1$$$
210$$$m \le 1$$$, $$$k \le 1$$$1
314$$$m \le 6$$$, $$$k = 0$$$
416$$$m = 0$$$, $$$k \le 6$$$1
523$$$m + k \le 12$$$0 – 4
627$$$m, k \le 12$$$0 – 5
Examples
Input
2 1 0
10
1

Output
10
Input
1 2 1
0
25
0
Output
2
Input
1 0 1
1

5
Output
3
Note

In C++, to read a string until the end, you can use std::getline.