Misc [II]


Miscellaneous [II]

Treetown is a town of various suburbs connected by main roads. The roads have been constructed in such a way that:

  • Every suburb can be reached by taking these roads from suburb to suburb
  • Between any two suburbs, there is only a single path connecting the two
  • All roads are bidirectional

The nature of this construction means that a single road failure leads to a disconnection of the town, causing major delays. You'd like to analyse the possible impact of removing a road from Treetown.

Every road in Treetown has a distance djd_j. For any pair of suburbs a,ba, b in Treetown, we compute the contribution to the Treetown economy as

∑i∈Rdi\sum_{i \in R} d_i

Where RR is the collection of roads on the path from aa to bb. For example, take the following graph, with 4 suburbs, a,b,c,da, b, c, d and 3 roads from aa to bb, bb to cc and cc to dd, of lengths 1, 3 and 4.

Then for the suburb pairing aa and cc, the contribution to productivity is

1+3=4,1 + 3 = 4,

summing the roads from aa to bb and bb to cc.

In this problem, we want you to assess the reduction in productivity after removing a single road (in other words, summing the productivity contribution of suburb pairings that are connected via the removed road.)

For example, removing the edge bb to cc would remove pairings acac, adad, bcbc, bdbd, which contribute 4+8+3+7=224 + 8 + 3 + 7 = 22 productivity.

Input

Input will begin with a single integer NN, representing the number of suburbs. N−1N-1 lines will follow. Each line will contain 3 space separated integers, ii jj and dd. This means there is a road from ii to jj of distance dd.

Finally, a single integer xx will follow. This represents a (1-indexed) index of one of the roads just inputted.

Output

Output should contain a single integer - the hit to productivity removing road xx would cause.

Constraints

  • 1≤N≤2×1051 \leq N \leq 2\times 10^5
  • 1≤d≤1031 \leq d \leq 10^3

Example

Input

Taking the example in the statement, this can be written as:

Input 1
4
1 2 1
2 3 3
3 4 4
2
Output

For which the output should be

Output 1
22

as discussed previously.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.