
Gimi has recently discovered a new game called Talatro. In this game, Gimi has a deck of cards, and his goal is to maximize the score obtained by playing exactly cards.
At the beginning, the score is determined by two components:
- Chips, denoted by , initialized with .
- Multiplier, denoted by , initialized with .
Each card played by Gimi can modify the values of and . There are types of cards:
- Adds to . More precisely, .
- Adds to and adds to . More precisely, .
- Adds to and multiplies by . More precisely, .
- Adds to , then adds to , and finally multiplies by . More precisely, .
The final score is calculated as the product of and . Gimi is free to choose the order in which he plays the cards. The question is: what is the maximum score he can achieve?
Task
Write a program that, given as input (the total number of cards in the deck) and the description of the cards, determines the maximum score Gimi can obtain.
Input Data
The input file contains on the first line the natural number , representing the total number of cards in the deck. The following lines each describe one card, with each line starting with the value , indicating the type of card . Depending on the type of the card, the corresponding values follow:
- For , the value is given.
- For , the values and are given.
- For , the values and are given.
- For , the values , and are given.
Output data
The output file will contain on the first line a single natural number, representing the maximum achievable score.
Restrictions
- .
- , for any .
- , for any .
| # | Points | Restrictions |
|---|---|---|
| 1 | 8 | |
| 2 | 10 | |
| 3 | 14 | |
| 4 | 18 | All cards of types and will have the same , and all cards of types and will have the same . |
| 5 | 23 | There will be no cards of type . |
| 6 | 27 | No additional restrictions. |
Example
stdin
6
1 3
1 5
2 1 1
3 1 2
4 1 1 2
3 1 3
stdout
324
Explanation
The optimal playing order is: the cards with indices and .
Initially: , .
After card 2:
After card 3:
After card 5:
After card 4:
After card 6:
Final score: .
A different order of playing these cards may lead to lower scores.