You work in the IT department of a major league baseball team. Baseball piles up an enormous number of stats, and your job is to write the programs that handle them.
Write a program that decides who bats fourth. The fourth spot is called the clean-up position, and some managers give it to the player with the best batting average.
You are given the current batting order: nine players with their last names, their hits so far, and their at bats so far. You are then given the hits and at bats each player recorded in the next series, in the same roster order. Once the two records are added together and the averages are recomputed, the best average can belong to someone new. There are three cases.
A batting average is (total hits) / (total at bats). When several players share the best average, the order stays unchanged if the clean-up batter is one of them. Otherwise apply the rules above to the tied player who bats earliest.
The first 9 lines give the current roster in batting order: a last name, the hits H so far, and the at bats A so far, separated by spaces. A last name is a string of letters with no spaces and at most 20 characters.
The next 9 lines give, in the same order, the hits h and the at bats a from the next series.
0 ≤ H ≤ A ≤ 1000, 0 ≤ h ≤ a ≤ 1000, and every player has A + a ≥ 1.
Print the new batting order from first to ninth, one last name per line.