stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.892403933515318x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.329079640258584x):
#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);

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.403997921654692x):
#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;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.1960072878754013x):
#include <iostream>

#include<string.h>

using namespace std;

string A; 

void cs()

{

	cin>>A;

	long long n=A.length();

	int *ans=new int[n+10];

	memset(ans,0,sizeof(ans));

	int i1=1,re=n,i2=0;

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

	{

		i2=i;i1=i+1;

		while(A[i2]=='S'&&A[i1]=='T')

		{

			re=re-2;ans[i2]=ans[i1]=1;

			while(ans[i2]==1&&i2>0)

			{

				i2--;

			}

			if(i2==0)

			{

				if(ans[0])

				{

					i2=i1+1;

					i1=i1+2;

				}else

				{

					i2=0;

					i1=i1+1;

				}

			}else

			{

				i1=i1+1;

			}

			i=i1-1;

		}



	}

	cout<<re<<endl;

}



int main(int argc, char** argv) 

{

    cs(); 

	return 0;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.1859866158429058x):
#include<iostream>

#include<vector>

#include<queue>

#include<string>

#include<algorithm>

#include<map>

#include<cstring>

#include<string.h>

using namespace std;

int main()

{

	string str;

	cin>>str;

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

	{

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

		{

			//cout<<str.size()<<" "<<i<<endl;

			str.erase(i,2);	

			if(i!=0)

			{

				i=i-2;

			}

			if(i==0)

			{

				i--;

			}

		}

	}

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

	return 0;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.1987935965018237x):
#include<iostream>

#include<string>

#include<algorithm>

using namespace std;

string s;

int main()

{

	cin >> s;

	int snum = 0, tnum = 0;

	int ans = s.size();

	int i = 0;

	int tag = 0;

	while (i < s.size())

	{

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

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

				snum++; i++;

			}

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

				tnum++; i++;

			}

			if (tnum >= snum) {//s用完

				ans -= snum * 2;

				snum = tnum = 0;

			}

			else {//s没用完，留给下一次

				ans -= tnum * 2;

				snum -= tnum;

				tnum = 0;

			}

		}

		else i++;

	}

	cout << ans;

	return 0;

}
// Slower C++ solution:
#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;



}

// Faster C++ solution for the same problem (measured speedup: 1.8179421322274074x):
#include<iostream>

#include<string>

#include<algorithm>

using namespace std;

string s;

int main()

{

	cin >> s;

	int snum = 0, tnum = 0;

	int ans = s.size();

	int i = 0;

	int tag = 0;

	while (i < s.size())

	{

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

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

				snum++; i++;

			}

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

				tnum++; i++;

			}

			if (tnum >= snum) {//s用完

				ans -= snum * 2;

				snum = tnum = 0;

			}

			else {//s没用完，留给下一次

				ans -= tnum * 2;

				snum -= tnum;

				tnum = 0;

			}

		}

		else i++;

	}

	cout << ans;

	return 0;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.210485403075234x):
#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;

}
// Slower C++ solution:
#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;



}

// Faster C++ solution for the same problem (measured speedup: 1.8356724803321014x):
#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;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.2101923049275987x):
#include<iostream>

#include<cstring>

using namespace std;

const int N = 2*1e5+10;

char str[N];

int pre[N];

int r,l,length, ans;

bool jud;



int main()

{

    scanf("%s",str);

    length = strlen(str);

    for(int i = 0; i < length; i++)pre[i] = i - 1;

    r = 1;

    while(r < length)

    {

        jud = false;

        while(str[l]=='S' && str[r]=='T')

        {

            ans += 2;

            if(pre[l] < 0 || r + 1 > length)

            {

                jud = true;

                break;

            }

            l = pre[l];

            r++;

            pre[r] = l;

        }

        if(pre[l] < 0 && jud)l = r + 1, r += 2;

        else l = r, r++;

    }

    printf("%d",length - ans);

    return 0;

}
// Slower C++ solution:
#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;



}

// Faster C++ solution for the same problem (measured speedup: 1.8352280039243039x):
#include<iostream>

#include<cstring>

using namespace std;

const int N = 2*1e5+10;

char str[N];

int pre[N];

int r,l,length, ans;

bool jud;



int main()

{

    scanf("%s",str);

    length = strlen(str);

    for(int i = 0; i < length; i++)pre[i] = i - 1;

    r = 1;

    while(r < length)

    {

        jud = false;

        while(str[l]=='S' && str[r]=='T')

        {

            ans += 2;

            if(pre[l] < 0 || r + 1 > length)

            {

                jud = true;

                break;

            }

            l = pre[l];

            r++;

            pre[r] = l;

        }

        if(pre[l] < 0 && jud)l = r + 1, r += 2;

        else l = r, r++;

    }

    printf("%d",length - ans);

    return 0;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.1856714373239299x):
#include<iostream>

#include<stdio.h>

#include<string.h>

#include<stack>

const int maxn=2e5+5;

using namespace std;

int main()

{

	string s;

	cin>>s;

	stack<char> q;

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

	{

		if(q.size()==0)

		{

			q.push(s[i]);

			continue;

		}

		char temp=q.top();

		if(temp=='S'&& s[i]=='T')

		{

			q.pop();

		}

else

{

q.push(s[i]);

}

	

	}

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

	return 0;

}
// Slower C++ solution:
#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;



}

// Faster C++ solution for the same problem (measured speedup: 1.7980426882322946x):
#include<iostream>

#include<stdio.h>

#include<string.h>

#include<stack>

const int maxn=2e5+5;

using namespace std;

int main()

{

	string s;

	cin>>s;

	stack<char> q;

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

	{

		if(q.size()==0)

		{

			q.push(s[i]);

			continue;

		}

		char temp=q.top();

		if(temp=='S'&& s[i]=='T')

		{

			q.pop();

		}

else

{

q.push(s[i]);

}

	

	}

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

	return 0;

}
// Slower C++ solution:
#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);

	



	

}

// Faster C++ solution for the same problem (measured speedup: 1.1849104507445773x):
#include<iostream>

#include<cstring>

#include<algorithm>

#include<stack>

using namespace std;



//const int maxn = 2 * 1e5 + 10;



int judge(string s) {

	//int mark = 0;

	stack<char>res;

	int size=s.size();

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

	{

		if(res.empty()){

			res.push(s[i]);

			continue;

		}

	    if(res.top()=='S'&&s[i]=='T'){

			res.pop();

			size=size-2;

			

		}

		else{

			res.push(s[i]);

		}

	

	}

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

		char c=res.top();

		res.pop();

	}

	return size;

}





int main() {

	string s;

	cin>>s;

    cout<<judge(s)<<endl;

	return 0;

}
// Slower C++ solution:
#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;



}

// Faster C++ solution for the same problem (measured speedup: 1.796888670085466x):
#include<iostream>

#include<cstring>

#include<algorithm>

#include<stack>

using namespace std;



//const int maxn = 2 * 1e5 + 10;



int judge(string s) {

	//int mark = 0;

	stack<char>res;

	int size=s.size();

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

	{

		if(res.empty()){

			res.push(s[i]);

			continue;

		}

	    if(res.top()=='S'&&s[i]=='T'){

			res.pop();

			size=size-2;

			

		}

		else{

			res.push(s[i]);

		}

	

	}

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

		char c=res.top();

		res.pop();

	}

	return size;

}





int main() {

	string s;

	cin>>s;

    cout<<judge(s)<<endl;

	return 0;

}