fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. int cnt = 0;
  7. char buf;
  8. map<int, long long> mp;
  9. mp[0] = 1;
  10. while(cin >>buf) {
  11. if(buf=='R')
  12. cnt++;
  13. else
  14. cnt--;
  15. mp[cnt]++;
  16. }
  17. long long answer = 0;
  18. for(auto e: mp) {
  19. answer += e.second*(e.second-1)/2;
  20. }
  21. cout <<answer;
  22. }
Success #stdin #stdout 0s 4696KB
stdin
REEERREE
stdout
7