Don't Be Last!
Time limit2sMemory limit512 MB
Sum each of the seven cows' milk output, then report the cow with the second-smallest total, or Tie if none or several qualify.
Problem
Farmer John owns 7 dairy cows: Bessie, Elsie, Daisy, Gertie, Annabelle, Maggie, and Henrietta. He milks them every day and keeps detailed records on the amount of milk each cow provides during each milking session. Not surprisingly, Farmer John highly prizes cows that provide large amounts of milk.
Cows, being lazy creatures, don't necessarily want to be responsible for producing too much milk. If it were up to them, each would be perfectly content to be the lowest-producing cow in the entire herd. However, they keep hearing Farmer John mention the phrase "farm to table" with his human friends, and while they don't quite understand what this means, they suspect that it may not be the best idea to be the cow producing the least milk. Instead, they figure it is safer to produce the second-smallest amount of milk in the herd. Help the cows figure out which of them currently occupies this desirable position.
Input
The first line contains the integer (), the number of entries in Farmer John's milking log.
Each of the next lines contains the name of a cow (one of the seven above) followed by a positive integer (at most 100), the amount of milk the cow produced during one of its milking sessions.
Any cow that does not appear in the log at all is assumed to have produced no milk.
Output
Print on a single line the name of the cow that produces the second-smallest amount of milk. More precisely, if is the minimum total amount of milk produced by any cow, print the name of the cow whose total production is minimal among all cows that produce more than units of milk. If several cows tie for this designation, or if no cow has this designation (that is, all cows have production equal to ), print Tie. Note that if one of the seven cows is absent from the milking log, since that cow produced no milk.
Hint
In the sample, Bessie, Elsie, and Daisy tie for the minimum, each producing 7 units of milk. The next-largest production, 9 units, belongs to Henrietta.