#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    string S; cin >> S;
    int pos=0; int ans=0;
    rep(i,S.size()){
        if(S[i]=='T'){
            if(pos==0) ans++;
            else pos--;
        } 
        else pos++;
    }
    cout << ans * ans << endl;
}