def solution(s):
    head = []
    sub = 0

    for i, v in enumerate(s):
        if v == 'S':
            head.append(i)

        if v == 'T' and head:
            head.pop(0)
            sub += 2

    return len(s) - sub