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

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

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

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

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

for char in s:
    if len(stack) == 0:
        stack.append(char)
        continue
    
    if stack[-1] + char == "ST":
        stack.pop(-1)
    else:
        stack.append(char)
print(len(stack))

Solution (Python):
x=input()

c_s=0
c_t=0

for i in x:
  if i=='S':
    c_s+=1
  else:
    if c_s==0:
      c_t+=1
    else:
      c_s-=1

print(c_s+c_t)

Solution (Python):
x = input()

s = [""]
for xi in x:
    if xi == "S":
        s.append(xi)
    elif xi == "T":
        if s[-1] == "S":
            s.pop()
        else:
            s.append(xi)

print(len(s) - 1)

Solution (Python):
X=input()
level=0
rem=0
for i,s in enumerate(X):
    if s=="S":
        level+=1
    else:
        if level>0:
            level-=1
            rem+=1
print(len(X)-rem*2)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
s = readline().rstrip().decode('utf-8')
n = len(s)
s_count = 0
ans = 0
i=0
while True:
    if i == n:
        break
    if s[i] == "T":
        if s_count > 0:
            s_count-=1
            ans+=2
    else:
        s_count+=1
    i+=1


print(n-ans)

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

Solution (Python):
x = input()
x = "T" + x + "S"
ar = []
c = 1
for i in range(1, len(x)):
    if x[i-1] == x[i]:
        c += 1
    else:
        ar.append(c)
        c = 1
ar.append(c)

ssum = ar[1]
trem = ar[0]
for i in range(2, len(ar), 2):
    trem += max(0, ar[i]-ssum)
    ssum -= min(ssum, ar[i])
    ssum += ar[i+1]
print(ssum+trem-2)

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

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

Solution (Python):







s = input()
score = max_score = 0
for ch in s:
    if ch == "T":
        score += 1
        max_score = max(score, max_score)
    elif ch == "S":
        score -= 1
print(max_score * 2)

Solution (Python):
from collections import deque
def main():
    X = input()
    stack = deque([])
    for i in range(len(X)):
        if X[i] == "S":
            stack.append(X[i])
        else:
            if len(stack) != 0:
                tmp = stack.pop()
                if tmp == "T":
                    stack.append(tmp)
                    stack.append(X[i])
            else:
                stack.append(X[i])
    print(len(stack))
if __name__ == '__main__':
    main()

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

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

Solution (Python):
S = input()

count = len(S)
N = count
s_count = 0
t_count = 0

i = 0
while i < N:
    if S[i] == 'S':
        s_count += 1
        i += 1
    else:
        if s_count != 0:
            tmp = i
            while tmp < N and S[tmp] == 'T':
                tmp += 1
                t_count += 1
            if s_count > t_count:
                cut = t_count
                s_count = s_count - t_count
                t_count = 0
            else:
                cut = s_count
                s_count = t_count = 0
            count -= cut*2
            i += cut
        else:
            i += 1

        
print(count)

Solution (Python):
from collections import deque

X = input()
N = len(X)
S = "S"
T = "T"
stack = deque("")

for i,str in enumerate(X):
  if str == S:
    stack.append(str)
  elif str == T:
    if len(stack) == 0:
      stack.append(str)
    elif stack[-1] == T:
      stack.append(str)
    elif stack[-1] == S:
      stack.pop()
      
print(len(stack))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X = input().strip()


    scount = 0
    ans = 0
    for s in X:
        if s == "S":
            scount += 1
        elif s == "T":
            if scount == 0:
                continue
            else:
                scount -= 1
                ans += 2

    print(len(X) - ans)



if __name__ == '__main__':
    main()

Solution (Python):
def examA():
    X = SI()
    d = defaultdict(int)
    for s in X:
        if s=="T" and d["S"]>=1:
            d["S"] -=1
        else:
            d[s] += 1
    ans = d["S"] + d["T"]
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

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

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

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

Solution (Python):
x=list(input())
n=len(x)

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

Solution (Python):
X = input()
ans=0
s_cnt=0
for tmp in X:
    if tmp =="T":
        if s_cnt==0:
            ans+=1
        else:
            s_cnt-=1
    if tmp=="S":
        s_cnt+=1
print(ans+s_cnt)

Solution (Python):
X = input()

n = 0
ans = len(X)
for c in X:
    if c == 'S':
        n += 1
    elif n > 0:
        n -= 1
        ans -= 2

print(ans)

Solution (Python):
from sys import stdin
inf = 10**10

s = stdin.readline().rstrip()

point_s = 0
point_t = 0

for i in s:
    if i == "S":
        point_s += 1
    else:
        if point_s:
            point_s -= 1
        else:
            point_t += 1

print(point_s+point_t)

