Problem:
 Score : 300 points    Problem Statement We have a string X , which has an even number of characters. Half the characters are S , and the other half are T .  Takahashi, who hates the string ST , will perform the following operation 10^{10000} times:   Among the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.   Find the eventual length of X .      Constraints  2 ≦ |X| ≦ 200,000  The length of X is even.  Half the characters in X are S , and the other half are T .       Partial Scores  In test cases worth 200 points, |X| ≦ 200 .         Input The input is given from Standard Input in the following format:  X       Output Print the eventual length of X .        Sample Input 1 TSTTSS      Sample Output 1 4  In the 1 -st operation, the 2 -nd and 3 -rd characters of TSTTSS are removed. X becomes TTSS , and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.
Thus, the answer is 4 .       Sample Input 2 SSTTST      Sample Output 2 0  X will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.       Sample Input 3 TSSTTTSS      Sample Output 3 4  X will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS .

Solution (Python):
X=input()

s_cnt=0;t_cnt=0
for i in range(len(X)):
    if X[i] == "S":
        s_cnt+=1
    else:
        if s_cnt>0:
            s_cnt-=1
            t_cnt+=1

print(len(X)-t_cnt*2)

Solution (Python):
s = input()
cnt = 0
cnt_set = 0
for x in s:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)

Solution (Python):
x = input()
x = x[::-1]
cnt = 0
for i in range(len(x)):
    if 'S' in x[i]:
        if cnt != 0:
            cnt -= 2
    else:
        cnt += 2
print(cnt)

Solution (Python):
S = input()
scount = 0
tcount = 0
ans = 0
l = len(S)
for c in S:
    if c == "S":
        scount += 1
    else:
        if scount >0:
            scount -=1
            ans += 2

ans += min (scount,tcount) * 2
ans = len(S) -ans
print(ans)

Solution (Python):
x=input()
t=0;s=0
for i in range(len(x)-1,-1,-1):
  if x[i]=='T':
    t+=1
  else:
    if t>0:
      t-=1
    else:
      s+=1
print(s+t)

Solution (Python):
X = input()

ans = 0
s = 0

for x in X:
    if x == 'S':
        s += 1
    else:
        if s > 0:
            ans += 2
            s -= 1

print(len(X) - ans)

Solution (Python):
from fractions import gcd
import math
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    x =input()
    n = len(x)
    s = 0
    ans = 0
    for i in range(n):
        if x[i] == 'S':
            s +=1
        elif s > 0:
            s -= 1
            ans += 1
    print(n-ans*2)

main()

Solution (Python):




x = input()
stock = 0
count = 0
for a in x:
    if a == "S":
        stock += 1
    else:
        if stock > 0:
            count += 2
            stock -= 1
print(len(x)-count)

Solution (Python):
X = input()

ans = ["foo"]
for i in range(len(X)):
    ans.append(X[i])
    if ans[-2] == "S" and ans[-1] == "T":
        ans.pop()
        ans.pop()

print(len(ans) - 1)

Solution (Python):
x = input()
ans = 0
s = 0
for i in range(len(x)):
    if x[i] == "S":
        s += 1
    else:
        if s:
            ans += 1
            s -= 1
print(len(x) - ans * 2)

Solution (Python):
s,t = 0,0
for x in input():
  if x == 'S':
    s += 1
  else:
    if s > 0:
      s -= 1
    else:
      t += 1

print(s+t)

Solution (Python):
x=input()
l=len(x)
t=0
for i in range(l):
    if x[i]=="T":
        t+=1
    else:
        break
s=0
for j in range(l):
    if x[l-1-j]=="S":
        s+=1
    else:
        break
x=x[t:l-s]
l=len(x)
if l==0:
    print(s+t)
