One day my teacher gave me a problem to solve. I was given N unique names and each name has a value. Name is a string consisting of lowercase Latin letters with length less than 10. Value is a positive integer less than 100. Initially these names are sorted in lexicographic order. Now if the j-th name is the prefix of the i-th name and has the max length, j is the father of i. Then numbers 1 to N form a tree. From leaf to root, each son's value should be added to father's value. After I added these values, my teacher ask me to show all these values.
Can you help me with the problem?
2 3 a ab ac 5 10 15 5 a ab abb ac b 5 10 100 15 6
30 10 15 130 110 100 15 6
Huge input, scanf is recommended.
zzxchavo @HEU