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 = list(input())
stack = []
for tmp in X:
    if tmp == 'T' and (len(stack) == 0 or stack[len(stack)-1] == 'T'):
        stack.append(tmp)
    elif tmp == 'T' and stack[len(stack)-1] == 'S':
        stack.pop()
    else:
        stack.append(tmp)
print(len(stack))

Solution (Python):
x = raw_input()
stack = []
ans = 0
for i in xrange(len(x)):
    if x[i] == "S":
        stack.append("S")
    else:
        if len(stack) == 0:
            ans += 1
        else:
            stack.pop()
print ans + len(stack)

Solution (Python):
s = raw_input()
p = 0
m = 0
for c in s:
    if c == 'S':
        p -= 1
    elif c == 'T':
        p += 1
    m = max(m,p)
print m*2

Solution (Python):
X = raw_input()

q = []
for x in X:
    q.append(x)
    if q[-2:] == ['S', 'T']:
        q.pop()
        q.pop()
print len(q)

Solution (Python):
S = input()
A = []
for c in S:
  A.append(c)
  while len(A) >= 2 and A[-2] == 'S' and A[-1] == 'T':
    A[-2:] = []
print(len(A))

Solution (Python):
X = input()
ans = 0

for c in X:
    if c == 'S':
        ans += 1
    if c == 'T' and ans > 0:
        ans -= 1
print(ans * 2)

Solution (Python):



x = input()
n = len(x)

s, t = 0, 0
cnt = 0
for i in range(n):
    if x[i] == 'T':
        if s > 0:
            s -= 1
            cnt += 2
    elif x[i] == 'S':
        s += 1




















print(n - cnt)

Solution (Python):
S=list(str(input()))
ans=[]
for i in S:
    if i=='S':
        ans.append(i)
    elif i=='T' and len(ans)==0:
        ans.append(i)
    elif i=='T' and ans[-1]=='T':
        ans.append(i)
    elif i=='T' and ans[-1]=='S':
        del ans[-1]
print(len(ans))

Solution (Python):
import sys

s = sys.stdin.readline().strip()

have = 0
ret = 0
for v in s:
    if v == 'S':
        have += 1
    elif have:
        have -= 1
    else:
        ret += 1
print ret * 2

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

Solution (Python):
X= input()

T_count=X.count("T")
S_count=X.count("S")
T_removed=0
i=0
ans=0
while i<len(X):
    if X[i]=="T":
        if T_removed>0:
            T_removed -=1
        else:
            T_count -= 1
            ans+=1
    elif X[i]=="S":
        if T_count:
            T_count-=1
            T_removed+=1
        else:
            ans+=1
    i+=1
print(ans)

Solution (Python):
s = raw_input()
c = len(s)
l = 0
was_es = True
for i in xrange(len(s)):
    if s[i] == "S":
        if was_es == True:
            l += 1
        was_es = True
    else:
        if l > 0:
            l -= 1
            c -= 2
print c

Solution (Python):
s = input()

ans = 0
for c in s:
    if c == 'S':
        ans += 1
    if c == 'T' and ans > 0:
        ans -= 1
print(ans*2)

Solution (Python):
x = raw_input()

y = []
for i in x:
    if len(y) == 0:
        y.append(i)
    elif i == 'S':
        y.append(i)
    elif i == 'T' and y[-1] == 'T':
        y.append(i)
    else:
        y.pop()

print len(y)

Solution (Python):
mystr = raw_input()
s_count = 0
t_count = 0
pairs = 0
for x in mystr:
    if x == "S":
        s_count += 1
    else:
        if (t_count < s_count):
            pairs += 1
            t_count +=1
print len(mystr)-2*pairs

Solution (Python):
string = input()
stack = ""

for i in string:
    if i == "S":
        stack += i
    elif i == "T" and (stack == "" or stack[-1] == "T"):
        stack += i
    else:
        stack = stack[0:-1]

print(len(stack))

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

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

Solution (Python):
s = input()

a=[]
for i in range(len(s)):
 if s[i]=="S":
     a.append("S")
 if s[i]=="T":
     if len(a)==0 or a[-1]=="T":
         a.append("T")
     if a[-1]=="S":
         a.pop()
print (len(a))

Solution (Python):

from sys import stdin
a = stdin.readline().strip()
l = len(a)
s = 0
t = 0
i = l-1
while i>=0:
    if a[i]=='T':
        t+=1 
    else:
        if t>0:
            t-=1 
        else:
            s+=1
    i-=1 
print s+t

Solution (Python):
X = input()
nS = 0
ret = len(X)
for c in X:
    if c == 'S':
        nS += 1
    elif c == 'T':
        if nS > 0:
            nS -= 1
            ret -= 2
print(ret)

Solution (Python):


s=raw_input()
res=0
for c in s:
 if c=='S':
  res+=1
 elif c=='T' and res>0:
  res-=1
print res*2

Solution (Python):