else:
    ans=l
    bef=x[0]
    cha=1
    for k in range(1,l):
        if bef=="S":
            if x[k]=="S":
                cha+=1
            else:
                bef=x[k]
                cha-=1
                ans-=2
        else:
            if x[k]=="S":
                bef=x[k]
                cha+=1
            else:
                if cha>0:
                    cha-=1
                    ans-=2
    print(ans+s+t)

Solution (Python):
S = input()
cs = 0
ans = 0
for i in range(len(S)):
  si = S[i]
  if si == 'T' and cs > 0:
    cs -= 1
    ans += 2
  elif si == 'S':
    cs += 1
    
print(len(S)-ans)

Solution (Python):
X = input()
N = len(X)
tmpS = 0
tmpans = 0

for i in range(N):
    if X[i] == 'S':
        tmpS += 1
    else:
        if tmpS == 0:
            tmpans += 1
        else:
            tmpS -= 1

print(tmpans*2)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")


X = input()

cnt = 0
sum_cnt = 0
for xi in X:
    if xi == "S":
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
            sum_cnt += 1

print(len(X) - sum_cnt*2)

Solution (Python):
X = input()
ans = 0
temp_s = 0
for x in X:
    if x == 'S':
        temp_s += 1
    elif temp_s > 0:
        temp_s -= 1
    else:
        ans += 1
ans += temp_s
print(ans)

Solution (Python):
X = input()

S_num = 0
ans = len(X)
for x in X:
  if x == 'S':
    S_num += 1
  elif S_num > 0:
    ans -= 2
    S_num -= 1
print(ans)

Solution (Python):
from sys import stdin
from collections import deque
X = (stdin.readline().rstrip())
stack = []
for i in X:
    if i == "S":
        stack.append(i)
    elif (i == "T" and stack == []):
        stack.append(i)
    elif (i == "T" and stack[-1] == "S"):
        stack.pop()
    else:
        stack.append(i)
print(len(stack))

Solution (Python):
x = input().rstrip()

snum = 0
stnum = 0
for item in x:
    if item == "S":
        snum += 1
    if item == "T":
        if snum > 0:
            snum -= 1
            stnum += 1
print(len(x) - 2*stnum)

Solution (Python):

"""
A - STring
https://atcoder.jp/contests/agc005/tasks/agc005_a

"""
import sys


def solve(X):
    stat = 0
    ans = 0
    for x in X:
        if x == 'T':
            stat += 1
            ans = max(ans, stat*2)
        else:
            stat -= 1
    return ans


def main(args):
    X = input()
    ans = solve(X)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
string = input()
num_t = 0
num_s = 0
for char in string:
    if char == "S":
        num_s += 1
    elif num_s > 0:
        num_s -= 1
    else:
        num_t += 1
print(num_t + num_s)

Solution (Python):
X = input()

count, ls = 0, 0
for x in X:
	if x == "S":
		ls += 1
	else:
		if 0 < ls:
			ls -= 1
		else:
			count += 1

print(ls + count)

Solution (Python):
X = input()

S_start_index = 0
for i in range(int(len(X)/2)):
    if X[i] == "S":
        S_start_index = i
        break

T_stop_index = 0

for i in range(len(X)-1, int(len(X)/2)-1, -1):

    if X[i] == "T":
        T_stop_index = i + 1
        break




count = 0
delate_count = 0
max_count = 0
for i in range(S_start_index ,T_stop_index):
    if X[i] == "S":
        count += 1
    else:
        if count == 0:
            pass
        else:
            count -= 1
            delate_count += 1



output = len(X) - delate_count*2

print(output)

Solution (Python):
X = input()
ans = 0
c = 0
for i in X:
    if i == 'T':
        if c == 0:
            ans += 2
        else:
            c -= 1
    else:
        c += 1
print(ans)

Solution (Python):
x = input()
t = 0
s = 0
cnt = 0
i=0
while t<len(x)//2:
    if x[i]=='S':
        s+=1
    if x[i]=='T':
        if s>0:
            cnt+=2
            s-=1
        t+=1
    i+=1
print(len(x)-cnt)

