stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <fstream>

#include <cstdio>

#include <vector>

#include <map>

#include <unordered_map>

#include <set>

#include <unordered_set>

#include <stack>

#include <queue>

#include <algorithm>

#include <string.h>

#include <string>

#include <math.h>

#include <iomanip>

using namespace std;



#define SORT(v) sort((v).begin(), (v).end())

#define RSORT(v) sort((v).rbegin(), (v).rend())

#define pb push_back



typedef pair<int, int> pii;

typedef long long ll;

typedef unsigned long long ull;



const int mod = (int)1e9 + 7;

const int mod2 = 998244353;



ll exp(ll taban, ll us, ll md) {

    ll carpan = taban % md;

	if(carpan == 0) return 0;

    ll temp = us;

    ll res = 1;

    while(temp){

        if(temp % 2) res = (res*carpan) % md;

        temp /= 2;

        carpan = (carpan*carpan) % md;

    }

    return res;

}

 

ll ebob(ll a, ll b){

    if(!a)return b;

    return ebob(b%a, a);

}



ll ekok(ll a, ll b){

    return (a*b)/ebob(a, b);

}



ll mul(ll a, ll b, ll md){

	return a*b % md;

}



vector<ll> fact;

vector<ll> inv_fact;

void fact_init(int n){

	fact.resize(n+5);

	inv_fact.resize(n+5);

	fact[0] = inv_fact[0] = 1;

	for(int i = 1; i <= n; i++){

		fact[i] = (fact[i-1] * i) % mod;

		inv_fact[i] = exp(fact[i], mod-2, mod);

	}

}



ll komb(ll a, ll b){

	if(a < b) return 0;

	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;

}





const int N = 2e5+5;



