#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll cs[200005], ct[200005];
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < ((ll)(s).size()); i++) {
    if (i > 0) cs[i] = cs[i - 1];
    if (s[i] == 'S')
      cs[i]++;
    else
      cs[i] = 0;
  }
  for (int i = ((ll)(s).size()) - 1; i >= 0; i--) {
    if (i < ((ll)(s).size()) - 1) ct[i] = ct[i + 1];
    if (ct[i + 1] == 'S') ct[i] = 0;
    if (s[i] == 'T') ct[i]++;
  }
  ll ans = ((ll)(s).size());
  ll nu = 0;
  for (int i = 0; i < ((ll)(s).size()) - 1; i++) {
    if (s[i] == 'S' && s[i + 1] == 'T') {
      nu += min(ct[i], cs[i]) * 2;
    }
  }
  cout << ans - nu << "\n";
  return 0;
}
