S=eval(input())

t=0

u=0

for i in range(len(S)):

    if S[i]=="S":

        t+=1

    else:

        if t>=1:

            u+=2

            t-=1

print((len(S)-u))
S=eval(input())

t=0

u=0

for v in S:

    if v=="S":

        t+=1

    else:

        if t>=1:

            u+=2

            t-=1

print((len(S)-u))
S = eval(input())
t = 0
u = 0
for i in range(len(S)):
    if S[i] == "S":
        t += 1
    else:
        if t >= 1:
            u += 2
            t -= 1
print((len(S) - u))

S = eval(input())
t = 0
u = 0
for v in S:
    if v == "S":
        t += 1
    else:
        if t >= 1:
            u += 2
            t -= 1
print((len(S) - u))

-for i in range(len(S)): -    if S[i] == "S": +for v in S: +    if v == "S":