#P10269. 实力派
实力派
Background

Problem Description
There are OIers from all over the country who form a team called "实力派" (shílìpài). Each person has a strength value . There are contests that send them invitations. In the -th contest, they are required to form a team of people to participate. To decide whether they should join a contest, they came up with the following two measures of strength:
-
Define the -th order minimum strength as the number of ways to choose people from these people such that the of the chosen people's strength values;
-
Define the -th order maximum strength as the sum of the of the chosen people over all possible choices.
For each contest, please tell them the -th order minimum strength and maximum strength for that contest. Also, to keep others from understanding, you need to take the answers modulo a secret modulus .
Input Format
The first line contains three integers , representing the number of team members, the number of contests, and the secret modulus, respectively.
The second line contains integers. The -th integer represents the strength value of the -th person.
The next lines each contain one integer , meaning the required number of participants for the -th contest.
Output Format
Output lines. The -th line contains two integers , representing the minimum strength and maximum strength in the -th contest, with answers taken modulo .
4 4 998244353
8 15 12 6
2
3
4
5
1 19
2 7
1 1
0 0
6 4 19260817
11 45 14 19 19 810
2
1
2
2
12 78
0 918
12 78
12 78
8 3 19491001
3 2 2 3 1 2 1 2
5
3
4
56 56
52 60
69 71
Hint
Sample Explanation
In the first contest, they need to choose people. Only the choice has , so the minimum strength is . The sum of over all choices is , so the maximum strength is .
In the second contest, they need to choose people. There are two choices with : and . Therefore, the minimum strength is . The sum of over all choices is , so the maximum strength is .
Constraints
For all data, , , , and .
This problem has a total of test points and uses bundled tests. The subtasks and test point distribution are as follows:
| Subtask ID | Test Point ID | Special Property | Score | Time Limit |
|---|---|---|---|---|
| No special property |
Hint
denotes the set of all prime numbers, and denotes the greatest common divisor.
Translated by ChatGPT 5