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