from collections import deque
S=input()
table=deque()
table.append(1)
ans=0
for s in S:
    if s=='S':
        table.append(1)
        #print(table,ans)
    else:
        if len(table)==1:
            table[0]==1
           #print(table,ans)
        else:
            table.pop()
            ans+=table[-1]
            #table[-1]+=1
            #print(table,ans)
print(ans)