#P6494. [COCI 2016/2017 #2] Go

[COCI 2016/2017 #2] Go

Description

In the game Evolve! Pokemon, Mirko has nn Pokemon. To complete their evolutions, Mirko has prepared mim_i candies for the ii-th Pokemon.

Each time he evolves the ii-th Pokemon, he must spend kik_i candies prepared for it. After the evolution is completed, Mirko will receive 22 candies of the same type as a reward. Note that each Pokemon can only use its own corresponding candies to evolve.

Mirko wants to know how many evolutions he can complete in total, and which Pokemon can be evolved the most times. If the Pokemon with the maximum number of evolutions is not unique, choose the one that appears earlier in the input.

Input Format

The first line contains an integer nn.

The next 2×n2 \times n lines:

  • Line 2×i2 \times i contains a string, the name of Mirko's ii-th Pokemon.

  • Line 2×i+12 \times i + 1 contains two integers ki,mik_i, m_i.

Output Format

The first line contains an integer, the total number of evolutions Mirko can complete.

The second line contains a string, the name of the Pokemon that can be evolved the most times.

4
Caterpie
12 33
Weedle
12 42
Pidgey
12 47
Rattata
25 71 
14
Weedle 
7
Bulbasaur
25 74
Ivysaur
100 83
Charmander
25 116
Charmeleon
100 32
Squirtle
25 1
Wartortle
100 173
Pikachu
50 154 
11
Charmander

Hint

Sample 1 Explanation

For Weedle's first evolution, Mirko spends 1212 candies, then receives 22 candies as a reward. At this time, there are 4212+2=3242 - 12 + 2 = 32 candies left for Weedle to evolve. In this way, Mirko can evolve Weedle a total of 44 times.

Similarly, Mirko can evolve Caterpies 33 times, Pidgeys 44 times, and Rattatas 33 times. In total, he can complete 1414 evolutions, which is the first part of the answer.

Among them, Weedle and Pidgeys have the most evolutions, both 44 times. Since Weedle appears earlier than Pidgeys in the input, Weedle is used as the second part of the answer.


Constraints

For 100%100\% of the testdata, 1n701 \le n \le 70, 12ki40012 \le k_i \le 400, 1mi1041 \le m_i \le 10^4.

All strings have length at most 2020, and contain only uppercase and lowercase letters.


Notes

This problem is translated from COCI2016-2017 CONTEST #2 T1 Go

Translated by ChatGPT 5