atcoder#EXAWIZARDS2019D. Modulo Operations
Modulo Operations
Score : points
Problem Statement
Snuke has a blackboard and a set consisting of integers. The -th element in is .
He wrote an integer on the blackboard, then performed the following operation times:
- Choose one element from and remove it.
- Let be the number written on the blackboard now, and be the integer removed from . Replace the number on the blackboard with .
There are possible orders in which the elements are removed from . For each of them, find the number that would be written on the blackboard after the operations, and compute the sum of all those numbers modulo .
Constraints
- All values in input are integers.
- are pairwise distinct.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 19
3 7
3
- There are two possible orders in which we remove the numbers from .
- If we remove and in this order, the number on the blackboard changes as follows: .
- If we remove and in this order, the number on the blackboard changes as follows: .
- The output should be the sum of these: .
5 82
22 11 6 5 13
288
10 100000
50000 50001 50002 50003 50004 50005 50006 50007 50008 50009
279669259
- Be sure to compute the sum modulo .