s=raw_input()
res=0
for c in s:
 if c=='S':
  res+=1
 elif c=='T' and res>0:
  res-=1
print res*2

Solution (Python):
s = input()

stack = []

for i in s:
    if i == 'S':
        stack.append(i)
    if i == 'T':
        if not stack:
            stack.append(i)
            continue
        last = stack.pop()
        if last == 'S':
            continue
        else:
            stack.append(last)
            stack.append(i)

print(len(stack))

Solution (Python):
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    s = []
    for c in x:
    	if len(s) == 0:
    		s.append(c)
    	elif c == 'T' and s[-1] == 'S':
    		s.pop()
    	else:
    		s.append(c)
    print(len(s))
 
main()

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

Solution (Python):
X = raw_input()
cnt = 0
ans = 0
for x in X:
    if x is 'S':
        cnt += 1
    else:
        if not cnt:
            ans += 1
        else:
            cnt -= 1
print ans*2

Solution (Python):
def main():
    s = input()
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Solution (Python):
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Solution (Python):
def main():
    s = input().replace('ST', '')
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Solution (Python):
s = ''.join(input().split('ST'))
cnts = 0
cnt = 0
for i in s:
    if i == 'S' :
        cnts += 1
    elif cnts > 0:
        cnts -= 1
        cnt += 1
print(len(s)-cnt*2)

Solution (Python):
s = ''.join(input().split('ST'))
while 1:
    i = s.find('ST')
    if i > -1:
        cnt = 0
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                cnt += 1
            else:
                break
        s = s[:i-cnt] + s[i+cnt+2:]
    else:
        break
print(len(s))

Solution (Python):
s = input()
cnt = 0
while cnt < 100000:
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) // 2
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

Solution (Python):
import numpy as np
from collections import deque
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())

st = []
X = deque(s())
N = len(X)
st.append(X[0])
X.popleft()

for i in range(N-1):
    st.append(X[0])
    X.popleft()
    if len(st) >= 2:
        if st[-1] == 'T' and st[-2] == 'S':
            st.pop()
            st.pop()
print len(st)

Solution (Python):
import numpy as np
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())

st = []
X = list(s())
N = len(X)
X.reverse()
st.append(X[-1])
X.pop()

for i in range(N-1):
    st.append(X[-1])
    X.pop()
    if len(st) >= 2:
        if st[-1] == 'T' and st[-2] == 'S':
            st.pop()
            st.pop()
print len(st)

Solution (Python):
X = raw_input()
cnt = 0
cnt_max = cnt
L = len(X)

for i in range(L):
   if X[i] == 'T':
      cnt += 1
   else:
      cnt -= 1
      
   if cnt > cnt_max: 
      cnt_max = cnt

print cnt_max * 2

Solution (Python):
s = raw_input()






temp = []
for i in range(len(s)):
    now = s[i]
    if len(temp) == 0:
        temp.append(now)
    elif temp[-1] + now == 'ST':
        temp.pop()
    else:
        temp.append(now)

print len(temp)

Solution (Python):

str = input()
res=0
s=0
for e in str:
       if e == 'S':
              s=s+1
       elif s>0:
              res=res+1
              s=s-1
print(len(str)-res*2)

Solution (Python):

str = input()
res=0
s=0
for e in str:
       if e == 'S':
              s=s+1
       elif s>0:
              res=res+1
              s=s-1
print(len(str)-res*2)

Solution (Python):
line = input()

ori = len(line)

count = 0 

T = 0 
S = 0 

for i in line:
    if i is "S":
        S += 1
    else:
        if S is not 0:
            S -= 1
            count += 1

print(ori - count * 2)

Solution (Python):
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)

Solution (Python):
x = str(input())

s_count = 0
st = 0

for i in range(len(x)):
    if(x[i]=='S'):
        s_count+=1
    else:   
        if(s_count>0):
            st+=1
            s_count-=1

print(len(x) - 2*st)

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

def solve(s):
    c=1 if s[0] == 'S' else 0
    ans=1 if s[0] == 'T' else 0

    for i in range(1, len(s)):
        if s[i] == 'S':
            if s[i-1] == 'S':
                c += 1
            else:
                ans+=c
                c=1
        else:
            if c > 0:
                c -= 1
                s[i] = 'S'
            else:
                ans += 1
    return ans+c

print(solve(s))

Solution (Python):
X = raw_input()

y = []
for n in xrange(len(X)):
    y.append(X[n])

    while (1):
        if len(y) < 2: break
        if y[-2] == 'S' and y[-1] == 'T':
            y.pop()
            y.pop()
        else:
            break

print len(y)

Solution (Python):
st = input()
sc = 0
tc = 0
for s in st:
    if s == "S":
        sc += 1
    if s == "T":
        if sc > 0:
            sc -= 1
        else:
            tc += 1

print(sc + tc)

Solution (Python):


X=input()

