This page is still under construction.

Parts of this page are still being built. What you see may change.

Ddong Game

Time limit1sMemory limit512 MB

Summary
Starting from 1 person, pick one of two operations per turn for N turns, optionally skipping exactly one turn, and maximize the final count while never dropping to 0 or less.
Level

Medium7 of 10

Topics
Dynamic programming, Implementation, Math
Solved
No attempts yet

Problem

This game smells so bad you cannot stand to watch it. So you will not play the ddong game yourself; you will have a program play it for you. You start with 1 person. You are given NN turns in total, and on each turn two of the following four choices are given. The same choice may be given twice. Each choice is one of +x,−x,\*x,/x (1≤x≤9)+x, -x, \*x, /x \, (1 \leq x \leq 9).

  1. If you choose +x+x, the number of people increases by xx.
  2. If you choose −x-x, the number of people decreases by xx.
  3. If you choose \*x\*x, the number of people is multiplied by xx.
  4. If you choose /x/x, the number of people is divided by xx. If the current number of people is not divisible by xx, the remainder is discarded.

For exactly one of the NN choices, you may watch an ad and skip the choice. You may also choose not to watch an ad and not to skip a choice. If, after any turn ends, the current number of people becomes 0 or less, the game is over. You must maximize the number of people after going through the NN choices. It is guaranteed that no matter what choices you make, the number of people never exceeds the 32-bit integer range along the way.

Input

The first line gives the number of choices N (1≤N≤100,000)N \, (1 \leq N \leq 100,000).

After that, NN lines each give 2 choices separated by a space.

Each choice is one of +x,−x,\*x,/x+x, -x, \*x, /x (1≤x≤91 \leq x \leq 9).

Output

Output the maximum number of people after going through the NN choices.

If the game is over no matter what choices you make, output ddong game.

Hint

In the first example, choosing +5+5 and \*2\*2 and skipping the third choice gives the maximum of 12 people.

In the second example, the game is over no matter which choices you pick.

Examples2

  1. Example 1

    Input
    3
    +5 *2
    +4 *2
    -5 /2
    
    Expected output
    12
    
  2. Example 2

    Input
    3
    +3 *6
    -8 -9
    -9 -9
    
    Expected output
    ddong game