stablegradients/pie-gem5-pairs huggingface dataset:
// 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.16822937281398x):
# include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define pii pair<int,int>

typedef long long ll;



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    string s;

    cin>>s;

    stack<char>st;

    int ans=s.size();

    for(auto isi:s){

        if(isi=='S') {

            st.push('S');



        }

        else {

            if(st.empty()==false){

                st.pop();

                ans-=2;

            }

        }

    }   

    cout<<ans<<endl;

}
// 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.771592209986336x):
# include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define pii pair<int,int>

typedef long long ll;



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    string s;

    cin>>s;

    stack<char>st;

    int ans=s.size();

    for(auto isi:s){

        if(isi=='S') {

            st.push('S');



        }

        else {

            if(st.empty()==false){

                st.pop();

                ans-=2;

            }

        }

    }   

    cout<<ans<<endl;

}
// 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.1680697389888532x):
#include <iostream>

#include <cstring>

#include <stack>

using namespace std;



stack<char> stacky;



int solve(string X, int N, int ans) {

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

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

            else {      // encounter 't'

                  if(!stacky.empty()) stacky.pop(); 

                  else ans++;

            }

      }

      ans += stacky.size();

      return ans;

}



int main() {

      ios_base::sync_with_stdio(false);

      cin.tie(NULL);

      cout.tie(NULL);



      string X;

      cin >> X;

      int N = X.size();

      

      cout << solve(X, N, 0) << endl;

}
// 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.7713501290665898x):
#include <iostream>

#include <cstring>

#include <stack>

using namespace std;



stack<char> stacky;



int solve(string X, int N, int ans) {

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

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

            else {      // encounter 't'

                  if(!stacky.empty()) stacky.pop(); 

                  else ans++;

            }

      }

      ans += stacky.size();

      return ans;

}



int main() {

      ios_base::sync_with_stdio(false);

      cin.tie(NULL);

      cout.tie(NULL);



      string X;

      cin >> X;

      int N = X.size();

      

      cout << solve(X, N, 0) << endl;

}
// 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.1967704035777849x):
#include <bits/stdc++.h>

using namespace std;



string S;

int suma,sumb;



int main()

{

	cin>>S;

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

	{

		if(S[i] == 'S') suma++;

		if((suma)&&(S[i]=='T'))

		{

			suma--;

			sumb+=2;

		}

	}

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

}
// 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.8148740080157268x):
#include <bits/stdc++.h>

using namespace std;



string S;

int suma,sumb;



int main()

{

	cin>>S;

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

	{

		if(S[i] == 'S') suma++;

		if((suma)&&(S[i]=='T'))

		{

			suma--;

			sumb+=2;

		}

	}

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

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

}


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

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

}

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

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

}

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

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

}

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

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

}

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

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

}


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

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

}


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

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

}

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

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

}

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

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

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 200000

#define LL long long

#define INF 1000000000000000000

int n,top;

char s[MAXN+5],stk[MAXN+5];

int main()

{

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

	n=strlen(s+1);

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

	{

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

		{

			if(stk[top]=='S')top--;

			else stk[++top]='T';

		}

		else stk[++top]='S';

	}

	printf("%d",top);

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 200000

#define LL long long

#define INF 1000000000000000000

int n,top;

char s[MAXN+5],stk[MAXN+5];

int main()

{

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

	n=strlen(s+1);

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

	{

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

		{

			if(stk[top]=='S')top--;

			else stk[++top]='T';

		}

		else stk[++top]='S';//

	}

	printf("%d",top);

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

#include<cstdio>

#include<cstring>

using namespace std;



#define MAXN 200000

int N;

char str[MAXN+5];



int main(){

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

    N=strlen(str+1);

    stack<char> S;

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

        if(S.empty()){

            S.push(str[i]);

            continue;

        }

        char tmp=S.top();

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

            S.pop();

        else

            S.push(str[i]);

    }

    printf("%d",S.size());

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 200005

#define LL long long

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ss=0,sum=0;

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

	{

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

		else if(s[i]=='T'&&ss) sum+=2,ss--;

	}

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

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

using namespace std ;

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

	string str ;

	cin >> str ;

	int len = str.size() ;

	int cntt = 0 ;

	int cnts = 0 ;

	int cntall = 0 ;

	int bank ;

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

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

			cnts += 1 ;

		}

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

			if ( cntt == cnts ) {

				cntall += 1 ;

			}

			if ( cnts > cntt ) {

				cntt += 1 ;

			}

		}

	}

	cout << cntall * 2 ;

	return 0;

}

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

#include<cstring>

#define maxn 200005

int n,tp;

char st[maxn],s[maxn];

int main()

{

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

	n=strlen(s+1);

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

		if(s[i]=='T'&&tp&&st[tp]=='S') tp--;

		else st[++tp]=s[i];

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

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

using namespace std ;

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

	string str ;

	cin >> str ;

	int len = str.size() ;

	int cntt = 0 ;

	int cnts = 0 ;

	int cntall = 0 ;

	int bank ;

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

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

			cnts += 1 ;

		}

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

			if ( cntt == cnts ) {

				cntall += 1 ;

			}

			if ( cnts > cntt ) {

				cntt += 1 ;

			}

		}

	}

	cout << cntall * 2 ;

	return 0;

}

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

string s;

int ts,tt,ans;

int main(){

	cin>>s;

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

		ts++;

	else

		tt++;

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

		if(s[i]!=s[i-1] && s[i]=='T'){

			tt=1;

		}

		else if(s[i]!=s[i-1] && s[i]=='S'){

			ans+=2*(min(ts,tt));

			if(ts>tt)

				ts=ts-tt+1;

			else

				ts=1;

			tt=0;

		}

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

			ts++;

		else

			tt++;

	}

	ans+=2*(min(ts,tt));

	cout<<(int)s.size()-ans;

}


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

}