int main(){

	ios::sync_with_stdio(false); cin.tie(NULL);

	string s; cin>>s;

	int bal = 0;

	int cikar = 0;

	for(int i = 0; i < s.size(); i++){

		if(s[i] == 'S') bal++;

		else if(s[i] == 'T' && bal){

			bal--;

			cikar += 2;

		}

	}

	cout<<s.size() - cikar<<endl;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main()

{

    string s;

    cin >> s;

    int size = s.size();

    int sum = 0;

    for (int i = 0; i < s.size(); i++) 

	{

        if (s[i] == 'S') 

		{

            sum++;

        }

        if (s[i] == 'T') 

		{

            if (sum > 0) 

			{

                sum--;

                size -= 2;

            }

        }

    }

    cout << size << endl;

    return 0;

}




// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

using namespace std;

int main()

{

    string s; //获取输入字符

    cin >> s;

    int totalsize = s.size();

    int num = 0;

    for (int i = 0; i < s.size(); i++) {

        if (s[i] == 'S') { //找到一个S

                num++; //S计数

        }

        if (s[i] == 'T') { //找到一个T

            if (num > 0) { //有S与之匹配

                num--; //统计

                totalsize -= 2;

            }

        }

    }

    cout << totalsize << endl; //输出结果

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



string str;

int main() {

    int s = 0, t = 0;

    cin >> str;

    int len = str.length();

    for (int i = 0; i < len; i++) {

        if (str[i] == 'S') s++;

        else s > 0 ? s-- : t++;

    }

    cout << t + s << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



string s;



int main(){

	cin>>s;

	int open=0,sumT=0,banyakT=0;

	for(int i=0; i<s.length(); i++){

		if(s[i]=='S'){

			open++; 

		}

		if(s[i]=='T'&&open>0){

			open--; sumT++;

		}

		if(s[i]=='T')banyakT++;

	}

	cout<<open+banyakT-sumT<<'\n';

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



string X,ans;

stack<char> stc;



int main(){

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

    cin>>X;

    for(int i = 0;i < X.length();i++){

        if(stc.empty()){

            stc.push(X[i]);

        }

        else if(!(stc.top() == 'S' && X[i] == 'T')){

            stc.push(X[i]);

        }

        else {

            stc.pop();

        }

    }

    cout<<stc.size()<<endl;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 200002



char s[N], x, y;

int p[N];



int main()

{	 

	int i, j, tp, l;

	

	s[0] = 0;

	scanf("%s", s + 1);

	for(i = 1, j = 0; s[i]; j = i++){

		p[i] = j;

	}

	p[i] = j, l = i - 1;

	for(i = 2; x = s[i]; i++){

		if(x == 'T'){

			if(s[tp = p[i]] == 'S'){

				l -= 2;

				p[i + 1] = p[tp];

			}

		}

	}

	printf("%d\n", l);

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <stack>

#include <string>

using namespace std;



int main(){

	string X;

	char ch[2000000];

	

	stack <char> first;

	stack <char> second;



	cin >> ch;

	X = ch;



	for(int i=0; i<X.size(); i++){

		if(first.size() == 0){

			first.push(X[i]);

		}

		else{

			if(first.top() == 'S' && X[i] == 'T'){

				first.pop();

				second.push(X[i]);

			}

			else{

				first.push(X[i]);

			}

		}

	}

	

	cout << first.size();



	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<vector>

using namespace std;

vector<char> Q;

int main()

{

	char s[200005];

	scanf("%s",s);//字符串

	int len=strlen(s);

	//printf("%d\n",len);

	for(int i=0;i<len;i++){

		if(!Q.empty()&&s[i]=='T'&&Q.back()=='S'){

			//把S拿出来

			Q.pop_back();

		}

		else

			Q.push_back(s[i]);//入数组

	}

	int cnt=0;

	while(!Q.empty()){

		Q.pop_back();

		cnt++;

	}

	printf("%d\n",cnt);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <string>

#include <cstring>

#include <stdlib.h>

#include <math.h>

#include <algorithm>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <list>

#include <iterator>

#include <assert.h>

#pragma warning(disable:4996) 

 

typedef long long ll;

#define MIN(a, b) ((a)>(b)? (b): (a))

#define MAX(a, b) ((a)<(b)? (b): (a))

#define LINF 9223300000000000000

#define INF 2140000000

const long long MOD = 1000000007;

//const long long MOD = 998244353;

using namespace std;



char str[200005];



void solve()

{

    scanf("%s", str);

    int n=strlen(str);

    vector<int> v;

    int i;

    for(i=0; i<n; i++) {

        if(str[i]=='S') {

            v.push_back(0);

        }

        else {

            if(!v.empty() && v.back()==0) {

                v.pop_back();

            }

            else {

                v.push_back(1);

            }

        }

    }

    printf("%d\n", (int)v.size());



    return;

}



int main(int argc, char* argv[])

{

#if 1

    solve();

#else

    int T; scanf("%d", &T);

    while(T--) {

        solve();

    }

#endif

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <string>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <algorithm>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <list>

#include <iterator>

#include <cassert>

#include <numeric>

#include <functional>

//#include <numeric>

#pragma warning(disable:4996) 

 

typedef long long ll;

typedef unsigned long long ull;

#define MIN(a, b) ((a)>(b)? (b): (a))

#define MAX(a, b) ((a)<(b)? (b): (a))

#define LINF  9223300000000000000

#define LINF2 1223300000000000000

#define INF 2140000000

const long long MOD = 1000000007;

//const long long MOD = 998244353;



using namespace std;



char str[200005];





void solve()

{

    scanf("%s", str);

    int n = strlen(str);

    int cntT = 0, cntS = 0;;

    int i;

    for (i = 0; i < n; i++) {

        if (str[i] == 'S') {

            cntS++;

        }

        else {

            if (cntS) cntS--;

            else cntT++;

        }

    }

    printf("%d\n", cntS + cntT);



    return;

}





int main(int argc, char* argv[])

{

#if 1

    solve();

#else

    int T;

    scanf("%d", &T);

    int t;

    for(t=0; t<T; t++) {

        //printf("Case #%d: ", t+1);

        solve();

    }

#endif

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main(){	

    string X;

    cin >> X;

    int ans=X.length();

    int cnt=0,i;

    for(auto i:X){

        if (i=='S'){

            ++cnt;

        } 

        else{

            if (cnt>0){

                --cnt;

                ans-=2;

            }

            else{

                cnt=0;

            }

        }

    }	

    cout<<ans<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char x[200002];

int n,sums,sumt,ans;

int main()

{

	scanf("%s",x);

	ans=n=strlen(x);

	for(int i=0;i<n;i++)

	{

		if(x[i]=='S')sums++;

		else	if(sums)sumt++;

		if(sums>=sumt)

		{

			ans-=sumt*2;

			sums-=sumt;

			sumt=0;

		}

	}

	printf("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;



/*

 <url:https://agc005.contest.atcoder.jp/tasks/agc005_a>

 問題文============================================================

 文字列 X が与えられます。X の長さは偶数であり、半分は S 、もう半分は T からなります。

 

 高橋君は ST という文字列が苦手です。なので以下の操作を 10^10000 回行うことにしました。

 

 X の(連続な)部分文字列で ST となるもののうち、最も左側にあるものを取り除く。存在しないならば何もしない。

 最終的に X は何文字になるかを求めてください。

 

 =================================================================

 

 解説=============================================================

 

 問題名 STring

 

 STはstackの ST

 よってstack

 

 stackで一つ手前の文字を確認しつつ左から右へなめる

 ================================================================

 */

int main(void) {

    cin.tie(0); ios::sync_with_stdio(false);

    string X; cin >> X;

    stack<string> st;

    for(int i = 0; i < (int)X.length(); i++){

        if(X[i] == 'S') st.push("S");

        else{

            if(!st.empty()){

                string c = st.top();

                if(c == "S") {

                    st.pop();

                    continue;

                }

            }

            st.push("T");

        }

    }

    cout << st.size() << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>



const int N=200000;



int del,t,len;

char s[N+5];



int main()

{

	scanf("%s",s+1);

	len=strlen(s+1);

	for(int i=1;i<=len;i++)

	{

		if(s[i] == 'S')

			t++;

		else

			t?t--,del+=2:1;

	}

	printf("%d\n",len-del);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<stdio.h>

#include<vector>

#include<set>

#include<algorithm>

using namespace std;

typedef long long ll;



char str[200005];

int main()

{

	for (int i = 0; i < 200005; i++)

	{

		str[i] = '+';

	}

	cin >> str;

	/*int left, right;

	left = 0;

	right = 1;

	while (str[right] != '+')

	{

		if (str[left] == 'S' && str[right] == 'T')

		{

			str[left] = '+';

			str[right] = '+';

			bool findout=

			if (left == 0)

			{

				left = right + 1;

				right = right + 2;

			}

			else

			{



			}

		}

		else if()



	}

	*/

	int i = 0;

	for (; i < 200005; i++)

	{

		if (str[i] == '\0')

			break;

	}

	int counts, countt;

	counts = 0, countt = 0;

	for (int j = i-1; j >=0; j--)

	{

		if (str[j] == 'T')

		{

			countt++;

		}

		if (str[j] == 'S' && countt > 0)

		{	

			counts++;

			countt--;

	    }

		

	}

	cout << i-(counts*2);

	



	

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

char str[200000 + 10];

int main() {

	scanf("%s", str);

	int len = strlen(str);

	int pos = 0,p=0;

	int num_t = 0,num_s=0;

	for (int i = 0;i < len;i++) {

		if (str[i] == 'S') num_s++;

		else if (num_s) {

			num_s--;

			p++;

		}

	}

	printf("%d", len-2*p);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

using namespace std;



struct ST

{

	int S;

	int T;



	ST()

	{

		S = T = 0;

	}

};



int main()

{

	string str;

	cin >> str;

	ST st[100005];

	int j = 0;

	for (int i = 0; i < str.size(); i++)

	{

		if (str[i] == 'S')

		{

			st[j].S++;

			i++;

			while (i < str.size()&&str[i] == 'S')

			{

				st[j].S++;

				i++;

			}

			i--;

		}

		else

		{

			st[j].T++;

			i++;

			while (i < str.size() && str[i] == 'T')

			{

				st[j].T++;

				i++;

			}

			i--;

			j++;

		}

	}



	int ans = str.size();

	int ys = 0;

	for (int i = 0; i < j; i++)

	{

		ys += st[i].S;

		if (ys <= st[i].T)

		{

			ans -= ys * 2;

			ys = 0;

		}

		else 

		{

			ans -= st[i].T * 2;

			ys -= st[i].T;

		}

	}

	cout << ans << endl;



}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

char str[200000 + 10];

int main() {

	scanf("%s", str);

	int len = strlen(str);

	int pos = 0,p=0;

	int num_t = 0,num_s=0;

	for (int i = 0;i < len;i++) {

		if (str[i] == 'S') num_s++;

		else if (num_s) {

			num_s--;

			p++;

		}

	}

	printf("%d", len-2*p);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>



using namespace std;



string str;



int main ()

{

    cin >> str;



    for (int i = 0; i + 1 < str.size (); ++i)

    {

        if (str[i] == 'S' && str[i + 1] == 'T')

        {

            for (; i + 1 < str.size () && str[i] == 'S' && str[i + 1] == 'T'; )

                str.erase (i, 2);



            i = max (i - 2, -1);

        }

    }



    cout << str.size () << '\n';



    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>



using namespace std;



int prv[200010];

char str[200010];



int main ()

{

    fgets (str + 1, 200010, stdin);



    int n = strlen (str + 1) - 1;

    for (int i = 1; i <= n; ++i)

        prv[i] = i - 1;



    int lg = n;

    for (int i = 1; i <= n; ++i)

    {

        for (; i <= n && str[i] == 'T' && str[prv[i]] == 'S';)

        {

            lg -= 2;

            prv[i + 1] = prv[prv[i]];

            ++i;

        }

    }



    printf ("%d\n", lg);



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

using namespace std;

string x;

int sum,ans;

int main()

{

	cin>>x;

	int len=x.length();

	ans=len;

	for(int i=0;i<len;i++)

	{

		if(x[i]=='S')

		  sum++;

		else

		{

			sum--;

			if(sum>=0)

			  ans-=2;

			else sum=0;

		}

	}

	cout<<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e6+5;

char s[N];

int cs, ct, ans;

int main()

{

    scanf("%s", s);

    for(int i = 0; s[i]; ++i)

    {

        if(s[i] == 'S') ++cs;

        else if(cs) --cs;

        else ++ct;

    }

    printf("%d\n", cs+ct);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int i,j,s;

char a[1000000],b;

int main() {

	while((b=getchar())!='\n'){

		s++;

		if(b=='S')

			a[i++]=b;

		if(b=='T')

			a[i++]=b;

		if(a[i-2]=='S'&&a[i-1]=='T'){

			s-=2;

			i-=2;

		}

	}

	cout<<s;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e6+5;

char s[N];

int cs, ct, ans;

int main()

{

    scanf("%s", s);

    for(int i = 0; s[i]; ++i)

    {

        if(s[i] == 'S') ++cs;

        else if(cs) --cs;

        else ++ct;

    }

    printf("%d\n", cs+ct);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

string st;

int sumt,sums,sum,i;

int main()

{

    std::ios::sync_with_stdio(false);

    cin>>st;

    while(i<st.size())

    {

        if(st[i]=='S') sums++;

        else if(sums) sumt++;

        if(sums>=sumt)

        {

            sum+=min(sums,sumt)*2;

            sums-=min(sums,sumt);

            sumt=0;

        }

        i++;

    }

    cout<<st.size()-sum<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e6+5;

char s[N];

int cs, ct, ans;

int main()

{

    scanf("%s", s);

    for(int i = 0; s[i]; ++i)

    {

        if(s[i] == 'S') ++cs;

        else if(cs) --cs;

        else ++ct;

    }

    printf("%d\n", cs+ct);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int sum,sum1;

int main() {

	string s;

	cin>>s;

	for(int i=0; i<s.size(); i++) {

		if(s[i]=='S') {

			sum++;

		}

		if(sum>0&&s[i]=='T') {

			sum1+=2;

			sum--;

		}

	}

	cout<<s.size()-sum1<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e6+5;

char s[N];

int cs, ct, ans;

int main()

{

    scanf("%s", s);

    for(int i = 0; s[i]; ++i)

    {

        if(s[i] == 'S') ++cs;

        else if(cs) --cs;

        else ++ct;

    }

    printf("%d\n", cs+ct);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

#include<stack> 

using namespace std;

inline int read(){

	int f=1,ans=0;char c=getchar();

	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}

	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}

	return f*ans;

}

const int MAXN=200011; 

stack<int> que;

char str[MAXN];

int len;

int main(){

	scanf("%s",str+1);

	len=strlen(str+1);

	for(int i=1;i<=len;i++){

		if(str[i]=='S') que.push(i);

		else{

			if(!que.empty()){

				if(str[que.top()]=='S') que.pop();

				else que.push(i);

			}

			else que.push(i);

		}

	}printf("%d\n",que.size());

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e6+5;

char s[N];

int cs, ct, ans;

int main()

{

    scanf("%s", s);

    for(int i = 0; s[i]; ++i)

    {

        if(s[i] == 'S') ++cs;

        else if(cs) --cs;

        else ++ct;

    }

    printf("%d\n", cs+ct);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main() {

    string s;

    cin >> s;

    int ans = s.size(), cnt = 0;

    for (int i = 0; i < s.size(); i++){

        if (s[i] == 'S')

            cnt ++;

        if (s[i] == 'T' && cnt > 0){

            ans -= 2;

            cnt --;

        }

    }

    cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200010

#define Abs(a) a>0?a:-a

char s[MAXN];

int n,ls,ans;

int main()

{

	scanf("%s",s);

	int n=strlen(s);

	for(int i=0;i<n;i++)

		if(ls==0&&s[i]=='T')

			ans++;

		else if(s[i]=='T')

			ls++;

		else if(s[i]=='S')

			ls--;

	ans+=Abs(ls);

	printf("%d\n",ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*   In The Name Of God   */

// Hunt...

/*

ID: alimora2

LANG: C++11

TASK: PROB

*/

#include <bits/stdc++.h>



#define sqr(A) (A) * (A)

using namespace std;

typedef long long ll;



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	string s;

	int ans;

	stack<char> t;

	cin >> s;

	ans = s.size();

	for (int i = 0; i < s.size(); i++) {

		if (s[i] == 'S')

			t.push(s[i]);

		if (!t.empty() && s[i] == 'T') {

			t.pop();

			ans -= 2;

		}

	}

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200010

#define Abs(a) a>0?a:-a

char s[MAXN];

int n,ls,ans;

int main()

{

	scanf("%s",s);

	int n=strlen(s);

	for(int i=0;i<n;i++)

		if(ls==0&&s[i]=='T')

			ans++;

		else if(s[i]=='T')

			ls++;

		else if(s[i]=='S')

			ls--;

	ans+=Abs(ls);

	printf("%d\n",ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//In the name of God

#include<bits/stdc++.h>



using namespace std;



const int N = 2e5 + 10;

string s;

int n, cnt;



int main(){

	cin >> s;	n = s.size();

	for(auto c : s){

		if(c == 'S')

			cnt++;

		else if(cnt){

			cnt--;

			n -= 2;

		}

	}

	cout << n;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200010

#define Abs(a) a>0?a:-a

char s[MAXN];

int n,ls,ans;

int main()

{

	scanf("%s",s);

	int n=strlen(s);

	for(int i=0;i<n;i++)

		if(ls==0&&s[i]=='T')

			ans++;

		else if(s[i]=='T')

			ls++;

		else if(s[i]=='S')

			ls--;

	ans+=Abs(ls);

	printf("%d\n",ans);

}


// Fastest known solution for this problem: