#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
using graph = vector<vector<ll>>;
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
bool isp(ll n) {
  bool res = true;
  if (n == 1)
    return false;
  else {
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        res = false;
        break;
      }
    }
    return res;
  }
}
int main() {
  string S;
  cin >> S;
  ll s = S.size();
  ll ans = 0;
  ll cnt = 0;
  bool T = false;
  for (ll i = s - 1; i >= 0; i--) {
    if (S[i] == 'S') {
      cnt++;
      T = false;
    } else if (!(T) && S[i] == 'T') {
      if (cnt > 0) {
        ans += cnt;
      }
      cnt = 0;
      T = true;
      cnt--;
    } else {
      cnt--;
    }
  }
  cout << ans * 2 << endl;
}