Solution (Python):
X=input()
ans = 0
s = 0
for c in X:
    if c=="S" : s+=1
    elif s>0 : s-=1
    else : ans+=1
print(ans+s)

Solution (Python):
s=input()

ans=0
q=0
for z in s:
  if z=="S":
    q+=1
  else:
    if q!=0:
      q-=1
      ans+=2

print(len(s)-ans)

Solution (Python):
s=input()
q=[]
cnt=0
for i in s:
    if i=='S':
        q.append('S')
    else:  
        if q:
            q.pop()
            cnt+=2
print(len(s)-cnt)

Solution (Python):
l=[]
for i in input():
    if i=="S":l.append("S")
    elif len(l)==0 or l[-1]=="T":l.append("T")
    else:l.pop()
print(len(l))

Solution (Python):
S = list(input())
N = len(S)
A = [0]*N

d = dict()
d['T'] = 1
d['S'] = -1

for i in range(N):
    A[i] = d[S[i]] + A[i-1]
        
print(max(A)*2)

Solution (Python):
s = input()
array = []

for char in s:
    if char == "S":
        array.append(char)
    elif char == "T":
        if len(array) == 0:
            array.append(char)
        elif array[-1] == "S":
            array.pop()
        else:
            array.append(char)
print(len(array))

Solution (Python):
X = input()
s,t = (0,0)
for i in range(len(X)):
	if X[i]=='S':
		s += 1
	else:
		if s==0:
			t += 1
		else:
			s -= 1
print(s+t)

Solution (Python):
X = input()

stack = []
for x in X:
    if len(stack) != 0 and x == "T" and stack[-1] == "S":
        stack.pop()
    else:
        stack.append(x)

print(len(stack))

Solution (Python):

def main():
    buf = input()
    X = buf
    length = len(X)
    S_count = 0
    for i in X:
        if i == 'S':
            S_count += 1
        else: 
            if S_count > 0:
                S_count -= 1
                length -= 2
    print(length)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
stack=[]
ans=0
for i in s:
    if i=="S":
        stack.append(1)
    elif len(stack)>0 and i=="T":
        stack.pop()
        ans+=1
print(len(s)-ans*2)

Solution (Python):
s = input()

a = 0
b = 0

for i in range(len(s)):
    if s[i]=='S':
        a+=1
    elif a>0:
        b+=2
        a-=1
print(len(s)-b)

Solution (Python):
from collections import deque

X = input()

dq = deque()

for x in X:
    if not dq:
        dq.append(x)
    elif dq[-1] == "S" and x == "T":
        dq.pop()
    else:
        dq.append(x)

ans = len(dq)
print(ans)

Solution (Python):
X=input()
count=0
balance=0
for x in X:
  if balance==0 and x=="T":
    count+=1
  elif x=="S":
    balance-=1
  elif x=="T":
    balance+=1
X=X[::-1]
balance=0
for x in X:
  if balance==0 and x=="S":
    count+=1
  elif x=="T":
    balance-=1
  elif x=="S":
    balance+=1
print(count)

Solution (Python):
x = input()
ans = 0
t = 0
s = 0
for i in range(len(x)):
    if x[i] == "S":
        s += 1
    elif x[i] == "T" and s > 0:
        s -=1
    else:
        t +=1
print(s+t)

Solution (Python):
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    if len(slen)>0:
      tmp=slen.popleft()+(stmp-ttmp)
      slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)

Solution (Python):
s = input()
ans = len(s)
cnt = 0
for c in s:
  if c == 'S':
    cnt += 1
  elif cnt > 0:
    ans -= 2
    cnt -= 1
print(ans)

Solution (Python):
S = input()
N = len(S)
t = 0
num = 0
for i in range(N):
    if S[i] == 'S':
        t += 1
    else:
        if t > 0:
            num += 2
            t -= 1

print(N - num)

Solution (Python):
s = input()

