Kyriakos Grizzly got bored from exercising so he decided to paint his rock collection! His collection consists of
For every colour
that appears at least once, find the index of the leftmost rock with colour and the index of the rightmost rock with colour . The score is the sum of for all .
If each rock (that hasn't been painted) is painted randomly with a colour from
Constraints
All
Subtask 1 [30%]
Subtask 2 [20%]
Subtask 3 [50%]
No additional constraints.
Note: You must pass subtasks 1 and 2 in order for this subtask to run.
Input Specification
The first line will contain three space-separated integers,
The next
Output Specification
Output one integer, the expected value of the score modulo
Sample Input 1
5 2 3
1 2
3 1
5 2
Sample Output 1
5
Sample Input 2
7 4 3
2 4
5 2
4 1
Sample Output 2
210937509
Comments