Millionaire

Decide after each correct quiz answer whether to quit or continue so the expected log utility is maximal, then convert that utility into a dollar amount.

Medium6Dynamic programmingProbabilityMathNo attempts yetTime limit2sMemory limit256 MB

Problem

Congratulations, you have been picked for the TV quiz show Who Wants to Be a Millionaire. Like most people you are somewhat risk averse, so you might rather take $250,000 than a 50% chance at $1,000,000. If you happen to be rich already, the gamble looks better. Before the show you want a strategy that maximizes the expected happiness your winnings bring.

More precisely, if your present net worth is WW dollars, then winning vv dollars gives you ln(1+v/W)\ln(1 + v/W) units of happiness. The expected happiness of the game is vP(v)ln(1+v/W)\sum_v P(v) \ln(1 + v/W), where P(v)P(v) is the probability that you win vv dollars and the sum runs over every possible value of vv. Happiness units are too abstract to report, so measure the value of the game in dollars: compute DD, the guaranteed payout that makes you exactly as happy as playing the show with optimal strategy.

The show asks nn trivia questions in a fixed order. Question ii carries a prize of viv_i dollars, and your analysis of past episodes says your chance of answering it correctly is pip_i.

After a correct answer you choose to quit or to continue. If you quit right after answering question ii correctly, you win viv_i dollars, and if you continue you must attempt question i+1i+1. If you answer every question correctly, you win the prize of the last question, vnv_n dollars.

If you answer a question incorrectly, the game ends at once and you win the prize of the last question you answered correctly among those marked safe. If you never answered a safe question correctly, you win nothing.

For example, take W=4000W = 4000 with a single unsafe question whose prize is $5,000 and whose success probability is 0.50.5. The game is worth 0.5ln(1+5000/4000)0.4050.5 \ln(1 + 5000/4000) \approx 0.405 units of happiness, and a guaranteed $2,000 grants ln(1+2000/4000)0.405\ln(1 + 2000/4000) \approx 0.405 as well, so D=2000D = 2000.

Input

The first line contains two space-separated integers nn and WW (1n1051 \le n \le 10^5, 1W1061 \le W \le 10^6). Line i+1i+1 describes question ii. It starts with the string safe or unsafe, telling whether question ii is safe, followed by a real number pip_i and an integer viv_i (0pi10 \le p_i \le 1, 1vi<vi+11061 \le v_i < v_{i+1} \le 10^6).

Output

Print one line holding a $ sign immediately followed by DD, rounded to exactly two decimal places.