s_cnt, t_cnt = 0, 0
t = 0
for i in s:
    if i == "S":
        s_cnt += 1
    if s_cnt == 0 and i == "T":
        t += 1
    if s_cnt != 0 and i == "T":
        s_cnt -= 1
    s_cnt = max(s_cnt, 0)

print(2*t)

Solution (Python):
X = input()
s = 0
t = 0
cnt = 0
for x in X:
    if x == 'S':
        s += 1
    else:
        t += 1
        if s and t:
            s -= 1
            t -= 1
            cnt += 2
print(len(X)-cnt)

Solution (Python):
X = input()
s = 0
t = 0
for c in X:
  if c == 'S': s += 1
  else:
    if s == 0: t += 1
    else: s -= 1
print(s + t)

Solution (Python):
s = input()
ans = 0
temp = 0
for i in range(len(s)):
  if s[i] == 'T':
    temp -= 1
  else:
    temp += 1
  ans = min(temp,ans)
print(ans*(-2))

Solution (Python):
s = input()
S = 0
T = 0
for i in range(len(s)):
  if s[i] == 'S':
    S += 1
  else:
    if S > 0:
      S -= 1
    else:
      T += 1
print(T * 2)

Solution (Python):
s = input()
cnt_s = 0
cnt_t = 0
for i in s:
    if i == 'S':
        cnt_s += 1
    elif cnt_s > 0:
        cnt_s -= 1
    else:
        cnt_t += 1

print(cnt_s + cnt_t)

Solution (Python):
from collections import deque

X = input()

dq = deque()

for x in X:
    if not dq:
        dq.append(x)
    elif dq[-1] == "S" and x == "T":
        dq.pop()
    else:
        dq.append(x)
    
ans = len(dq)
print(ans)

Solution (Python):
s = input()
y = [0]
z = []
for t in s:
    if t == "S":
        y.append(t)
    elif y[-1] == "S":
        del y[-1]
    else:
        z.append(t)

print(len(y) + len(z) - 1)

Solution (Python):
from collections import deque


X = input()
stk = deque()

for c in X:
    if len(stk) == 0:
        stk.append(c)
    else:
        if stk[-1] == "S":
            if c == "T":
                stk.pop()
            else:
                stk.append(c)
        else:
            stk.append(c)
print(len(stk))

Solution (Python):
X = input()
cnt_S, cnt_T = 0, 0

for c in X:
    if c == "S":
        cnt_S += 1
    else:
        if cnt_S:
            cnt_S -= 1
        else:
            cnt_T += 1
print(cnt_S + cnt_T)

Solution (Python):
X = input()

s_stack=0
t_stack=0

for x in X:
  if x=='S':
    s_stack +=1
  if x=='T':
    if s_stack:
      s_stack -=1
    else:
      t_stack +=1

answer = s_stack + t_stack
print(answer)

Solution (Python):
x = input().strip()
stack = []

for _x in x:
  if stack and _x == 'T' and stack[-1] == 'S':
    stack.pop()
  else:
    stack.append(_x)
print(len(stack))

Solution (Python):
x=input();a,l=0,len(x)
for i in range(l):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)

Solution (Python):
X = input()

count = 0
s = 0
for x in X:
    if x == 'S':
        s += 1
    elif s > 0:
        s -= 1
        count += 1

print(len(X) - count*2)

Solution (Python):
s=input()
ls=len(s)
c=0
ans=0
for i in range(ls):
    if s[i]=='S':
        c+=1
    elif c>0:
        ans+=2
        c-=1
print(ls-ans)

Solution (Python):
X = input()
ans = 0
s = 0
for i in range(len(X)):
    if X[i] == 'S':
        s += 1
    elif s > 0:
        ans += 2
        s -= 1
print(len(X)-ans)

Solution (Python):
X = input()
t = 0
s = 0
for i in X:
    if i == 'T':
        if s > 0:
            s -= 1
        else:
            t += 1
    if i == 'S':
        s += 1
