doju enjoys adding new data to problems on an online judge. Watching someone fail because of the data doju added makes doju very happy.
The problem doju is preparing data for today has this input format.
The first line contains an integer n (1≤n≤maxn). The second line contains n distinct integers a1,a2,…,an (1≤ai≤maxa) in increasing order.
The correct solution first computes the greatest common divisor g of a1,a2,…,an, then computes x=an/g−n. It prints odd when x is odd and even when x is even.
Two wrong ways of computing x still get this problem right once in a while.
- x=an/g
- x=an−n
Both methods print the parity of the x they computed. Count the data files that make both methods print an answer different from the correct one. Two data files are different when n differs or the sequence differs.
Given maxn, maxa and q, write a program that computes the number of data files that make both wrong methods fail, modulo q.