codeforces-scrape

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

804B.md (1042B)


      1 Source: https://codeforces.com/problemset/problem/804/B
      2 
      3 B. Minimum number of steps
      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 We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
     22 
     23 The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
     24 
     25 Input
     26 
     27 The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
     28 
     29 Output
     30 
     31 Print the minimum number of steps modulo 109 + 7.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 ab
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 1
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 aab
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 3
     57 ```
     58 
     59 Note
     60 
     61 The first example: "ab"  →  "bba".
     62 
     63 The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".