ans=0
dep=0
for moji in X:
    if moji == 'S':
        dep=dep+1
    else:
        if dep == 0:
            ans=ans+1
        else:
            dep=dep-1

print(ans*2)

Solution (Python):
s = raw_input().strip()
st = []
for x in s:
    st.append(x)
    while len(st) >= 2 and st[-1] == 'T' and st[-2] == 'S':
        st.pop()
        st.pop()
print len(st)

Solution (Python):
s = input()
l = len(s)

num = 0
ans = l
for i in range(l):
    if s[i] == "S":
        num += 1
    else:
        if num == 0:
            continue
        else:
            num -= 1
            ans -= 2

print(ans)

Solution (Python):
x = raw_input()

l = len(x)

s = 0
for i in x:
    if(i=='S'): s+=1
    if(i=='T' and s>0): 
        s-=1
        l-=2

print l

Solution (Python):
input_string = raw_input()

s_num = 0
str_len = len(input_string)

for c in input_string:
    if c == 'S':
        s_num += 1

    elif c == 'T':
        if s_num > 0:
            s_num -= 1
            str_len -= 2

print str_len

Solution (Python):
x=input()
stack=[]
for c in x:
    if len(stack)==0:
        stack.append(c)
    else:
        if stack[-1]=='T':
            stack.append(c)
        else:
            if c=='T':
                stack.pop()
            else:
                stack.append(c)
print(len(stack))

Solution (Python):
S = raw_input()
left = 0
ans = 0
for s in S:
    if s == 'S':
        left += 1
    elif s == 'T' and left > 0:
        left -= 1
        ans += 2
print len(S) - ans

Solution (Python):
st=raw_input()
n=len(st)
ans=n
ssc=0
for c in st:
    if c=='S':
        ssc+=1
    elif c=='T' and ssc>0:
        ans-=2
        ssc-=1
print ans

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

print(len(string) - 2 * count),

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

Solution (Python):
s=raw_input()
stack=[]
for i in xrange(len(s)):
    if len(stack)==0 or s[i]=="S":
        stack.append(s[i])
        continue
    if s[i]=="T":
        if stack[-1]=="S":
            stack.pop()
        else:
            stack.append(s[i])
print(len(stack))

Solution (Python):
def solve(s: str) -> int:
    ans = 0
    s_cnt = 0
    for c in s:
        if c == 'S':
            s_cnt += 1
        else:
            if s_cnt > 0:
                s_cnt -= 1
            else:
                ans += 1
    return ans + s_cnt

print(solve(input().strip()))

Solution (Python):
instring = raw_input()

finallen = len(instring)
num_open = 0
for char in instring:
    if (char == 'S'):
        num_open += 1
    elif(num_open > 0):
        num_open -= 1
        finallen -= 2
print finallen

Solution (Python):
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Solution (Python):



def final_length(st):
    s = 0
    t = 0
    for c in st:
        if c == "S":
            s += 1
        elif c == "T":
            if s > 0:
                s -= 1
            else:
                t += 1
    return s + t


def main():
    print(final_length(input()))


if __name__ == '__main__':
    main()

Solution (Python):
X = raw_input()
t = []
for x in X:
    if len(t)>0 and t[-1]=="S" and x=="T":
        t.pop()
    else:
        t += [x]
print len(t)

Solution (Python):
from sys import stdin

compteur=0
chaine=stdin.readline()
reste=len(chaine)-1
for caractere in chaine:
    if caractere=="S":
        compteur+=1
    elif caractere=="T" and compteur>0:
        compteur-=1
        reste-=2
print(reste)

Solution (Python):
cs = input()
i = 0
r = 0
for c in cs:
    if c=="S":
        i += 1
    elif i>0:
        i -= 1
        r += 1
print(len(cs) - 2*r)

Solution (Python):



X = input()
S = ""
for ch in X:
    if ch == 'S':
        S += ch
    else:
        if len(S) > 0 and S[-1] == 'S':
            S = S[:-1]
        else:
            S += ch
print(len(S))

Solution (Python):


s = raw_input()

a = []
for c in s:
	if c == 'S':
		a.append(c)
	else:
		if len(a) > 0 and a[-1] == 'S':
			a.pop()
		else:
			a.append(c)

print len(a)

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

X = s()

con = 0
dec = 0
for c in X:
    if c == 'S':
        con += 1
    elif con > 0:
        con -= 1
        dec += 2
    else:
        con = 0

print len(X) - dec

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    s = input()
    r = 0
    n = 0
    for c in s:
        if c == 'S':
            n -= 1
        else:
            n += 1
        if r < n:
            r = n

    return r*2

print(f())

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

X = input()

n = 0
for x in X:
  if x == "S":
    n += 1
  else:
    if n > 0:
      n -= 1

print(2*n)

Solution (Python):
X = raw_input()
ans = ""
for c in X:
    ans += c
    if len(ans) >= 2 and ans[-2:] == "ST":
        ans = ans[:-2]
print len(ans)