Solution (Python):
x=input()
ans=[]
for i in range(len(x)):
    if(x[i]=='S'):
        ans.append(x[i])
    elif(len(ans)>0 and ans[-1]=='S'):
        ans.pop()
    else:
        ans.append(x[i])
print(len(''.join(ans)))

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

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

for c in x:
    if c == "S":
        s += 1
    else:
        if s != 0:
            s -= 1
        else:
            ans += 1
else:
    ans += s

print(ans)

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

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

tcnt_l = 0
scnt_l = 0
for i in range(N):
    if X[i] == "T" and scnt_l == 0:
        tcnt_l += 1
    elif X[i] == "S":
        scnt_l += 1
    else:
        scnt_l -= 1

tcnt_r = 0
scnt_r = 0
for i in range(N-1,-1,-1):
    if X[i] == "S" and tcnt_r == 0:
        scnt_r += 1
    elif X[i] == "T":
        tcnt_r += 1
    else:
        tcnt_r -= 1

print(tcnt_l+scnt_r)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    
    S = Scanner.string()
    cnt = 0
    ans = 0
    for s in S:
        if s == "S":
            cnt += 1
        else:
            if cnt > 0:
                cnt -= 1
                ans += 1
    print(len(S) - ans * 2)
    return


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys


def main():
    S = str(input())
    N = len(S)
    sc = 0
    count = 0
    for r in range(N):
        if S[r] == "T":
            if sc == 0:
                continue
            else:
                sc -= 1
                count += 1
        else:
            sc += 1
            
    print(N-2*count)

if __name__ == "__main__":
    main()

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

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

x = ns()
n = len(x)

ans = n
i = 0
cs = 0
while i < n:
    if x[i] == 'S':
        cs += 1
        i += 1
    else:
        ct = 0
        while i < n and x[i] == 'T':
            ct += 1
            i += 1
        ans -= min(cs, ct) * 2
        cs -= min(cs, ct)

print(ans)

Solution (Python):
X = input()

result = len(X)
n_S = 0
for c in X:
    if c == 'S':
        n_S += 1
    elif c == 'T':
        if n_S > 0:
           n_S -= 1 
           result -= 2
    else:
        raise ValueError
print(result)

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

ans = 0
stock = 0
for x in xl:
    if x == "S":
        stock += 1
    else:
        if stock:
            stock -= 1
            ans += 1

print(len(xl)-2*ans)

Solution (Python):
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 += 2
        
print(N - ans)

Solution (Python):
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 += 2
print(N-ans)

Solution (Python):
x = input()

s = list()
cnt = 0
for c in x:
    if c == "S":
        s.append(c)
    elif c == "T" and len(s) != 0:
        s.pop()
        cnt += 1

print(len(x)-cnt*2)

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

cnt_S = 0
cnt_T = 0

for i in range(len(x)):
    if x[i] == "S":
        cnt_S += 1
    
    elif x[i] == "T":
        if cnt_T < cnt_S:
            cnt_T += 1

print(len(x)-2*cnt_T)

Solution (Python):
X = input()

stacks = []
for i in range(len(X)):
    if not stacks:
        stacks.append(X[i])
    elif stacks[-1] == "S" and X[i] == "T":
        del stacks[-1]
    else:
        stacks.append(X[i])

print(len(stacks))

Solution (Python):
X = input()

ans = 0
cnt = 0
for i in range(len(X)):
    if cnt == 0 and X[i] == "T":
        ans += 1
    else:
        if X[i] == "T":
            cnt += 1
        else:
            cnt -= 1

print(ans*2)

Solution (Python):
s=input()

from collections import deque

stack=deque()

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

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

Solution (Python):
s_list = list(input())
seizon_t = 0
s_amari = 0
for char in s_list:
  if char == "T":
    if s_amari == 0:
      seizon_t += 1
    else:
      s_amari -= 1
  else:
    s_amari += 1
print(2*seizon_t)

Solution (Python):
from collections import deque

X = input()

ret = deque([X[0]])
for i in range(1, len(X)):
    x = X[i]
    if x == 'S':
        ret.append(x)
    else:
        if len(ret) > 0 and ret[-1] == 'S':
            ret.pop()
        else:
            ret.append(x)
print(len(ret))

Solution (Python):



X = input()

N = len(X)

cnt_S = 0
cnt_T = 0
cnt_delete = 0
for i in range(N):
    if i == 0:
        if X[i] == "S":
            cnt_S += 1
        else:
            cnt_T += 1
    else:
        if X[i-1] == "S" and X[i] == "S":
            cnt_S += 1
        elif X[i-1] == "S" and X[i] == "T":
            cnt_T += 1
        elif X[i-1] == "T" and X[i] == "T":
            cnt_T += 1
        elif X[i-1] == "T" and X[i] == "S":
            tmp = min(cnt_S, cnt_T)
            cnt_delete += tmp*2
            cnt_S -= tmp
            cnt_T = 0
            cnt_S += 1

    if i == N-1:
        tmp = min(cnt_S, cnt_T)
        cnt_delete += tmp*2

print(N - cnt_delete)

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

Solution (Python):
x = input()

counter = 0
stack = []

for i in range(len(x)):
    if x[i] == "S":
        stack.append("S")
    elif stack:
        stack.pop()
        counter += 1

print(len(x) - 2 * counter)

Solution (Python):
X = input()
xlst = []
xlst.append(X[0])
for i in range(1, len(X)):
    if X[i] == 'S':
        xlst.append(X[i])
    else:
        if xlst != [] and xlst[-1] == 'T':
            xlst.append(X[i])
        elif xlst != [] and xlst[-1] == 'S':
            xlst.pop()
        else:
            xlst.append(X[i])

print(len(xlst))

Solution (Python):
X = input()
xlst = []
xlst.append(X[0])
for i in range(1, len(X)):
    if X[i] == 'S':
        xlst.append(X[i])
    else:
        if xlst != [] and xlst[-1] == 'T':
            xlst.append(X[i])
        elif xlst != [] and xlst[-1] == 'S':
            xlst.pop()
        else:
            xlst.append(X[i])

print(len(xlst))

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

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

Solution (Python):
X=input()
Y=[0]*len(X)

for i in range(len(X)):
    if X[i]=='T':
        Y[i]=1


from collections import deque

Z=deque([])
for i in range(len(X)):
    c=Y[i]
    if c==0:
        Z.append(c)
    elif Z==deque([]):
        Z.append(c)
    elif Z[-1]==1:
        Z.append(c)
    else:
        Z.pop()

print(len(Z))

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

Solution (Python):

ST = input()
flag = False
pool_s = 0
pair = 0
flag = 0
for v in ST:
    if flag == False and v == "S":
        flag = True
        pool_s = 1
    elif flag and v == "T":
        if pool_s > 0:
            pair += 1
            pool_s -= 1
        else:
            pool_s = 0
            flag = False
    elif flag and v == "S":
        pool_s += 1
print(len(ST) - pair * 2)

Solution (Python):

X = input()
ans = 0
cnt = 0
for x in X:
    if x=="S":
        cnt+=1
    else:
        if (cnt>0):
            cnt-=1
            ans+=1
print (len(X)-2*ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    x = S()
    ans = len(x)
    l = 0
    for xi in x:
        if xi == "T":
            if l:
                l -= 1
                ans -= 2
        else:
            l += 1
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
X = input().strip()
cnt = 0
cntmax = 0
for i in range(len(X)):
    if X[i]=="T":
        cnt += 1
        cntmax = max(cntmax,cnt)
    else:
        cnt -= 1
print(cntmax*2)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	
	scnt = 0
	remove = 0
	for s in S:
		if s == 'S':
			scnt += 1
		else:
			if scnt:
				scnt -= 1
				remove += 2
	
	
	print(len(S)-remove)

if __name__ == '__main__':
	main()

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

Solution (Python):
x = input()

s = 0
cnt = len(x)
for i in x:
    if i == "T":
        if s > 0:
            s -= 1
            cnt -= 2
        else:
            s = 0
    if i == "S":
        s += 1
print(cnt)

Solution (Python):
x = input()

st_sub = 0
count = 0
for char in x:

    if st_sub < 0 and char == "S":
        st_sub = 1
    elif char == "S":
        st_sub += 1
    else:
        st_sub -= 1
    
    if st_sub < 0:
        count += 1
    
print(count * 2)

Solution (Python):
import sys
input = sys.stdin.readline
x = list(input())[: -1]
s = 0
t = 0
res = len(x)
for i in range(len(x)):
  if x[i] == "S":
    s += 1
  else:
    t += 1
    if s > 0:
      res -= 2
      s -= 1
print(res)

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    X=input()
    Q=[]
    ans=0
    for c in X:
        if(c=='T' and Q and Q[-1]=='S'): Q.pop()
        else: Q.append(c)
    print(len(Q))
resolve()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X = read().rstrip().decode('utf-8')

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

answer = len(stack) - 1
print(answer)

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

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

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

Solution (Python):
x = input()
len_x = len(x)
cnt = 0
cur = 0
for _x in x:
    if _x == "S":
        cur += 1
    else:
        cnt += cur > 0
        cur = max(0, cur - 1)
print(len_x - 2 * cnt)

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

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

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

Solution (Python):
from collections import deque

x = input()
n = len(x)

deq = deque()

for i in range(n):
    if x[i] == 'S':
        deq.appendleft(x[i])
    elif x[i] == 'T' and  deq and deq[0] == 'S':
        deq.popleft()
    else:
        deq.appendleft('T')

print(len(deq))

Solution (Python):
from collections import deque
X = input()
n = len(X)

q = deque()
for x in X:
    if x == 'S':
        q.append(x)
    else:
        if len(q) == 0 or q[-1] == 'T':
            q.append(x)
        else:
            q.pop()

ans = len(q)
print(ans)

Solution (Python):
x = input()

s = 0
cnt = len(x)
for i in x:
    if i == "T":
        if s > 0:
            s -= 1
            cnt -= 2
        else:
            s = 0
    if i == "S":
        s += 1
print(cnt)

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

ans = 0
temp = 0
for c in x:
    if c == 'T':
        if temp > 0:
            temp -= 1
        else:
            ans += 1
    else:
        temp += 1

print(ans * 2)

Solution (Python):
def sol():
  ti = 0
  ans = lenX
  for i in range(lenX//2):
    while S[i]>=T[ti]:
      ti += 1
      if ti>=lenX//2:return ans
    ans -= 2    
    ti += 1
    if ti>=lenX//2:return ans
  return ans

X = input()
lenX = len(X)
S = []
T = []
for i,x in enumerate(X):
  if x == 'S':S.append(i)
  else:T.append(i)

print(sol())

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

if(c>10**5):
    print(len(S)-(2*(10**5)))
else:
    print(len(S)-(2*c))

Solution (Python):
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        
        if cs >0:
            ans +=1
            cs -=1
           

print(len(arr)-2*ans)

Solution (Python):
x=input()
f=0
c=0

for i in x:
    if i=="S":
        f+=1
    else:
        if f==0:
            c+=1
        else:
            f-=1
print(2*c)

Solution (Python):
x=input()
f=0
c=0

for i in x:
    if i=="T":
        if f==0:
            c+=1
        else:
            f-=1
    else:
        f+=1
print(2*c)

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

for i in x:
    if i=="S":
        f+=1
    elif f!=0:
        f-=1
print(2*f)

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

for i in x:
    if i=="S":
        f+=1
    else:
        if f!=0:
            f-=1
print(2*f)

Solution (Python):
x=input()
f=0
c=0

for i in x:
    if i=="S":
        f+=1
    else:
        if f==0:
            c+=1
        else:
            f-=1
print(2*c)

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

Solution (Python):
s=input()
a,b,n=0,0,len(s)
for i in range(n):
    if s[i]=='T':
        if a==0:
            b+=1
        else:
            a-=1
            b-=1
    else:
        a+=1
        b+=1
print(b)

Solution (Python):
x = input()

s = 0
t = 0
nokori = 0
disappear = 0

for i in x:
    if i == "S":
        s += 1
    else:
        if s > 0:
            disappear += 2
            s -= 1

print(len(x)-disappear)

Solution (Python):
X = input()

S, T = 0, 0
for x in X :
    if x == 'T' and S > 0 :
        S -= 1
    elif x == 'T' :
        T += 1
    elif x == 'S' :
        S += 1
        
print(S + T)

Solution (Python):
import sys
input = sys.stdin.readline
S = list(input())[: -1]
s = 0
t = 0
res = len(S)
if S[0] == "S": s += 1
for i in range(1, len(S)):
  if S[i] == "S":
    s += 1
  else:
    if s > 0:
      res -= 2
      s -= 1
      t = 1
print(res)

Solution (Python):

stack = []
X = str(input())
for i in range(len(X)):
    if X[i] == "S":
        stack.append(X[i])
    elif X[i] == "T" and (len(stack) == 0 or stack[-1] == "T"):
        stack.append(X[i])
    elif X[i] == "T" and stack[-1] == "S":
        stack.pop()
print(len(stack))

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

Solution (Python):


X = input()

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



print(len(buf))

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

Solution (Python):
def main():
    S = input()
    stack = 0
    for s in S:
        if s == "S":
            stack += 1
        else:
            if stack > 0:
                stack -= 1
    print(stack*2)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    S = input()
    stack = []
    for s in S:
        if s == "S":
            stack.append(s)
        else:
            if stack:
                stack.pop()
    print(2*len(stack))


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

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

Solution (Python):
X = input()
N = len(X)
ans = N
st = 0
for i in range(N):
    if X[i] == 'S':
        st += 1
    else:
        if st:
            st -= 1
            ans -= 2
        else:
            continue
print(ans)

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x = input()
n = len(x)
s = 0
d = 0
for i,j in enumerate(x):
    if j == 'S':
        s += 1
    else:
        if s > 0:
            d += 2
            s -= 1
print(n-d)