CF632A.Grandma Laura and Apples

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.

She precisely remembers she had nn buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.

So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).

For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is pp (the number pp is even).

Print the total money grandma should have at the end of the day to check if some buyers cheated her.

输入格式

The first line contains two integers nn and pp ( 1<=n<=40,2<=p<=10001<=n<=40,2<=p<=1000 ) — the number of the buyers and the cost of one apple. It is guaranteed that the number pp is even.

The next nn lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.

It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.

输出格式

Print the only integer aa — the total money grandma should have at the end of the day.

Note that the answer can be too large, so you should use 6464 -bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

输入输出样例

  • 输入#1

    2 10
    half
    halfplus
    

    输出#1

    15
    
  • 输入#2

    3 10
    halfplus
    halfplus
    halfplus
    

    输出#2

    55
    

说明/提示

In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.

首页