X = input()
mLoop = 10 ** 1000
mode = 'Ti' if X[0] == 'T' else 'I'
sum = 0
total = 0
for i in X:
  if i != mode[0]:
    if i == 'S':
      total += sum
      sum = 1
      mode = 'S'
    else:
      mode = 'Td'
      sum -= 1
  else:
    if i == 'S':
      sum += 1
    else:
      if sum == 0:
        mode = 'Ti'
        sum = 1
      elif mode == 'Td':
        sum -= 1
      else:
        sum += 1
  #print(sum, total, sep=' ')

total += sum      
print(total)  