codeforces-scrape

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

318B.md (1919B)


      1 Source: https://codeforces.com/problemset/problem/318/B
      2 
      3 B. Strings of Power
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
     22 
     23 Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consecutive characters in a string) in a given text makes our hero especially joyful. Recently he felt an enormous fit of energy while reading a certain text. So Volodya decided to count all powerful substrings in this text and brag about it all day long. Help him in this difficult task. Two substrings are considered different if they appear at the different positions in the text.
     24 
     25 For simplicity, let us assume that Volodya's text can be represented as a single string.
     26 
     27 Input
     28 
     29 Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.
     30 
     31 Output
     32 
     33 Print exactly one number — the number of powerful substrings of the given string.
     34 
     35 Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 heavymetalisheavymetal
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 3
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 heavymetalismetal
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 2
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 3
     73 ```
     74 
     75 Note
     76 
     77 In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.
     78 
     79 In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".