Under construction

Still being built. Things may change

Plus or Times

Interview

Time limit1sMemory limit2048 MB

Summary
Given a starting value P and N rounds where each round offers either adding c or multiplying by c, find the maximum final value.
Level

Medium5 of 10

Topics
Dynamic programming, Implementation
Solved
No attempts yet

Problem

Adrian is playing a game. When the game starts, Adrian is given PP points as his initial points. The game consists of NN rounds, numbered from 1 to NN. In round ii, Adrian has two options. Each option is one of the following two types.

+ c (−1000≤c≤1000-1000 \le c \le 1000) adds cc to his current points.

x c (−2≤c≤2-2 \le c \le 2) multiplies his current points by cc.

Adrian wants to maximize his points at the end of the game. Find the maximum points Adrian can have after completing all NN rounds.

Input

The first line contains two integers NN and PP (1≤N≤501 \le N \le 50, −1000≤P≤1000-1000 \le P \le 1000). Each of the next NN lines contains the two options of one round, separated by a space. Each option has the form T c, where TT is + or x. If TT is +, then −1000≤c≤1000-1000 \le c \le 1000. If TT is x, then −2≤c≤2-2 \le c \le 2.

Output

Print the maximum points Adrian can achieve as an integer on a single line.

Examples2

  1. Example 1

    Input
    3 123
    + 100 x 2
    + -100 x -2
    + 0 + 0
    
    Expected output
    146
    
  2. Example 2

    Input
    3 123
    + 100 x 2
    + -100 x -2
    x 0 x 0
    
    Expected output
    0