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



using namespace std;



string s;

vector <char> q;



int main()

{

	cin >> s;

	q.push_back(s[0]);

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

	{

		if(q[q.size() - 1] == 'S' && s[i] == 'T')

			q.pop_back();

		else

			q.push_back(s[i]);

	}

	cout << q.size();

}


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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

// Created by yjq on 2019/11/7.

//



#include <bits/stdc++.h>



using namespace std;



#define ll long long

#define ld long double

#define ull unsigned long long

#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)



string s;



stack<char> S;



int main() {

    __;

    cin >> s;

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

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

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

            if (S.empty())S.push(s[i]);

            else {

                if (S.top() == 'S')S.pop();

                else S.push(s[i]);

            }

        }

    }

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

    return 0;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#pragma GCC optimize(2)

//#pragma G++ optimize(2)

//#include <bits/stdc++.h>

#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <string>

#include <climits>

#include <algorithm>

#include <queue>

#include <vector>

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;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

#include<iostream>

#include<cstring>

#include<string>

#include<algorithm>



using namespace std;



const int N = 200010;

int preT[N], preS[N];

char s[N];

int main() 

{

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

    int n = strlen(s + 1);

    int ans = 0;

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

        preS[i] = preS[i - 1] + (s[i] == 'S');

        preT[i] = preT[i - 1] + (s[i] == 'T');

        ans = max(ans, s[i] == 'T' ? preT[i] - preS[i] : 0);

    }

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

    // system("pause");

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

#include <cstdio>

#include <cstring>

#define N 200010

using namespace std;

int top,n;

char s[N],sta[N];

int main(){

	scanf("%s",s);n=strlen(s);

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

		if(top&&sta[top]=='S'&&s[i]=='T') top--;

		else sta[++top]=s[i];

	}

	printf("%d",top);

	return 0;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

#include<string>

#include<stack>

using namespace std;



stack<int> st;



int main(){

	string str;

	cin >> str;

	int n = str.size();

	int sum = 0;

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

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

		if(str[i] == 'T' && !st.empty()){

			st.pop();

			sum += 2;

		}

	}

	//n = str.size();

	cout << n - sum;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

#include <stdio.h>

#include <string.h>

using namespace std;

char x[200100];

int main(int argc, char** argv) {

	scanf("%s",x);

	int len=strlen(x);

	int ans=len;

	int s=0;

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

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

			s++;

		}else{

			if(s!=0){

				s--;ans-=2;

			}

		}

	}

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

	return 0;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

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

#include<string>

#include<iostream>

using namespace std;

int main()

{

	string s;

	cin>>s;

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

	{

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

		{

			s.erase(i,1);

			s.erase(i,1);

			if(i!=0){

				i--;

			}

		}

		else

			i++;

	}

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

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

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



const int maxn=2e5;

char s[maxn],sk[maxn],tmp;

int cnt=0;



int main(){

	

	scanf("%s",s);

	

	for(int i=0;s[i]!='\0';i++){

		

		if(!cnt){

			sk[cnt]=s[i];

			cnt++;

		}

		else if(s[i]=='T' && sk[cnt-1]=='S'){

			cnt--;

		}

		else{

			sk[cnt]=s[i];

			cnt++;

		}

		

	}

	

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

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// 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 <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;

}

// 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;

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;

}


// 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;

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;

 } 

// 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<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;

}

// 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<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;

} 

// 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<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;

}

// 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<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;

} 

// 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<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;

}

// 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<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;

}

// 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 <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;

}


// 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 <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;

}

// 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;



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;

}

// 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<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;

} 

// 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>

#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;

}


// 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 <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;

}

// 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: