from collections import deque

def getinputdata():



    array_result = []    

    data = eval(input())

    array_result.append(data.split(" "))



    flg = True



    try:

        while flg:



            data = eval(input())



            if(data != ""):

                

                array_result.append(data.split(" "))



                flg = True



            else:



                flg = False

    finally:



        return array_result



arr_data = getinputdata()



x=arr_data[0][0]



b = deque([])



for v in x:

    

    if v=="S":

        

        b.appendleft(v)

        

    elif v=="T" and (len(b)==0 or b[0]=="T"):

        

        b.appendleft(v)

        

    else:

            

        b.popleft()

            

print((len(b)))    

def getinputdata():



    array_result = []    

    data = eval(input())

    array_result.append(data.split(" "))



    flg = True



    try:

        while flg:



            data = eval(input())



            if(data != ""):

                

                array_result.append(data.split(" "))



                flg = True



            else:



                flg = False

    finally:



        return array_result



arr_data = getinputdata()



x=arr_data[0][0]



arr=[]





for v in x:

    

#    sの場合

    if v=="S":

        

        arr.append("S")

        

#    tの場合 直前がTあるいは初めての場合

    elif v=="T" and (len(arr)==0 or arr[-1]=="T"):

        

        arr.append("T")

      

    else:

            

        del arr[-1]

        

            

print((len(arr)))    

from collections import deque


def getinputdata():
    array_result = []
    data = eval(input())
    array_result.append(data.split(" "))
    flg = True
    try:
        while flg:
            data = eval(input())
            if data != "":
                array_result.append(data.split(" "))
                flg = True
            else:
                flg = False
    finally:
        return array_result


arr_data = getinputdata()
x = arr_data[0][0]
b = deque([])
for v in x:
    if v == "S":
        b.appendleft(v)
    elif v == "T" and (len(b) == 0 or b[0] == "T"):
        b.appendleft(v)
    else:
        b.popleft()
print((len(b)))

def getinputdata():
    array_result = []
    data = eval(input())
    array_result.append(data.split(" "))
    flg = True
    try:
        while flg:
            data = eval(input())
            if data != "":
                array_result.append(data.split(" "))
                flg = True
            else:
                flg = False
    finally:
        return array_result


arr_data = getinputdata()
x = arr_data[0][0]
arr = []
for v in x:
    #    sの場合
    if v == "S":
        arr.append("S")
    #    tの場合 直前がTあるいは初めての場合
    elif v == "T" and (len(arr) == 0 or arr[-1] == "T"):
        arr.append("T")
    else:
        del arr[-1]
print((len(arr)))

-from collections import deque - - -b = deque([]) +arr = [] +    #    sの場合 -        b.appendleft(v) -    elif v == "T" and (len(b) == 0 or b[0] == "T"): -        b.appendleft(v) +        arr.append("S") +    #    tの場合 直前がTあるいは初めての場合 +    elif v == "T" and (len(arr) == 0 or arr[-1] == "T"): +        arr.append("T") -        b.popleft() -print((len(b))) +        del arr[-1] +print((len(arr)))