#include <bits/stdc++.h>
using namespace std;

int main() {
    bool ok[4] = {};
    string S;
    cin >> S;
    int ans = 0;
    int now = 0;
    for(char c : S) {
        if(c == 'L') {
            now--;
            now += 4;
            now %= 4;
        } else {
            now++;
            now %= 4;
            ok[now] = true;
            if(!now) {
                bool check = true;
                for(int i = 0; i < 4; i++) check &= ok[i];
                ans += check;
            }
        }
        if(!now) for(int i = 0; i < 4; i++) ok[i] = false;
    }
    cout << ans << endl;
    return 0;
}

