#include <iostream>
#include <map>
using namespace std;
int main() {
int cnt = 0;
char buf;
map<int, long long> mp;
mp[0] = 1;
while(cin >>buf) {
if(buf=='R')
cnt++;
else
cnt--;
mp[cnt]++;
}
long long answer = 0;
for(auto e: mp) {
answer += e.second*(e.second-1)/2;
}
cout <<answer;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgY250ID0gMDsKCWNoYXIgYnVmOwoJbWFwPGludCwgbG9uZyBsb25nPiBtcDsKCW1wWzBdID0gMTsKCXdoaWxlKGNpbiA+PmJ1ZikgewoJCWlmKGJ1Zj09J1InKQoJCQljbnQrKzsKCQllbHNlCgkJCWNudC0tOwoJCW1wW2NudF0rKzsKCX0KCWxvbmcgbG9uZyBhbnN3ZXIgPSAwOwoJZm9yKGF1dG8gZTogbXApIHsKCQlhbnN3ZXIgKz0gZS5zZWNvbmQqKGUuc2Vjb25kLTEpLzI7Cgl9Cgljb3V0IDw8YW5zd2VyOwp9