Under construction

Still being built. Things may change

Adding Parentheses 2

Interview

Time limit0.5sMemory limit512 MB

Summary
Place non-nested parentheses around single operators in a digit-operator expression to make its value as large as possible.
Level

Medium7 of 10

Topics
Dynamic programming, Math, Brute force
Solved
No attempts yet

Problem

There is an expression of length NN. The expression consists of integers between 00 and 99 inclusive and the operators +, -, and ×. Because multiplication has higher precedence than addition and subtraction, multiplication must be evaluated first. When evaluating an expression, it must be evaluated from left to right. For example, the result of 3+8×7−9×23+8×7-9×2 is 4141.

If parentheses are added to the expression, the subexpression inside the parentheses must be evaluated first. However, each pair of parentheses must contain exactly one operator. For example, if parentheses are added to 3+8×7−9×23+8×7-9×2 as (3+8)×7−(9×2)(3+8)×7-(9×2), the result is 5959. Nested parentheses are not allowed. That is, 3+((8×7)−9)×23+((8×7)-9)×2 and 3+((8×7)−(9×2))3+((8×7)-(9×2)) are not valid expressions because they contain parentheses inside parentheses.

Given an expression, write a program to find the maximum possible result of an expression that can be made by adding parentheses appropriately. There is no limit on the number of parentheses added, and none have to be added.

Input

The first line gives the length of the expression, N(1≤N≤19)N(1 ≤ N ≤ 19). The second line gives the expression. Every integer in the expression is between 00 and 99 inclusive. The string starts with an integer, and operators and integers alternate. Each operator is one of +, -, *. Here * denotes the × operation, which is multiplication. Because only valid expressions are given, NN is odd.

Output

On the first line, print the maximum possible result of an expression obtained by adding parentheses appropriately. The answer is less than 2312^{31} and greater than −231-2^{31}.

Examples5

  1. Example 1

    Input
    9
    3+8*7-9*2
    
    Expected output
    59
    
  2. Example 2

    Input
    5
    8*3+5
    
    Expected output
    64
  3. Example 3

    Input
    7
    8*3+5+2
    
    Expected output
    66
    
  4. Example 4

    Input
    19
    1*2+3*4*5-6*7*8*9*0
    
    Expected output
    100
    
  5. Example 5

    Input
    19
    1*2+3*4*5-6*7*8*9*9
    
    Expected output
    -27116