stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

#define ll long long int

#define rep(i,n) for( int i = 0; i < n; i++ )

#define rrep(i,n) for( int i = n; i >= 0; i-- )

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000



vector<int> G[100010];

int L[2][100010];





void dfs(int T, int V, int cost) {

	L[T][V] = cost;

	rep(i, G[V].size()) {

		if (L[T][G[V][i]] != INF) continue;

		dfs(T, G[V][i], cost + 1);

	}

}



int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);



	int N;

	cin >> N;

	rep(i, N-1) {

		int a, b;

		cin >> a >> b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

	rep(i, 2) rep(j, 100010) L[i][j] = INF;

	dfs(0, 1, 0);

	dfs(1, N, 0);

	int Fennec = 0;

	int Snuke = 0;

	REP(i, 1, N) {

		if (L[0][i] <= L[1][i]) Fennec++;

		else Snuke++;

	}

	if (Fennec > Snuke) cout << "Fennec" << endl;

	else cout << "Snuke" << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.238078826226755x):
#include "bits/stdc++.h"

using namespace std;

#define ll long long int

#define rep(i,n) for( int i = 0; i < n; i++ )

#define rrep(i,n) for( int i = n; i >= 0; i-- )

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000



vector<int> G[100010];



int d[100010][2];



void dfs(int x, int k, int p = -1, int depth = 0) {

    d[x][k] = depth;

    for(auto to: G[x]) {

        if (to == p) continue;

        dfs(to, k, x, depth + 1);

    }

}



int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N; cin >> N;

    rep(i, N - 1) {

        int s, t;

        cin >> s >> t;

        s--; t--;

        G[s].push_back(t);

        G[t].push_back(s);

    }

    dfs(0, 0);

    dfs(N - 1, 1);

    int cnt1 = 0, cnt2 = 0;

    rep(i, N) {

        if (d[i][0] <= d[i][1]) cnt1++;

        else cnt2++;

    }

    if(cnt1 > cnt2) {

        cout << "Fennec" << endl;

    } else {

        cout << "Snuke" << endl;

    }

    //cout << cnt1 << " " << cnt2 << endl;





    return 0;

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

using namespace std;

int main()

{

    string x;

    cin >> x;

    int sz = x . size() , s = 0;

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

    {

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

        {

            s ++;

            i ++;

        }

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

        {

            while (s)

            {

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

                {

                    sz -= 2;

                }

                else

                {

                    break;

                }

                s --;

                i ++;

            }

        }

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

        {

            i ++;

        }

    }

    cout << sz;

}

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

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;

 

typedef long long ll ;

typedef long double ld ;





#define int long long

#define all(v) v.begin() , v.end()



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



string s ;

int n ;

vector < int > all ; 



int32_t main()                     

{

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> s ;

	n = ( int ) s . size ( ) ;

	all . push_back ( 1 ) ;

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

		if ( s [ i ] == s [ i - 1 ] )

			all . back ( ) ++ ;

		else

			all . push_back ( 1 ) ; 

	}

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

		int res = 0 ; 

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

			if ( all [ i ] < all [ i + 1 ] ) {

				res += all [ i ] ; 

			}

			else {

				res += all [ i + 1 ] ;

				if ( i + 2 < ( int ) all . size ( ) )

					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 

			}

		}

		res <<= 1 ;

		cout << n - res << endl ; 

	}

	else {

		int res = 0 ;

		for ( int i = 0 ; i + 1 < ( int ) all . size ( ) ; i += 2 ) {

			if ( all [ i ] < all [ i + 1 ] ) {

					res += all [ i ] ; 

			}

			else {

				res += all [ i + 1 ] ;

				if ( i + 2 < ( int ) all . size ( ) )

					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 

			}

		}

		cout << n - 2 * res << endl ; 

	}

}


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

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

}


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

}
// Slower C++ solution:
//

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

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

}

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

}
// 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.320905082354201x):
#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;

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

using namespace std;

int main()

{

    string x;

    cin >> x;

    int sz = x . size() , s = 0;

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

    {

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

        {

            s ++;

            i ++;

        }

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

        {

            while (s)

            {

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

                {

                    sz -= 2;

                }

                else

                {

                    break;

                }

                s --;

                i ++;

            }

        }

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

        {

            i ++;

        }

    }

    cout << sz;

}

// Faster C++ solution for the same problem (measured speedup: 5.306809744273358x):
#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:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;

 

typedef long long ll ;

typedef long double ld ;





#define int long long

#define all(v) v.begin() , v.end()



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



string s ;

int n ;

vector < int > all ; 



int32_t main()                     

{

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> s ;

	n = ( int ) s . size ( ) ;

	all . push_back ( 1 ) ;

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

		if ( s [ i ] == s [ i - 1 ] )

			all . back ( ) ++ ;

		else

			all . push_back ( 1 ) ; 

	}

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

		int res = 0 ; 

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

			if ( all [ i ] < all [ i + 1 ] ) {

				res += all [ i ] ; 

			}

			else {

				res += all [ i + 1 ] ;

				if ( i + 2 < ( int ) all . size ( ) )

					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 

			}

		}

		res <<= 1 ;

		cout << n - res << endl ; 

	}

	else {

		int res = 0 ;

		for ( int i = 0 ; i + 1 < ( int ) all . size ( ) ; i += 2 ) {

			if ( all [ i ] < all [ i + 1 ] ) {

					res += all [ i ] ; 

			}

			else {

				res += all [ i + 1 ] ;

				if ( i + 2 < ( int ) all . size ( ) )

					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 

			}

		}

		cout << n - 2 * res << endl ; 

	}

}


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

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();

}


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

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

}

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

}

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

}

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

}

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

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

}

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

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;

}

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

}

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

}