# -*- coding: utf-8 -*-

import math

import sys

import itertools

import numpy as np

import functools

import collections

mo = 1000000007

r = range



s = eval(input())

ret = 0

tmp = 0

for c in s:

    tmp += 1 if c == 'S' else -1

    ret = min(ret, tmp)



print((-ret*2))
s = eval(input())

ret = 0

tmp = 0

for c in s:

    tmp += 1 if c == 'S' else -1

    ret = min(ret, tmp)



print((-ret*2))
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections

mo = 1000000007
r = range
s = eval(input())
ret = 0
tmp = 0
for c in s:
    tmp += 1 if c == "S" else -1
    ret = min(ret, tmp)
print((-ret * 2))

s = eval(input())
ret = 0
tmp = 0
for c in s:
    tmp += 1 if c == "S" else -1
    ret = min(ret, tmp)
print((-ret * 2))

-# -*- coding: utf-8 -*- -import math -import sys -import itertools -import numpy as np -import functools -import collections - -mo = 1000000007 -r = range