print(s + t)

Solution (Python):
x = input()
s = []
for a in x:
    if len(s) == 0:
        s.append(a)
    else:
        t = s.pop()
        if t != 'S' or a != 'T':
            s.append(t)
            s.append(a)
print(len(s))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    x = S()
    s = 0
    ans = len(x)
    for i in x:
        if i == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
    return


def B():
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    A()

Solution (Python):
S = input()
t = 0
s = 0
for c in S:
  if c=="T" and s==0:
    t += 1
  elif c=="T":
    s -= 1
  else:
    s += 1
print(s+t)

Solution (Python):
ipt = raw_input()
l = ""
for s in ipt:
    if not l:
        l += s
    elif l[-1]+s == "ST":
        l = l[:-1]
    else:
        l += s
print len(l)

Solution (Python):
s = raw_input()
sn = 0
tn = 0
for i in s:
	if i == "S":
		sn += 1
	elif i == "T":
		tn += 1
		if sn > 0:
			sn -= 1
			tn -= 1
print sn + tn

Solution (Python):


s = raw_input()

s1 = []
for x in s:
	if not s1:
		s1.append(x)
		continue
	if x == 'T' and s1[-1] == 'S':
		
		del s1[-1]
	else:
		s1.append(x)

print len(s1)

Solution (Python):
s = raw_input()

head = 0
sub = 0

for i, v in enumerate(s):
    if v == 'S':
        head += 1

    if v == 'T' and head:
        head -= 1
        sub += 2

print(len(s) - sub)

Solution (Python):
X = list(input())

S_count = 0
ans = 0
for i in range(len(X)):
    if X[i] == 'S':
        S_count += 1
    else:
        if S_count:
            ans += 2
            S_count -= 1

print(len(X)-ans)

Solution (Python):
s = input()
t = []
cnt = 0
for a in s:
    t.append(a)
    cnt += 1
    if cnt >= 2:
        if t[-2] == 'S' and t[-1] == 'T':
            cnt -= 2
            for i in range(2):
                t.pop(-1)
print(cnt)

Solution (Python):
s = input()
t = []
for a in s:
    t.append(a)
    if len(t) >= 2:
        if t[-2] == 'S' and t[-1] == 'T':
            for i in range(2):
                t.pop(-1)
print(len(t))

Solution (Python):
s = input()
ans = 0
cnt = 0
for a in s:
    if a == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
        else:
            ans += 1
print(ans+cnt)

Solution (Python):
n = input()
co = 0
su = 0
a = [n[0]]

for i in range(len(n)-1):
    if len(a) == 0:
        a.append(n[i+1])
    else:
        t = n[i+1]
        if t == "T":
            if a[-1] == "S":
                a.pop()
            else:
                a.append(t)
        else:
            a.append(t)
print(len(a))

Solution (Python):
from collections import deque

x = input()
q = deque(x[0])

for i in range(1, len(x)):
    if q:
        p = q.pop()
        if p == 'S' and x[i] == 'T':
            pass
        else:
            q.append(p)
            q.append(x[i])
    else:
        q.append(x[i])
print(len(q))

Solution (Python):
x = input()

ans = 0
cnt_s = 0
for xx in x:
    if xx == 'T':
        if cnt_s > 0:
            cnt_s -= 1
        else:
            ans += 2
    else:
        cnt_s += 1
print(ans)

Solution (Python):
S=input()
N=len(S)
ans=N

stack=[]
stack.append(S[0])
for i in range(1,N):
  if len(stack)!=0 and stack[len(stack)-1]=='S' and S[i]=='T':
    ans-=2
    stack.pop()
  elif S[i]=='S':
    stack.append(S[i])

print(ans)

Solution (Python):
x = []
s = input()
for i in s:
  if i == "T" and x != [] and x[-1] == "S":
    x.pop()
  else:
    x.append(i)
print(len(x))

