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

ans = len(x)
tmp_s = 0
mae = 1

for i in range(len(x)):
    if x[i] == 'S':
        
        
        tmp_s += 1
    elif tmp_s > 0:
        ans -= 2
        tmp_s -= 1
        mae = 0
        
print(ans)

Solution (Python):

X = input()

T = 0
S = 0

for i in X:

    if i == "S":
        S += 1

    else:
        if S > 0:
            S -= 1
        else:
            T += 1

print (S+T)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)


def test(S):
    s = S[:]
    while 'ST' in s:
        s = s.replace('ST', '')
        print(s)
    return len(s)


S = np.array(list(S), dtype='U1')
st = np.zeros(N, dtype=int)
st[S == 'S'] = 1
st[S == 'T'] = -1
print(min(st.cumsum()) * -2)

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

Solution (Python):
A = input()
n = len(A)
A += "S"
sc, tc, c = 0, 0, 0
for i in range(n):
  if A[i] == "S":
    sc += 1
  else:
    tc += 1
    if A[i+1] == "S":
      if sc <= tc:
        c += sc
        sc = 0
        tc = 0
      else:
        c += tc
        sc -= tc
        tc = 0
print(n-2*c)

Solution (Python):

import numpy as np

X = input()

Y = np.zeros(len(X), dtype=int)
for i in range(len(X)):
    if X[i] == 'S':
        Y[i] = -1
    else:
        Y[i] = 1

answer = 2 * Y.cumsum().max()
print(answer)

Solution (Python):
x = input()

stack = []
cnt = 0
for c in x:
  
  if not stack:
    stack.append(c)

  else:
    
    if c == "S":
      
      stack.append(c)

    
    else:
      
      top = stack.pop()

      
      if top == 'S' and c == 'T':
        cnt += 2
        
print(len(x)-cnt)

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

Solution (Python):
X = input()
ans = len(X)
N = len(X)
cnt_s = 0
cnt_t = 0
for i in range(N):
    if X[i] == "S":
        cnt_s += 1
    if X[i] == "T":
        cnt_t += 1
    
    if i < N -1:
        if X[i] == "T" and X[i + 1] == "S":
            ans -= 2 * min(cnt_s, cnt_t)
            cnt_s -= min(cnt_s, cnt_t)
            cnt_t = 0
    if i == N - 1:
        ans -= 2 * min(cnt_s, cnt_t)
    
print(ans)

Solution (Python):
X = list(input())
rm = 0
cntS = 0
for x in X:
  if x == "S":
    cntS += 1
  else:
    if cntS > 0:
      rm += 1
    cntS = max(0, cntS-1)
print(len(X)-rm*2)

Solution (Python):
X=input()
scount=0
ngcount=0
for x in X:
  if x=="S":
    scount+=1
  else:
    if scount>0:
      scount-=1
    else:
      ngcount+=1
print(ngcount*2)

Solution (Python):
def main():
    x=list(input())
    ans=cnt=key=0
    for i in range(len(x)):
        if key==0 and x[i]=="T":
            ans+=1
        elif x[i]=="S":
            key=1
            cnt+=1
        elif key==1 and x[i]=="T":
            cnt-=1
            if cnt==0:
                key=0
    ans+=cnt
    print(ans)
main()

Solution (Python):
X=input()
idx=0
motolenx=len(X)
lenx=len(X)
scount=0
while idx<motolenx:

    if X[idx]=="S":
        scount+=1
    if X[idx]=="T" and scount>0:
        scount-=1
        lenx-=2
    idx+=1


print(lenx)

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

Solution (Python):
s = input()

mx = 0
l = len(s)
now = 0
for i in range(l):
    if s[i] == "T":
        now += 1
        mx = max(now,mx)
    else:
        now -= 1

print(mx*2)

Solution (Python):
X = input()
l = [''] * 2*10**5

last = X[0]
l[0] = X[0]
lastSindex = []
if last == 'S':
    lastSindex.append(0)

for i, a in enumerate(X):
    if i == 0:
        continue
    
    if a == 'T':
        if len(lastSindex) != 0:
            li = lastSindex.pop()
            l[li] = ''
        else:
            l[i] = a
    if a == 'S':
        lastSindex.append(i)
        l[i] = a

print(len(''.join(l)))

Solution (Python):
s = input()
a = list()
a.append('Q')

