codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

632A.md (2298B)


      1 Source: https://codeforces.com/problemset/problem/632/A
      2 
      3 A. Grandma Laura and Apples
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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).
     26 
     27 For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is *p* (the number *p* is even).
     28 
     29 Print the total money grandma should have at the end of the day to check if some buyers cheated her.
     30 
     31 Input
     32 
     33 The first line contains two integers *n* and *p* (1 ≤ *n* ≤ 40, 2 ≤ *p* ≤ 1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
     34 
     35 The next *n* 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.
     36 
     37 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.
     38 
     39 Output
     40 
     41 Print the only integer *a* — the total money grandma should have at the end of the day.
     42 
     43 Note that the answer can be too large, so you should use 64-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.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 2 10  
     51 half  
     52 halfplus
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 15
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 3 10  
     65 halfplus  
     66 halfplus  
     67 halfplus
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 55
     74 ```
     75 
     76 Note
     77 
     78 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.