unittest
{
	assert( [ "TSTTSS" ].parse.expand.solve == 4 );
	assert( [ "SSTTST" ].parse.expand.solve == 0 );
	assert( [ "TSSTTTSS" ].parse.expand.solve == 4 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto x = input.front.to!( dchar[] );
	return tuple( x );
}

auto solve( dchar[] x )
{
	auto ans = x.length.signed;
	auto i = 0L;
	auto s = 0L;
	auto t = 0L;
	while( i < x.length )
	{
		for( ; i < x.length && x[ i ] == 'S'; i++ ) s++;
		for( ; i < x.length && x[ i ] == 'T'; i++ ) t++;
		if( s <= t )
		{
			ans -= s * 2;
			s = 0;
			t = 0;
		}
		else
		{
			ans -= t * 2;
			s -= t;
			t = 0;
		}
	}
	return ans;
}
