Problem: You are given an integer . You have to calculate the number of binary (consisting of characters 0 and/or 1) strings meeting the following constraints.
For every pair of integers such that , an integer is given. It imposes the following constraint on the string :
- if , all characters in should be the same;
- if , there should be at least two different characters in ;
- if , there are no additional constraints on the string .
Count the number of binary strings of length meeting the aforementioned constraints. Since the answer can be large, print it modulo .
Input Format: The first line contains one integer ().
Then lines follow. The -th of them contains integers ().
Output Format: Print one integer — the number of strings meeting the constraints, taken modulo .
Note: In the first example, the strings meeting the constraints are 001, 010, 011, 100, 101, 110.
In the second example, the strings meeting the constraints are 001, 110.