Buggy python submission (verdict: Time Limit Exceeded):
X = input()
if len(X) >= 15 **5:
    for i in range(len(X)):
        if X[i] == "S":
            count_T = X[i:].count("T")
            break
    for i in range(len(X)-1,-1,-1):
        if X[i] == "T":
            count_S = X[:i+1].count("S")
            break
    pair = min(count_T,count_S)
    ans = len(X) - 2 * pair
    print(ans)
else:
    for i in range(10**5):
        note = X
        X = X.replace("ST","")
        if note == X:
            break
    print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
def erase(string,word):
    for i in range(10**5):
        note = string
        string = string.replace(word,"")
        if note == string:
            break
    return string
for e in ["SSSSTTTT","SSSTTT","SSTT","ST"]:
    X = erase(X,e)
print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
X = X.replace("ST","")
if X[:len(X) // 2].count("S") == len(X) // 2:
    print(0)
    exit()
for i in range(10**5):
    note = X
    X = X.replace("ST","")
    if note == X:
        break
print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
if X[:len(X) // 2].count("S") == len(X) // 2:
    print(0)
    exit()
for i in range(10**5):
    note = X
    X = X.replace("ST","")
    if note == X:
        break
print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
for i in range(10**5):
    note = X
    X = X.replace("ST","")
    if note == X:
        break
print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
for i in range(10**5):
    X = X.replace("ST","")
print(len(X))

Fixed submission:
X = input()
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print(len(stack))