X = input().strip()

cnt = 0

cntmax = 0

for i in range(len(X)):

    if X[i]=="T":

        cnt += 1

        cntmax = max(cntmax,cnt)

    else:

        cnt -= 1

print((cntmax*2))
X = input().strip()

N = len(X)

cnt = 0

tot = 0

for i in range(N):

    if X[i]=="T":

        cnt += 1

    else:

        if cnt>0:

            tot += cnt

            cnt = -1

        else:

            cnt -= 1

print((2*tot))
X = input().strip()
cnt = 0
cntmax = 0
for i in range(len(X)):
    if X[i] == "T":
        cnt += 1
        cntmax = max(cntmax, cnt)
    else:
        cnt -= 1
print((cntmax * 2))

X = input().strip()
N = len(X)
cnt = 0
tot = 0
for i in range(N):
    if X[i] == "T":
        cnt += 1
    else:
        if cnt > 0:
            tot += cnt
            cnt = -1
        else:
            cnt -= 1
print((2 * tot))

+N = len(X) -cntmax = 0 -for i in range(len(X)): +tot = 0 +for i in range(N): -        cntmax = max(cntmax, cnt) -        cnt -= 1 -print((cntmax * 2)) +        if cnt > 0: +            tot += cnt +            cnt = -1 +        else: +            cnt -= 1 +print((2 * tot))