fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. string s;
  10. if (!(cin >> s)) return 0;
  11. int n = (int)s.size();
  12. long long ans = 0;
  13. int last = -1; // last start index of counted "bear"
  14. for (int i = 0; i + 3 < n; ++i) {
  15. if (s[i] == 'b' && s[i+1] == 'e' && s[i+2] == 'a' && s[i+3] == 'r') {
  16. long long leftChoices = (long long)(i - last);
  17. long long rightChoices = (long long)(n - (i + 3));
  18. ans += leftChoices * rightChoices;
  19. last = i;
  20. }
  21. }
  22. cout << ans << '\n';
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty