a=[]
for i in input():
    if i=="S":
        a+=i
    
    if a:
        if i=="T" and a[-1]=="T":
            a+=i
        if i=="T" and a[-1]=="S":
            a.pop(-1)
    elif i=="T" and len(a)==0:
        a+=i    
print(len(a))
6bdc57853461c00d0b9b0090986b3129d14ce3e7
<mask token>

<mask token>
for i in input():
    if i == 'S':
        a += i
    if a:
        if i == 'T' and a[-1] == 'T':
            a += i
        if i == 'T' and a[-1] == 'S':
            a.pop(-1)
    elif i == 'T' and len(a) == 0:
        a += i
print(len(a))

a = []
for i in input():
    if i == 'S':
        a += i
    if a:
        if i == 'T' and a[-1] == 'T':
            a += i
        if i == 'T' and a[-1] == 'S':
            a.pop(-1)
    elif i == 'T' and len(a) == 0:
        a += i
print(len(a))

a=[]
for i in input():
    if i=="S":
        a+=i
    
    if a:
        if i=="T" and a[-1]=="T":
            a+=i
        if i=="T" and a[-1]=="S":
            a.pop(-1)
    elif i=="T" and len(a)==0:
        a+=i    
print(len(a))