for i in range(len(s)):
    ch = s[i]
    if(ch == 'T' and a[len(a)-1]=='S'):
        a.pop()
    else:
        a.append(ch)
        
s = ""
s = s.join(a)

print(len(s)-1)

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

ans=0
s=0
for x in X:
  if x=="T":
    if s==0:
      pass
    else:
      s-=1
      ans+=1
  else:
    s+=1
    
print(len(X)-2*ans)

Solution (Python):
s = input()
lens = len(s)
cnts = 0
ans = 0
for i in s:
  if i == 'S':
    cnts += 1
  elif i == 'T' and cnts > 0:
    ans += 1
    cnts -= 1
print(lens-ans*2)

Solution (Python):
X = input()

countS = 0
countT = 0
for x in X:
  if x == 'S':
    countS += 1
  if x == 'T' and countS > 0:
    countT += 1
    countS -= 1
print(len(X)-countT*2)

Solution (Python):
x=input()
length=len(x)
x=x+"E"
ch=x[0]
lists=[]
counter=1
for i in range(length):
    if x[i]==x[i+1]:
        counter+=1
    elif x[i]!=x[i+1] :
        lists.append(counter)
        counter=1
uselist=[]
if x[0]=="S" and x[-2]=="S":
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="S" and x[-2]=="T":
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
   
