Threads to the Waking Cats
There is one cat at every vertex of a weighted tree. The vertices are numbered , and every edge has a positive integer length.
Initially, only the cat at vertex is awake. The remaining cats wake up in a uniformly random order, so each of the possible orders is equally likely.
When the cat at vertex wakes up, it stretches a thread along the unique tree path to a cat that was already awake and whose vertex is as close as possible to . The length of this thread is the distance between the two vertices. If several already-awake cats are tied for the minimum distance, any of them may be chosen because the thread length is the same.
Every awakened cat remains at its own vertex. Threads do not affect later choices.
Find the expected sum of the lengths of all threads.
Input
The first line contains an integer (), the number of vertices and cats.
Each of the next lines contains three integers , , and (, , ), describing an edge of length between vertices and .
Output
Let the expected total thread length be the reduced fraction . Print
where is the multiplicative inverse of modulo .
Samples
Sample 1
Input
1
Output
0
The only cat is already awake, so no thread is stretched.
Sample 2
Input
4 1 2 9 1 3 9 2 4 3
Output
499122199
For this tree, the expected total thread length is . Its value modulo is .