stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <string>

using namespace std;

int main()

{

    string s;

    cin >> s;

    int size = s.size();

    int sum = 0;

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

	{

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

		{

                sum++;

        }

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

		{

            if (sum > 0) 

			{

                sum--;

                size -= 2;

            }

        }

    }

    cout << size << endl;

    return 0;

}

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

}
// Slower C++ solution:
#include <iostream>

#include <string>



using namespace std;



int main()

{

	string str;

	cin>>str;

	char a[200200];

	a[0]='Q';

	int length=0;

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

	{

	    if(str[i]=='T'&&a[length]=='S')

	    {

	    	length--;

		}

		else

		{

			length++;

			a[length]=str[i];

		}

	}

	cout<<length;

	return 0;

}

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

}
// Slower C++ solution:
#include <iostream>

#include <string.h>

using namespace std;

void trim(string &s)

{

    int index = 0;

    if( !s.empty())

    {

        while( (index = s.find(' ',index)) != string::npos)

        {

            s.erase(index,1);

        }

    }



}

int main()

{

	string h;

	cin>>h;

	int panduan=0;

	int length;

	

	while(panduan==0)

	{

		panduan=1;

		length=h.size()-1;

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

		{

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

			{

				int l=i;int r=i+1;

				while(l>=0 && r<length+1 && h[l]=='S' && h[r]=='T')

				{

					h[l]=' ';h[r]=' ';

					l--;r++;

				}

				panduan=0;

			}

		}

		trim(h);

	}

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

}

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

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

string X;

stack<int> sta;

int child=0;

int main(){

	cin>>X;

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

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

			sta.push(1);

		else{

			if(!sta.empty()){

				child+=2;

				sta.pop();

			}

		}

	}

	cout<<X.size()-child<<endl;

	return 0;

}


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

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char c[200000+5];

int main()

{

//	gets(c);

	scanf("%s",c);

	int len=strlen(c);

	stack<char>ans;

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

		if(ans.empty()){

			ans.push(c[i]);

			continue;

		}

		if(ans.top()=='S'&&c[i]=='T'){

			ans.pop();

		}

		else{

			ans.push(c[i]);

		}

	}

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

	return 0;

 } 

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

}
// Slower C++ solution:
#include<iostream>

#include<string>

using namespace std;





int main(void){

	string str;

	cin>>str;

	int len=str.size();

	for(int i=0;i<len-1;){

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

			int temp=i;

			str.erase(i,2);

			if(temp>0)

				i=temp-1;

			else

				i=temp;

			len=str.size();

		}

		else i++;

	}

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



	return 0;

}

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

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

using namespace std;

char c[200001];

int cc[200001];

int main(){

	cin>>c;

	//cout<<strlen(c)<<endl;

	int length=strlen(c);

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

			if(!cc[i]&&c[i]=='S'){

				for(int y=i+1;y<length;y++){

					if(!cc[y]&&c[y]!='T'){

						break;

					}else if(!cc[y]&&c[i]=='S'&&c[y]=='T'){//cout<<i<<' '<<y<<endl;

							cc[i]=1;cc[y]=1;

							

							

							for(int n=1,m=1;n<=i&&y+m<length;){

								while(n<=i&&cc[i-n]){if(cc[i-n])n++;

								}

								while(y+m<length&&cc[y+m])if(cc[y+m])m++;

								if(!cc[i-n]&&!cc[y+m]&&c[i-n]=='S'&&c[y+m]=='T'){//cout<<"s"<<i-n<<' '<<y+m<<endl;

									cc[i-n]=1;cc[y+m]=1;

								}else{//i=y+n;

									break;

								}

							}

							break;

					}

				}

			}

		}

	int ans=0;

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

		//cout<<cc[i]<<endl;

		if(!cc[i]){

			ans++;

		}

	}

	cout<<ans<<endl;

} 

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

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

using namespace std;



char c[200099];

int main()

{

	int i=0;

	while(scanf("%c",&c[i])!=EOF)

	{

		if(i>0)

		{

			if(c[i-1]=='S'&&c[i]=='T')

			i=i-2;

		}

		i++;

	}

	cout<<i-1<<endl;

	return 0;

}

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

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

		q.push(s[i]);

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

		{

			q.pop();

			q.pop();

		}	

	}

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

	return 0;

} 

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

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<deque>

using namespace std;

const int maxn=2e5+10;

char ch[maxn];

int len;

deque<char> Q;

int main(){

	cin>>ch;

	len=strlen(ch);

	Q.clear();

	Q.push_back('A');

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

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

			Q.push_back(ch[i]);

		else if(ch[i]=='T'){

			char u=Q.back();

			if(u=='T'||u=='A')

				Q.push_back(ch[i]);

			else if(u=='S')

				Q.pop_back();

		}	

	}

	int ans=Q.size();

	if(ans%2==1) ans--;

	cout<<ans<<endl;

	return 0;

}

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

}
// Slower C++ solution:
#include<iostream>

#include<stdio.h>

#include<stack> 

using namespace std;

int main()

{

	stack<char> st;

	char a;

	while(cin>>a)

	{

		if(st.size()>0&&st.top()=='S'&&a=='T')

		st.pop();

		else

		{

			st.push(a);

		}

	}

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

}

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

}
// Slower C++ solution:
#include <iostream>

#include <string>

using namespace std;



int main() {

	std::ios::sync_with_stdio(false);

	string str;

	cin>>str;

	int i=0;

	int t=-1;

	int len=str.length();

	int countt=0;

	while(i<len){

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

			++t;

		}

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

			if(t==-1){

				++countt;

			}

			if(t>=0){

				--t;

			}

		}

		++i;

	}

	printf("%i\n",t+1+countt);

	return 0;

}


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

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <string>

using namespace std;



long long anss,anst;

string s;

int main()

{

    cin>>s;

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

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

        else {

            anst++;

            if(anss) anss--,anst--;

        }

    }

    cout<<anss+anst<<endl;

    return 0;

}

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



stack<char> st;

string s;



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    cin>>s;

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

    {

        if(st.empty()||!(st.top()=='S'&&s[i]=='T')) st.push(s[i]);

        else st.pop();

    }

    cout<<st.size();

    return 0;

}

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

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<string>

using namespace std;

int main()

{

	string a;

	cin>>a;

	int tmp=a.find("ST");

	while(a.length()>0&&tmp>=0)

	{

		a.erase(tmp,2);

		int x=max(tmp-1,0);

		tmp=a.find("ST",x);

		if(tmp==string::npos)

			tmp=-1;

	}

	cout<<a.length()<<endl;

	return 0;

} 

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

}
// Slower C++ solution:
#include<bits/stdc++.h>

#include<stack>

using namespace std;

int main()

{

	char s[200010];

	scanf("%s",&s);

	int x=strlen(s);

	stack<int> a;

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

	{

		if(a.empty())

		{

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

			a.push(0);

			else

			a.push(1);

			continue;

		}

		if(a.top()==0&&s[i]=='T')

		a.pop();

		else{

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

			a.push(0);

			else

			a.push(1);

		}

		

	}

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

}


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

}
// Slower C++ solution:
#include <iostream>

#include <string>

using namespace std;

int main(){

    int s=0, st=0;

    string a;

    cin >> a;

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

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

            s++;

        }

        else{

            if(s>0){

                st++;

                s--;

            }

        }

    }

    st*=2;

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

    return 0;

}

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

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

}

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

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

}




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

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

}

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

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

}


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

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

}

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

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

}


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

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

}


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

}