Problem Description
You are given a sequence of pairs of natural numbers , for from to .
A subsequence of indices is called if for every two consecutive indices and , where , the difference is divisible by
Your task is to determine the sum of the products over all non-empty clever subsequences, modulo .
Input Format
The input file contains the natural number () on the first line.
The second line contains natural numbers (), separated by spaces.
The third line contains natural numbers (), separated by spaces.
Output Format
The output must contain a single natural number, representing the sum of the products of all non-empty clever subsequences, modulo .
Scoring
| Subtask | Points | Constraints |
|---|---|---|
Examples
3 2 3 2 1 10 100
211
We have pairs: , and .