#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const pair<int, int> pairs[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
pair<ll, ll> run(string* moves, size_t i, size_t N, ll X, ll Y)
{
int direction = 1;
while(++i < N)
{
switch(moves->at(i))
{
case 'F':
X += pairs[direction].first;
Y += pairs[direction].second;
break;
case 'R':
if(++direction == 5)
direction = 1;
break;
case 'L':
if(--direction == 0)
direction = 4;
break;
}
}
return {X, Y};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string moves;
getline(cin, moves);
size_t N = moves.size();
set<pair<ll, ll>> endings;
int direction = 1;
ll X = 0;
ll Y = 0;
pair<ll, ll> original_end = run(&moves, -1, N, 0, 0);
ll X2, Y2;
for(size_t i = 0;i<N;i++)
{
char original = moves[i];
ll dx = original_end.first - X;
ll dy = original_end.second - Y;
pair<char, char> PossibleMoves;
switch(original)
{
case 'F':
X2 = X - pairs[direction].first;
Y2 = Y - pairs[direction].second;
endings.insert({dy + X2, -dx + Y2}); //R
endings.insert({-dy + X2, dx + Y2}); //L
break;
case 'L':
X2 = X + pairs[direction].first;
Y2 = Y + pairs[direction].second;
endings.insert({-dx + X, -dy + Y}); //R
endings.insert({dy + X2, -dx + Y2}); //F
//PossibleMoves = {'F', 'R'};
break;
case 'R':
X2 = X + pairs[direction].first;
Y2 = Y + pairs[direction].second;
endings.insert({-dx + X, -dy + Y}); //L
endings.insert({-dy + X2, dx + Y2}); //F
//PossibleMoves = {'L', 'F'};
break;
}
/*moves[i] = PossibleMoves.first;
run(&moves, i-1, N, X, Y, &endings);
moves[i] = PossibleMoves.second;
run(&moves, i-1, N, X, Y, &endings);
moves[i] = original;*/
switch(original)
{
case 'F':
X += pairs[direction].first;
Y += pairs[direction].second;
break;
case 'R':
if(++direction == 5)
direction = 1;
break;
case 'L':
if(--direction == 0)
direction = 4;
break;
}
}
cout << endings.size() - 1;
return 0;
}