#P44. [KBC003D] Flu 2
[KBC003D] Flu 2
Source
This problem is adapted from Long Long OJ. All rights reserved.
Problem Background
In the distant Gensokyo, an outbreak of idiocy flu has occurred.
Problem Description
There are residents living in Gensokyo, each with a unique and distinct personal ID number ranging from to .
On the first day, people are infected, and we know their IDs. In the subsequent days, a person with ID will be infected on a certain day if and only if:
- Some resident was infected on the previous day;
- Some resident was infected on the first day (note: and can be the same here);
- and satisfy the condition: .
Each resident can be infected repeatedly! Please write a program to find out which people will be infected on the -th day.
Input Format
The first line contains three non-negative integers $K, M, NK, M, N\ (1 \le K \le 10^{18}, 3 \le M \le 1500, 0 \le N \le M - 1)$.
The second line contains distinct non-negative integers (in the range ) representing the ID's of people infected on the first day.
Output Format
Output a line with several non-negative integers (in ascending order), representing the ID's of people infected on the -th day.
Samples
1 100 3
1 2 3
1 2 3
2 100 3
1 2 3
1 2 3 4 6 9
3 101 2
5 50
24 38 63 77