Jimmy’s company has plantations of flowers. For each of the plantations, we know the type of flowers that are cultivated and how many tons of flowers have been produced this year. We know that the flower plantations are connected by direct roads, so that each plantation is accessible from any another and there is only one way to go from plantation to plantation , for every . In addition, we know the distance in kilometers for each of the direct connections.
Task
Jimmy wants to bring all the flowers of the same type in the same place, with minimal transport costs. If we have tons of flowers and we want to send them over a distance of kilometres, the transport cost is . For each type of flower, Jimmy wants to determine the minimal transport cost to bring all the flowers of this type together.
Input data
On the first line there will be the number , then, on the second line, small letters separated from each other by a space, which symbolize the type of flower produced
on the plantation (each type of flower is a small letter in the English alphabet).
On the third line there are integer numbers which symbolize how many tons of this flower have been produced on the plantation .
On each of the following lines, there are three natural numbers , , with the signification that there is a direct road between the plantations and , while the number , represents the distance from to .
Output data
At the standard output, the first line will display integer numbers separated from each other by a space, the integer number representing the minimal transport cost for the type of flower which is specified by the letter on the position in the English alphabet (the answers are in the order of the letters of the alphabet).
Constraints and clarifications
- Each of the numbers presented in the input is a natural number .
- The final destination of each of the transports is in one of the existing plantations.
- If a small letter does not represent the code of a flower type, then the minimal transport cost for that type is .
- For of the tests, .
- For another of the tests, .
Example
stdin
4
a b a b
2 4 4 3
1 3 4
3 4 2
1 2 5
stdout
8 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0