B

来源:互联网 发布:数据的加密文件 编辑:程序博客网 时间:2024/05/02 00:10

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 n 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 isp (the number p is even).

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

Input

The first line contains two integers n andp (1 ≤ n ≤ 40, 2 ≤ p ≤ 1000) — the number of the buyers and the cost of one apple. It is guaranteed that the numberp is even.

The next n lines contains the description of buyers. Each buyer is described with the stringhalf if he simply bought half of the apples and with the stringhalfplus 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.

Output

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

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

Example
Input
2 10halfhalfplus
Output
15
Input
3 10halfplushalfplushalfplus
Output
55
Note

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.

题目大意

有N个人买苹果,给出每个苹果的单价,如果是Half,表示这个人买苹果的时候苹果的个数是偶数且这个人买走一半的苹果,

如果是halfplus则表示苹果的个数是奇数且这个人花买走一半的苹果再花半价买走一个苹果,求最后得到的钱

我们可以先从后面算起来得出苹果的个数,在从开头计算价钱

代码:

#include<stdio.h>#include<iostream>#include<string>using namespace std;typedef long long ll; int main(){string str[50];int n,p;cin>>n>>p;int i;for(i=0;i<n;i++)   cin>>str[i];ll num=0;for(i=n-1;i>=0;i--){if(str[i]=="half") num=num*2;else num=num*2+1;}ll sum=0;for(i=0;i<n;i++){    num/=2;if(str[i]=="half") sum+=num*p;else sum+=num*p+p/2;}printf("%lld\n",sum);return 0;}