Allen, Nella's older brother, has a better way of building graphs; he plugs them into his graph generator! The generator takes
- An initial graph
consisting of nodes labeled from to connected by distinct undirected edges of length . - An array
of length , where if nodes labeled are producers and otherwise. - A positive integer
, the number of generation phases.
The generator then begins building the graph, happening in
For every node
To estimate the size of the graph constructed after the
Constraints
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line contains
The second line contains
The next
Output Specification
Output the sum of the lengths of the shortest paths between every pair of nodes. Since this value may be large, output it modulo
Sample Input
2 1 2
1 1
1 2
Sample Output
35
Comments