Solution (Python):

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]

    stack = []

    for s in S:
        if len(stack) == 0:
            stack.append(s)
        else:
            if s == "T" and stack[len(stack) - 1] == "S":
                stack.pop()
            else:
                stack.append(s)
    print len(stack)


if __name__ == '__main__':
    main()

Solution (Python):
X=input()
from collections import deque
lt=deque()
r=0
ans=0
while r<len(X):
    if(X[r:r+2]=='ST'):
        ans+=2
        r+=2
        continue
    elif(len(lt)>0 and X[lt[-1]]+X[r]=='ST'):
        ans+=2
        lt.pop()
        r+=1
        continue
    if(X[r]=='S'):
        lt.append(r)
        r+=1
    else:
        r+=1
        lt.clear()

print(len(X)-ans)

Solution (Python):
stack = 0
S = input()
ans = len(S)
for c in S:
    if c == "S":
        stack += 1
    elif stack != 0:
        stack -= 1
        ans -= 2
print(ans)

Solution (Python):
S = input()

result = ""
for s in S:
  if(s == "T" and result == ""):
    result += s
  elif(s == "T" and result[-1] == "S"):
    result = result[:-1]
  else:
    result += s
print(len(result))

Solution (Python):
def solve(s):
    sums = 0
    sumt = 0
    ans = 0
    for i in s:
        if i == 'S':
            sums += 1
        else:
            if sums > 0:
                sums -= 1
                ans += 2
    return len(s)-ans

if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
def solve(s):
    sums = 0
    sumt = 0
    ans = 0
    for i in s:
        if i == 'S':
            sums += 1
        else:
            if sums > 0:
                sums -= 1
                ans += 2
    return len(s)-ans

if __name__ == '__main__':
    s = input()
    print(solve(s))

Solution (Python):
s = input()
sums = 0
sumt = 0
ans = 0
for i in s:
    if i == 'S':
        if sumt == 0:
            sums += 1
    else:
        if sums > 0:
            sums -= 1
            ans += 2
        
print(len(s)-ans)

Solution (Python):
X = input()
Q = []
for i in range(len(X)):
    if X[i] == 'T':
        if len(Q) > 0 and Q[-1] == 'S':
            Q.pop()
        else:
            Q.append('T')
    else:
        Q.append('S')
print(len(Q))

Solution (Python):
from collections import deque
X = input()
Q = deque()
for i in range(len(X)):
    if X[i] == 'T':
        if len(Q) > 0 and Q[-1] == 'S':
            Q.pop()
        else:
            Q.append('T')
    else:
        Q.append('S')
print(len(Q))

Solution (Python):
X = input()
N = len(X)

ans = 0
nsta = 0
for i in range(N):
    if X[i] == "T":
        if nsta > 0:
            nsta -= 1
            ans +=  1
    if X[i] == "S":
        nsta += 1

print( N - 2 * ans)

Solution (Python):
x=input()
l=[x[0]]
for i in range(1,len(x)):
    if l!=[]:
        if l[-1]=="S":
            h=1
        else:
            h=0
    l.append(x[i])
    if len(l)!=1:
        if l[-1]=="T":
            if h==1:
                l.pop(-1)
                l.pop(-1)
                if l!=[]:
                    h=(0 if l[-1]=="T" else 1)
                else:
                    h=0
            else:
                h=0
        else:
            h=0
print(len(l))

Solution (Python):
def main():
    x=input()
    cnt=0
    ans=len(x)
    for i in range(len(x)):
        if(x[i]=='S'):
            cnt+=1
        else:
            if(cnt>0):
                cnt-=1
                ans-=2
    print(ans)
        
if __name__=="__main__":
    main()

Solution (Python):
x=input()
s_cnt=0
t_cnt=0
for i in x:
    if i=="S":
        s_cnt+=1
    elif s_cnt>0:
        s_cnt-=1
    else:
        t_cnt+=1
