Epidemic Flu

Time limit1sMemory limit128 MB

Problem

An epidemic flu has started spreading through the village where Sang-geun lives. The village has $M$ people, numbered $0$ to $M-1$. The flu lasts exactly one day, so a single person can catch it several times (on different days).

The flu was brought in by people who had visited another village and come back. Their numbers are all known, and on the first day exactly these people have the flu.

From the second day on, the flu spreads each day by the following rule: for every person $a$ who had the flu on the immediately preceding day and every person $b$ who had it on the first day, the person numbered $p = (a \times b) \bmod M$ catches the flu. Here $a$ and $b$ may be equal.

For example, suppose the village has $101$ people and the people infected on the first day are $5$ and $50$. On the second day the infected people are $25$, $48$ ($250 \bmod 101$), and $76$ ($2500 \bmod 101$). One of the people infected on the third day is $77$ ($(48 \times 50) \bmod 101$).

Write a program that finds everyone who has the flu on day $K$.

Input

The first line contains three integers $K$, $M$, and $N$ ($1 \le K \le 10^{18}$, $3 \le M \le 1500$, $N < M$); $N$ is the number of people infected on the first day.

The second line contains the numbers of the people infected on the first day, separated by spaces.

Output

On one line, print the numbers of the people who have the flu on day $K$, in ascending order, separated by spaces.