Problem p03986 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define ulli unsigned long long int
#define lli long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vi vector<int>
#define pii pair<int, int>
#define itr iterator
#define ub upper_bound
#define lb lower_bound
#define rep(lo, hi) for (lli i = lo; i < hi; i++)
#define traverse(container, it)                                                \
  for (typeof(container.begin()) it = container.begin();                       \
       it != container.end(); it++)
#define mem(a, val) memset(a, val, sizeof(a))
#define gcd __gcd
#define digits(n) (floor(log10(n)) + 1)
#define bin_1(n) __builtin_popcount(n)
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define out cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define iss(s) istringstream(s)
#define MOD 1000000007
#define PI acos(-1.0)
#define eps 1e-9
#define oo (lli)1e18 + 10
const int inf = 0x3f3f3f3f;
using namespace std;
void fastscan(int &x) {
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar())
    x = (x << 1) + (x << 3) + c - 48;
  if (neg)
    x *= -1;
}
int bin1(lli x) {
  int r = 0;
  while (x) {
    r++;
    x &= x - 1;
  }
  return r;
}
lli exgcd(lli a, lli b, lli &x, lli &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  lli x1, y1, gcd = exgcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
lli modpow(lli b, lli e, lli m) {
  lli r = 1;
  b = b % m;
  while (e > 0) {
    if (e % 2 == 1)
      r = (r * b) % m;
    e /= 2;
    b = (b * b) % m;
  }
  return r;
}
lli modinverse(lli a, lli mod) { return modpow(a, mod - 2, mod); }
lli modinverse2(lli a, lli m) {
  lli x, y;
  exgcd(a, m, x, y);
  while (x < 0)
    x += m;
  return x;
}
lli nCrmod(lli n, lli r, lli m) {
  if (r > n)
    r = n - r;
  lli res = 1;
  for (lli i = r; i >= 1; i--) {
    res = (res * (n - i + 1)) % m;
    res = (res * modinverse(i, m));
  }
  return res;
}
lli power(lli b, lli e) {
  if (e == 0)
    return 1;
  if (e % 2 == 0)
    return power(b * b, e / 2);
  return b * power(b * b, e / 2);
}
double powerf(double b, int e) {
  if (e == 0)
    return 1;
  if (e % 2 == 0)
    return powerf(b * b, e / 2);
  else {
    if (e > 0)
      return b * powerf(b * b, e / 2);
    else
      return powerf(b * b, e / 2) / b;
  }
}
lli phi(lli n) {
  lli res = n, p;
  for (p = 2; p * p <= n; p++) {
    if (n % p == 0) {
      while (n % p == 0)
        n /= p;
      res -= res / p;
    }
  }
  if (n > 1)
    res -= res / n;
  return res;
}
bool isprime(lli x) {
  if (x == 1)
    return false;
  for (lli i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
#define sievesize 1000010
bool prime[sievesize + 1];
void sieve() {
  lli x, y;
  prime[0] = prime[1] = true;
  for (x = 2; x * x <= sievesize; x++) {
    if (!prime[x])
      for (y = x * x; y <= sievesize; y += x)
        prime[y] = true;
  }
}
bool isvowel(char c) {
  if (isupper(c))
    c = tolower(c);
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
double dist(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli stringmod(string s, lli mod) {
  lli res = 0;
  for (int i = 0; i < s.size(); i++)
    res = (res * 10 + s[i] - '0') % mod;
  return res;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
void pre() {}
void gcj() { // freopen("C:\\Users\\atul5095\\Downloads\\A-small-attempt0.in","r",stdin);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-small-output.out","w",stdout);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-large.in","r",stdin);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-large-output.out","w",stdout);
  lli t;
  cin >> t;
  for (lli c = 1; c <= t; c++) {
    cout << "Case #" << c << ": ";
    cout << endl;
  }
}
#define N (int)1e5 + 10
void judge() {
  string s;
  cin >> s;
  stack<char> x;
  rep(0, s.size()) {
    if (s[i] == 'S')
      x.push('S');
    else if (x.top() == 'S')
      x.pop();
    else
      x.push('T');
  }
  cout << x.size();
}
int main() {
  ios;
  lli tt = 1;
  // cin>>tt;
  while (tt--) {
    judge();
    // gcj();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define ulli unsigned long long int
#define lli long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vi vector<int>
#define pii pair<int, int>
#define itr iterator
#define ub upper_bound
#define lb lower_bound
#define rep(lo, hi) for (lli i = lo; i < hi; i++)
#define traverse(container, it)                                                \
  for (typeof(container.begin()) it = container.begin();                       \
       it != container.end(); it++)
#define mem(a, val) memset(a, val, sizeof(a))
#define gcd __gcd
#define digits(n) (floor(log10(n)) + 1)
#define bin_1(n) __builtin_popcount(n)
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define out cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define iss(s) istringstream(s)
#define MOD 1000000007
#define PI acos(-1.0)
#define eps 1e-9
#define oo (lli)1e18 + 10
const int inf = 0x3f3f3f3f;
using namespace std;
void fastscan(int &x) {
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar())
    x = (x << 1) + (x << 3) + c - 48;
  if (neg)
    x *= -1;
}
int bin1(lli x) {
  int r = 0;
  while (x) {
    r++;
    x &= x - 1;
  }
  return r;
}
lli exgcd(lli a, lli b, lli &x, lli &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  lli x1, y1, gcd = exgcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
lli modpow(lli b, lli e, lli m) {
  lli r = 1;
  b = b % m;
  while (e > 0) {
    if (e % 2 == 1)
      r = (r * b) % m;
    e /= 2;
    b = (b * b) % m;
  }
  return r;
}
lli modinverse(lli a, lli mod) { return modpow(a, mod - 2, mod); }
lli modinverse2(lli a, lli m) {
  lli x, y;
  exgcd(a, m, x, y);
  while (x < 0)
    x += m;
  return x;
}
lli nCrmod(lli n, lli r, lli m) {
  if (r > n)
    r = n - r;
  lli res = 1;
  for (lli i = r; i >= 1; i--) {
    res = (res * (n - i + 1)) % m;
    res = (res * modinverse(i, m));
  }
  return res;
}
lli power(lli b, lli e) {
  if (e == 0)
    return 1;
  if (e % 2 == 0)
    return power(b * b, e / 2);
  return b * power(b * b, e / 2);
}
double powerf(double b, int e) {
  if (e == 0)
    return 1;
  if (e % 2 == 0)
    return powerf(b * b, e / 2);
  else {
    if (e > 0)
      return b * powerf(b * b, e / 2);
    else
      return powerf(b * b, e / 2) / b;
  }
}
lli phi(lli n) {
  lli res = n, p;
  for (p = 2; p * p <= n; p++) {
    if (n % p == 0) {
      while (n % p == 0)
        n /= p;
      res -= res / p;
    }
  }
  if (n > 1)
    res -= res / n;
  return res;
}
bool isprime(lli x) {
  if (x == 1)
    return false;
  for (lli i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
#define sievesize 1000010
bool prime[sievesize + 1];
void sieve() {
  lli x, y;
  prime[0] = prime[1] = true;
  for (x = 2; x * x <= sievesize; x++) {
    if (!prime[x])
      for (y = x * x; y <= sievesize; y += x)
        prime[y] = true;
  }
}
bool isvowel(char c) {
  if (isupper(c))
    c = tolower(c);
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
double dist(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli stringmod(string s, lli mod) {
  lli res = 0;
  for (int i = 0; i < s.size(); i++)
    res = (res * 10 + s[i] - '0') % mod;
  return res;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
void pre() {}
void gcj() { // freopen("C:\\Users\\atul5095\\Downloads\\A-small-attempt0.in","r",stdin);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-small-output.out","w",stdout);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-large.in","r",stdin);
  // freopen("C:\\Users\\atul5095\\Downloads\\A-large-output.out","w",stdout);
  lli t;
  cin >> t;
  for (lli c = 1; c <= t; c++) {
    cout << "Case #" << c << ": ";
    cout << endl;
  }
}
#define N (int)1e5 + 10
void judge() {
  string s;
  cin >> s;
  stack<char> x;
  rep(0, s.size()) {
    if (s[i] == 'S')
      x.push('S');
    else if (!x.empty() && x.top() == 'S')
      x.pop();
    else
      x.push('T');
  }
  cout << x.size();
}
int main() {
  ios;
  lli tt = 1;
  // cin>>tt;
  while (tt--) {
    judge();
    // gcj();
  }
  return 0;
}