elif x[0]=="T" and x[-2]=="S":
    lists.insert(0,0)
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="T" and x[-2]=="T":
    lists.insert(0,0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
        
num=len(uselist)
uselist.append((0,0))
a=0
b=0
count=0
for i in range(num):
    a+=uselist[i][0]
    b+=uselist[i][1]
    if a<=b:
        count+=b-a
        a=0
        b=0
    if i==num-1 and a>b:
        count+=a-b
print(count)

Solution (Python):
S = input()
ans = 0
pos = 0
scount = 0

while pos < len(S):

    while pos <len(S) and S[pos] == 'T':
        pos += 1
        ans += 1
    if pos >= len(S):
        break

    while pos <len(S) and S[pos] == 'S':
        pos += 1
        scount += 1
    if pos >= len(S):
        ans += scount
        break

    tcount = 0
    while pos < len(S) and S[pos] == 'T':
        pos += 1
        tcount += 1
    if pos >= len(S):
        ans += abs(scount-tcount)
        break
      
    if scount >= tcount:
        scount = scount -tcount
    else: 
        ans += tcount-scount
        scount = 0

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

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

if __name__ == '__main__':
    main()

Solution (Python):
X = input()

result = 0
t = 0
for i in range(len(X)):
    if X[i] == 'S':
        t += 1
    else:
        if t != 0:
            result += 2
            t -= 1
print(len(X) - result)

Solution (Python):
l=list(input())
n=len(l)
s=0
ans=n
for i in range(n):
    if l[i]=='S':
        s+=1
    if s>0 and l[i]=='T':
        s-=1
        ans-=2
print(ans)

Solution (Python):
from collections import deque

X = input()
stack = deque([X[0]])

for i in X[1:]:
    if stack:
        if stack[-1] == 'S' and i == 'T':
            stack.pop()
        else:
            stack.append(i)
    else:
        stack.append(i)

print(len(stack))

Solution (Python):
X=input()
k=0 
cnt=0 
for c in X:
    if c=='S':
        k+=1
    else:
        if k==0:
            cnt+=1
        else:
            k-=1
print(cnt*2)

Solution (Python):
X=input()
k=0 
cnt=0 
for c in X:
    if c=='S':
        k+=1
    else:
        if k==0:
            cnt+=1
        else:
            k-=1
print(cnt*2)

Solution (Python):
x = input()

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

Solution (Python):
w=input()
count=0
counts=0
for i in range(len(w)):
  if w[i]=="S":
    counts+=1
  else:
    if counts!=0:
      counts-=1
      count+=1
print(len(w)-count*2)

Solution (Python):
stack = 0
cnt = 0
for x in input():
    if x == "S": stack += 1
    else:
        if stack: stack -= 1
        else: cnt += 1
print(cnt + stack)

Solution (Python):



import sys


def main():
    X = input()
    t = 0
    s = 0

    for x in X:
        if x == 'T':
            if s == 0:
                t += 1
            else:
                s -= 1
        else:
            s += 1

    print(t+s)


if __name__ == '__main__':
    main()

Solution (Python):
x=str(input())
c=0
ans=0
for i in x:
    if i=='S':
        c+=1
    if c>0 and i=='T':
            c-=1
            ans+=2

print(len(x)-ans)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    x = str(input().rstrip('\n'))
    s = 0
    cnt = 0
    for i in range(len(x)):
        if x[i] == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                cnt += 1
    print(len(x) - cnt * 2)


if __name__ == '__main__':
    slove()

Solution (Python):
X=list(input())
N=len(X)
count=0

for x in X:
    if x=="S":
        count+=1
    else:
        if count>0:
            count-=1
            N-=2
print(N)

Solution (Python):



def main():
    ans=0
    tmp=0
    x=input()
    for i in x:
        if tmp==0 and i=="T":
            ans+=1
        elif i=="T":
            tmp-=1
        else:
            tmp+=1
    print(ans*2)

if __name__ == '__main__':
    main()

Solution (Python):
S=input()

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

Solution (Python):
x = input()
n = len(x)
res = 0
tres = 0
for c in x:
    if c == 'T':
        tres += 1
    else:
        tres -= 1
    res = max(tres,res)

print(res * 2)

Solution (Python):
x=input()
ans=len(x)
n=0
for i in x:
  if i=="S":
    n+=1
  elif i=="T" and n>0:
    n-=1
    ans-=2
print(ans)

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

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

Solution (Python):
S=input()

tmp=0
ans=len(S)

for s in S:
  if s=="S":
    tmp+=1
  if s=="T" and tmp>0:
    ans-=2
    tmp-=1

print(ans)

Solution (Python):
S=input()
A1=[]
L=len(S)
A1.append(S[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and S[i]=="T":
        A1.pop(-1)
    else:
        A1.append(S[i])

print(len(A1))

Solution (Python):
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and A2[i]=="T":
        A1.pop(-1)
    else:
        A1.append(A2[i])

print(len(A1))

Solution (Python):

def main():
    s = list(input())
    l = ["b"]
    for i in range(len(s)):
        if s[i] == "S":
            l.append("S")
        elif s[i] == "T" and (l[-1] == "T" or len(l) == 1):
            l.append("T")
        elif s[i] == "T" and l[-1] == "S":
            l.pop()
    print(len(l) - 1)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    x = input().strip() + "x"
    c = []
    pre = x[0]
    count = 1
    for i in range(1, len(x)):
        if x[i] != pre:
            c.append(count)
            count = 1
        else:
            count += 1
        pre = x[i]

    ans = len(x) - 1
    stock = 0
    if x[0] == "S":
        start = 1
    else:
        start = 2

    for i in range(start, len(c), 2):
        if c[i-1] + stock <= c[i]:            
            ans -= (c[i-1]+stock) * 2
            stock = 0
        else:
            ans -= c[i] * 2
            stock += c[i-1] - c[i]
    
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
t=m=0
for c in input():t+=2if c=="T"else-2;m=max(m,t)
print(m)

Solution (Python):
def resolve():
    x = input()
    ans = [x[0]]
    for c in x[1:]:
        if ans and ans[-1] == "S" and c == "T":
            ans.pop()
        else:
            ans.append(c)
    print(len(ans))


if __name__ == "__main__":
    resolve()

Solution (Python):
def a_st_ring():
    X = input()
    stack = []
    for c in X:
        if len(stack) > 0 and stack[-1] == 'S' and c == 'T':
            stack.pop()
        else:
            stack.append(c)
    return len(stack)

print(a_st_ring())

Solution (Python):
a = []
x = input()
for i in x:
    if i == "T":
        if len(a) == 0 or a[-1] == "t":
            a.append("t")
        else:
            del a[-1]
    else:
        a.append("s")
print(len(a))

Solution (Python):
x = input()
cur = x[0]
cnt = 0
rle = []
for i in x:
    if i == cur:
        cnt += 1
    else:
        rle.append([cur, cnt])
        cur = i
        cnt = 1
rle.append([cur, cnt])

n = len(rle)
ans = 0
for i, (cur, cnt) in enumerate(rle):
    if cur == "T":
        continue
    if i+1 < n:
        nxt, nxt_cnt = rle[i+1]
        if cnt <= nxt_cnt:
            ans += cnt
        else:
            ans += nxt_cnt
            if i+2 < n:
                rle[i+2][1] += cnt-nxt_cnt
print(len(x) - 2*ans)

Solution (Python):
X = input()
rs = []
n = 0
for c in X:
  if c == "T":
    n += 1
  if c == "S":
    n -= 1
  rs.append(n)
r = max(rs)*2
print(r)

Solution (Python):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline


S = list(input().strip())

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(s + t)

Solution (Python):
import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    A = []
    for c in X:
        if len(A) > 0 and A[-1] == "S" and c == "T":
            A.pop()
        else:
            A.append(c)
    print(len(A))

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
scnt=0;tcnt=0
for i in s:
  if i=="T":
    if scnt!=0:
      scnt-=1
    else:tcnt+=1
  elif i=="S":
    scnt+=1
print(scnt+tcnt)

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

Solution (Python):
X = input()
s = cnt = 0

for i in range(len(X)):
    if X[i] == 'S':
        s += 1
    elif s != 0:
        cnt += 2
        s -= 1

ans = len(X) - cnt
print(ans)

Solution (Python):
from collections import deque
s = input()
d = deque([])
for i in s:
  if d:
    if d[-1] == "S" and i == "T":
      d.pop()
    else:
      d.append(i)  
  else:
    d.append(i)
print(len(d))

Solution (Python):
x = input()

s=t=k=0

for i in range(len(x)):
  if x[i] =='S':
    s+=1
  elif s!=0:
    k+=2
    s-=1
    
print(len(x) -k)

Solution (Python):
x=list(input())
ans=0
check=0
for i in x:
	if i=='T':
		if check==0:
			ans+=1
		check-=1
		check=max(check,0)

	else:
		check+=1
print(ans*2)

Solution (Python):
x=input()
s=t=k=0
for i in range(len(x)):
	if x[i]=="S":
		s+=1
	elif s!=0:
		k+=2
		s-=1
print(len(x)-k)

Solution (Python):
x=list(input())
from collections import deque
l=deque()
for a in x:
    if a=="S":
        l.append(a)
    else:
        if not l or l[-1]=="T":
            l.append(a)
        else:
            d=l.pop()
print(len(l))

Solution (Python):
X = input()
cnt_s = 0
ans_t = 0
for x in X:
    if x == "S":
        cnt_s += 1
    else:
        if cnt_s > 0:
            cnt_s -= 1
        else:
            ans_t += 1
print(ans_t*2)

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

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

Solution (Python):
x = input()

ans = ""
for i in x:
  ans += i
  if len(ans) >= 2 and (ans[-2] == "S" and ans[-1] == "T"):
    ans = ans[:-2]

print(len(ans))

Solution (Python):
X = input()
Y = []
for i in X:
    Y.append(i)
    if len(Y) > 1:
        if Y[-2] + Y[-1] == "ST":
            Y.pop()
            Y.pop()
print(len(Y))

Solution (Python):
def main():
    S = input()
    stack = []
    for i in range(len(S)):
        stack.append(S[i])
        while len(stack) > 1 and "".join(stack[-2:]) == "ST":
            stack.pop()
            stack.pop()
        
    return len(stack)


if __name__ == '__main__':
    print(main())

Solution (Python):


from collections import Counter,deque


from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
q=deque()
for i in s:
    if i=="S":
        q.append(i)
    else:
        if len(q)==0:
            q.append(i)
        elif q[-1]=="T":
            q.append(i)
        else:
            q.pop()
   
print(len(q))

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

Solution (Python):


import sys




x = input()

x_len=len(x)


ans=0
store=0
for i in range(0,x_len):
	if(x[i]=="S"):
		store+=1
	else:
		if(store>0):
			store-=1
		else:
			ans+=1
print(ans*2)

Solution (Python):
x = input()
t = 0
c = 0
for i in range(len(x)):
    if x[-i-1] == "T":
        t += 1
    else:
        r = 1 if t > 0 else 0
        t -= r
        c += r
print(len(x) - c * 2)

Solution (Python):
s = input()

del_list = [] 
l = 0
pointer = 0
for i,v in enumerate(s):
    if v == "S":
        del_list.append([i,-1])
        l += 1
    else:
        if l != 0 and pointer != l:
            del_list[pointer][1]  = i
            pointer += 1


rems = 0
delpair = 0
for i in del_list:
    if i[1] == -1:
        rems += 1
    else:
        delpair += 1

remt = s.count("T") - delpair
print(remt+rems)

Solution (Python):

import sys, math, fractions, itertools, collections, copy, heapq


def solve(X: str):
    stack = []
    for s in X:
        if s == 'S':
            stack.append(s)
        if s == 'T':
            if len(stack) == 0:
                stack.append(s)
            elif stack[-1] == 'T':
                stack.append(s)
            elif stack[-1] == 'S':
                stack.pop()
    print(len(stack))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = next(tokens)  
    solve(X)

if __name__ == '__main__':
    main()

Solution (Python):
def sol():
    X = input()

    scount = 0
    ans = 0
    for x in X:
        if x == 'S':
            scount += 1
        else:
            if scount == 0:
                ans += 1
            else:
                scount -= 1

    print(ans * 2)

sol()

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

Solution (Python):
x = input()

s = []
for i in range(len(x)):
    if x[i] == "S":
        s.append(x[i])
    else:
        if len(s) != 0 and s[-1] == "S":
            s.pop(-1)
        else:
            s.append(x[i])

print(len(s))

Solution (Python):
a=b=0
for i in input():c=i=="T";d=a>0;a+=1-c-c*d;b+=c*(1-d)
print(a+b)

Solution (Python):



x=input()
n=len(x)
stack=[]

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

Solution (Python):


x=input()
n=len(x)
ans=n
cnt=0

for i in range(n):
    if x[i]==('S'):
        cnt+=1
    else:
        if cnt>0:
            cnt-=1
            ans-=2
print(ans)

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

Solution (Python):
s = input()
tt = 0
cnt = 0
for i in range(len(s)):
    if s[-i-1] == "T":
        tt += 1
    elif s[-i-1] == "S":
        t = min(1, tt)
        cnt += t
        tt -= t
print(len(s) - cnt * 2)

Solution (Python):
S = input()
ans = 0
cnt = 0
for s in S:
    if s == "T":
        if cnt == 0:
            ans += 1
        else:
            cnt -= 1
    else:
        cnt += 1
print(ans*2)

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

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

stack = []
x = input()
n = len(x)
for i in range(n):
    if x[i] == 'S':
        stack.append(x[i])
    else:
        if len(stack) == 0 or stack[-1] != 'S':
            stack.append(x[i])
        elif stack[-1] == 'S':
            stack.pop()
print(len(stack))

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

count = 0
for i in range(len(x)):
    if x[i] == "S":
        count += 1
    else:
        count -= 1
    if count < 0:
        ans+=1
        count = 0
count = 0
for i in range(len(x)-1,-1,-1):
    if x[i] == "T":
        count += 1
    else:
        count -= 1
    if count <0 :
        ans+=1
        count = 0
print(ans)

Solution (Python):
s=input()
cnt_s=0
cnt_t=0
ans=len(s)
for i in s:
    if i=="S":
        cnt_s+=1
    else:
        if cnt_s>0:
            cnt_s-=1
            ans-=2
print(ans)

Solution (Python):
l=[]
x=list(input())
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

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

count_S = 0
count_T = 0
TS_max = 0

for i in range(len(X)):
    if X[i] == 'S':
        count_S += 1
    elif X[i] == 'T':
        count_T += 1
    tmp = count_T - count_S
    TS_max = max(TS_max, tmp)

ans = TS_max * 2
print(ans)

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

Solution (Python):


x=input()
sbuf = 0
tot = len(x)
for c in x:
    if c == "S":
        sbuf += 1
    else:
        if sbuf > 0:
            sbuf -= 1
            tot-=2

print(tot)

Solution (Python):
a = input()
t = 0
cnt = 0
for i in range(len(a)-1, -1, -1):
    if a[i] == "T":
        t += 1
    elif a[i] == "S" and t != 0:
        t -= 1
        cnt += 1
print(len(a) - cnt * 2)

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

Solution (Python):
from collections import deque

S = input()
lenS = len(S)
pops = 0
ans = lenS
stack = deque()
for i in range(lenS):
    if stack and S[i] == "T":
        a = stack.pop()
        if a == "S":
            ans -= 2
    else:
        stack.append(S[i])
print(str(ans))

Solution (Python):
X = input()

cnt1 = 0
cnt2 = 0
cnt = 0
for i in range(len(X)):
    if X[i] == 'S':
        if cnt2:
            cnt += cnt2 * 2
            cnt2 = 0
        cnt1 += 1
    elif cnt1 and X[i] == 'T':
        cnt2 += 1
        cnt1 -= 1

if cnt2:
    cnt += cnt2 * 2

print(len(X) - cnt)

Solution (Python):




X=input()
st=0
cnt=0
for i in range(len(X)):
    if X[i]=='S':
        st+=1
    else:
        if st>0:
            st-=1
            cnt+=1
print(len(X)-cnt*2)

Solution (Python):
X=input()
ans=0
memo=0
for i in range(len(X)):
    if X[i]=="T":
        if memo==0:pass
        else:memo-=1
    else:memo+=1
print(memo*2)

Solution (Python):
def main():
    ls = list(input())
    t = 0
    cnt = 0
    for i in reversed(range(len(ls))):
        if ls[i]=="T":
            t +=1
        if ls[i]=="S":
            if t==0:
                pass
            else:
                cnt +=2
                t -= 1
    print(len(ls)-cnt)
if __name__ == '__main__':
    main()

Solution (Python):
x = list(input())
count = 0
stock_s = 0

for i in range(len(x)):
    if x[i] == "S":
        stock_s += 1
    else:
        if stock_s > 0:
            stock_s -= 1
        else:
            count += 1
print(count * 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

import re




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()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



X = input()

t_cnt, s_cnt = 0, 0
for Xi in X:
    if Xi == "S":
        s_cnt += 1
    elif Xi == "T":
        if s_cnt > 0:
            s_cnt -= 1
        else:
            t_cnt += 1

print(t_cnt + s_cnt)

Solution (Python):

def main():
    X = input().rstrip()
    ans, p = 0, 0  
    for i in X:
        if i == "S":
            p += 1
        else:
            if p:
                p -= 1
            else:
                ans += 1  
    ans += p  
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    X = input().rstrip()
    ans, s, t = 0, 0, 0
    for i in X:
        if i == "S":
            s += 1
        else:
            if t < s:
                t += 1
            else:
                ans += 1
    ans += s - t
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
X = list(input())
S = 0
T = 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):
def solve(x):
    n = len(x)
    f, s = 0, 0
    for c in x:
        if c == "S":
            f += 1
        elif f > 0:
            f -= 1
            s += 2
    return n - s

x = input()
print(solve(x))

Solution (Python):
X = input()
ans = 0
S_count = 0
for i in range(len(X)):
    if X[i] == 'S':
        S_count -= 1
    elif S_count == 0 and X[i] == 'T':
        ans += 1
    elif X[i] == 'T':
        S_count += 1

print(2*ans)

Solution (Python):
def main():
    X = input()
    ans = len(X)
    s = 0
    for c in X:
        if c == "S":
            s += 1
        elif c == "T":
            if s:
                s -= 1
                ans -= 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    data  = list(input())

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

    print(ans)




if __name__ == '__main__':
    main()

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

print(s+t)

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

print(s+t)

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

c = 0
uppun = 0
for i, x in enumerate(X):
    if x == 'S':
        uppun += 1
    if x == 'T':
        c += 1
        if uppun > 0:
            uppun -= 1
    if c == N//2:
        ans = N - (i+1-c - uppun)*2
        break

print(ans)

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

Solution (Python):
s=input()
ss=0
tt=0
for i in range(len(s)):
    if s[i]=="S":
        ss+=1
    if s[i]=="T" and tt<ss:
        tt+=1
print(len(s)-2*tt)

Solution (Python):
X = input()

count = 0
count_s = 0
i = 0
while i < len(X):
    if i < len(X) - 1 and X[i] == 'S' and X[i+1] == 'T':
        count += 1
        i += 1
    elif X[i] == 'S':
        count_s += 1
    elif X[i] == 'T' and count_s > 0:
        count_s -= 1
        count += 1
    else:
        count_s = 0
    i += 1

count = min(count, 10 ** 10000)
print(len(X) - count * 2)

Solution (Python):



X = list(input())
num = len(X)
stack = []

for i in X:
    if i == "S":
        stack.append(i)
    else:
        if stack == [] or stack[-1] == "T":
            stack.append(i)
        else:
            stack.pop()
print(len(stack))