For any real number , define as the distance from to its nearest integer.
Let be positive integers and consider the function defined on the real inteval by:
For example, when we get the blancmange function shown bellow
Given a polynomial , where are integers. Let
It can be proved that is a rational number, therefore we can write it as where and are integers.
In addition, the constraints on the inputs guarantee that is not divisible by the prime number .
In this case, find modulo ( is the the inverse of modulo ).
The first line of each test file contains three space-separated integers , and .
The next line contains space-separated integers .