print(s_cnt+t_cnt)

Solution (Python):
def solve():
  s =input()
  n =len(s)
  queue = 0
  ans = 0
  for i in range(n):
    if s[i] == 'S': queue+=1
    else: 
      if queue >0:
        queue -= 1
        ans += 2
  return (n-ans)  
  
  
if __name__ == '__main__':
  print(solve())

Solution (Python):
s = input()
lisS = []
lisT = []
for i in range(len(s)):
  if s[i] == 'S':
    lisS.append(i)
  else:
    lisT.append(i)
ans = 0
cnt = 0
cs = 0
ct = 0
while cnt < len(s)//2:
  if lisS[cs] < lisT[ct]:
    cs += 1
    ct += 1
    ans += 2
  else:
    ct += 1
  cnt += 1
print(len(s)-ans)

Solution (Python):
S = input()

s = 0
t = 0
res = len(S)
stack = [S[0]]
for i in range(1, len(S)):
    if stack != []:
        if stack[-1] == 'S' and S[i] == 'T':
            stack.pop()
        else:
            stack.append(S[i])
    else:
        stack.append(S[i])

print(len(stack))

Solution (Python):
ans=0
stack=[]
for s in input():
    if len(stack)>0 and s=="T":
        if stack[-1]=="S":
            del stack[-1]
        else:
            stack.append(s)
    else:
        stack.append(s)
print(len(stack))

Solution (Python):
x = input()

st_10_2 = "S" * 10 * 10 + "T" * 10 * 10
st_10_3 = "S" * 10 * 10 * 10 + "T" * 10 * 10 * 10

while True:
    x = x.replace(st_10_3,"").replace(st_10_2,"").replace("ST","")
    if "ST" not in x:
        break

print(len(x))

Solution (Python):
s = input()
n = len(s)
ruiseki = [0]*(n+1)

for i in range(n):
  if s[i]=="S":
    ruiseki[i+1] = ruiseki[i]-1
  else:
    ruiseki[i+1] = ruiseki[i]+1
print(max(ruiseki)*2)

Solution (Python):
S=input()
ans=[]
for s in S:
    if ans==[]:
        ans.append(s)
    elif s=='T':
        if ans[-1]=='S':
            ans.pop()
        else:
            ans.append(s)
    else:
        ans.append(s)
print(len(ans))

Solution (Python):
x=input()
n=len(x)
s_count=0
t_count=0
for i in x:
    if i == "S" : s_count+=1
    else:
        if s_count>0 : 
            s_count-=1
            n-=2
print(n)

Solution (Python):
xx = input()

remove = 0
s_num=0
for x in xx:
    if x=='S':
        s_num += 1
    else:
        if s_num>0:
            remove += 1
            s_num -= 1
print(len(xx) - 2 * remove)

Solution (Python):
X = input()
st = []
for s in X:
    if s == 'S': st.append(s)
    if s == 'T':
        if (not st) or st[-1] == 'T': st.append(s)
        if st[-1] == 'S': st.pop()
print(len(st))

Solution (Python):
x=input()
y=[0]
z=[]
for t in x:
    if t=="S":
        y.append(t)
    elif y[-1]=="S":
        del y[-1]
    else:
        z.append(t)
print(len(y)+len(z)-1)

Solution (Python):
s = input()

stack = []
for c in s:
    if c == 'S':
        stack.append(c)
    else:
        if not stack:
            stack.append(c)
        elif stack[-1] == 'T':
            stack.append(c)
        else:
            stack.pop()

print(len(stack))

Solution (Python):
s = input()

ans = 0
cnt = 0
for c in s:
    if c == 'S':
        cnt += 1
    else:
        if cnt:
            ans += 1
            cnt -= 1

print(len(s) - 2 * ans)

Solution (Python):


x = input()


sc = 0

tc = 0

for c in x:
    if c == 'S':
        sc += 1
    elif sc >= 1:
        sc -= 1
    else:
        tc += 1

