Buggy python submission (verdict: Runtime Error):
X=input()
t,s=0,0
for x in X:
 if x=='S':ns+=1
 elif ns>0:ns-=1
 else:nt+=1
print(nt+ns)

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i
        while j < N and X[j] != 'T':
            j += 1
        if j >= N:
            return N - 2*cnt
        cnt += 1
        if 2*cnt == N:
            return 0
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i
        while j < N and X[j] != 'T':
            j += 1
        if j >= N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Runtime Error):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i + 1
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '

print(solve())

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())