You run a display advertising program. The input arrives as a series of lines, and each line couples a number of clicks with the domain those clicks came from.
Compute the total number of clicks for each domain. A click recorded against a domain also counts toward every parent domain above it, so each parent's total must include the clicks rolled up from all of its subdomains in addition to any clicks recorded against it directly.
Example
Input:
6
900,google.com
60,mail.yahoo.com
10,mobile.sports.yahoo.com
40,sports.yahoo.com
300,yahoo.com
10,stackoverflow.com
Output:
com 1320
google.com 900
mail.yahoo.com 60
mobile.sports.yahoo.com 10
sports.yahoo.com 50
stackoverflow.com 10
yahoo.com 410