Farmer John's cows are trying to select the milking team for the world-famous Multistate Milking Match-up (MMM) competition. As you probably know, any team that produces at least gallons of milk is a winner. Each cow has the potential of contributing between and gallons of milk.(Sadly, some cows have a tendency to knock over jugs containing milk produced by other cows.) The MMM prides itself on promoting family values. FJ's cows have no doubt that they can produce gallons of milk and win the contest, but to support the contest's spirit, they want to send a team with as many parent-child relationships as possible (while still producing at least gallons of milk). Not surprisingly, all the cows on FJ's farm are female. Given the family tree of FJ's cows and the amount of milk that each would contribute, compute the maximum number of parent-child relationships that can exist in a winning team. Note that a set of cows with a grandmother-mother-daughter combination has two parent-child relationships (grandmother-mother, mother-daughter).
Lines : Line contains two space-separated integers describing cow . The first integer is the number of gallons of milk cow would contribute. The second integer (range ) is the index of the cow's mother. If the cow's mother is unknown, the second number is . The family information has no cycles: no cow is her own mother, grandmother, etc.
INPUT DETAILS:
There are cows. Cow can produce gallons and has two daughters, cow and , who can produce and gallons, respectively. Cow has a daughter (cow ) who can produce gallons. Then there's cow , who can produce gallons.