print(sc + tc)

Solution (Python):
s=input()
sc=0
tc=0
for i in s:
  if i=='S':
    sc+=1
  elif sc!=0:
    sc-=1
  else :tc+=1
print(tc+sc)

Solution (Python):
a = input()
s,t = 0,0
for i in a:
    if i == "S":
        s += 1
    else:
        if s==0:
            t += 1
        else:
            s -=1
print(s+t)

Solution (Python):
X = input()

s, t = 0, 0
for x in X:
    if x == "S":
        s += 1
    else:
        if s == 0:
            t += 1
        else:
            s -= 1

print(s+t)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

scnt = 0
dlt = 0

for si in s:
    if si == 'S':
        scnt += 1
        
    if scnt > 0 and si == 'T':
        scnt -= 1
        dlt += 2
        
print(len(s)-dlt)

Solution (Python):
X = input()
ans = len(X)
tmp = 0
for i in range(len(X)):
    if X[i] == "S":
        tmp += 1
    elif tmp:
        tmp -= 1
        ans -= 2
print(ans)

Solution (Python):

X = input()

ss = []
ans = len(X)

for c in X:
    if ss == []:
        if c == 'T':
            continue
        else:
            ss.append(c)
    else:
        if c == 'T':
            ans -= 2
            ss.pop()
        else:
            ss.append(c)

print(ans)

Solution (Python):
x = input()

count = 0
s = 0
t = 0

for w in x:
    if w == "T":
        if s > 0:
            s -= 1
            count += 1
    else:
        s += 1

print(len(x)-count*2)

Solution (Python):
x = input()

count = 0
s = 0
t = 0

for w in x:
    if w == "T":
        if s > 0:
            s -= 1
            count += 1
    else:
        s += 1

print(len(x)-count*2)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

scnt = 0
dlt = 0

for si in s:
    if si == 'S':
        scnt += 1
        
    if scnt > 0 and si == 'T':
        scnt -= 1
        dlt += 2
        
print(len(s)-dlt)

Solution (Python):
S = input()
ans = 0
ss = 0
for c in S:
    if c=='S':
        ss += 1
    else:
        if ss > 0:
            ss -= 1
        else:
            ans += 1
ans += ss
print(ans)

Solution (Python):
s = input()
SSS = 0
len = 0
for c in s:
    if c == 'S':
        SSS += 1
        len += 1
    elif SSS == 0:
        len += 1
    else:
        SSS -= 1
        len -= 1
    
print(len)

Solution (Python):
def solve(X):
    ans = 0
    count = 0
    for c in X:
        if c == "S":
            count += 1
        else:
            if count > 0:
                count -= 1
            else:
                ans += 1
    ans += count
    return ans

if __name__ == "__main__":
    X = input()
    print(solve(X))

Solution (Python):
c=0
for x in input():c+=x<'T'or-(c>0)
print(2*c)

Solution (Python):
c=0
for x in input():c+=x=='S'or-(c>0)
print(2*c)

Solution (Python):
c=0
for x in input():c+=x=='S'or(c>0)*-1
print(2*c)

Solution (Python):
x = input()
cnt = 0
ans = 0
for i in range(len(x)):
    if x[i] == "S":
        cnt += 1
    else:
        if cnt == 0:
            ans += 1
        else:
            cnt -= 1
print(2 * ans)

Solution (Python):
import collections

stack = collections.deque()

for s in input():
    if not stack:
        stack.append(s)
    else:
        tail = stack[-1]
        if tail == "S" and s == "T":
            stack.pop()
        else:
            stack.append(s)
print(len(stack))

Solution (Python):
X = input()
N = len(X)

sum_s = 0
ans = 0
for i in range(N):
    if X[i] == 'S':
        sum_s += 1
    elif X[i] == 'T':
        if sum_s > 0:
            sum_s -= 1
        else:
            ans += 1

print(ans+sum_s)