Buggy python submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

x = STR()
l = len(x)
a = x[0]
st = []
tmp = 1
for i in range(1, l):
    if a[i] == a[i-1]:
        tmp += 1
    else:
        st.append(tmp)
        tmp = 1
st.append(tmp)

ll = len(st)
ans = l
if a == 'S':
    if ll % 2 == 1:
        ll -= 1
    for i in range(0, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)
else:
    if ll % 2 == 0:
        ll -= 1
    for i in range(1, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)


Fixed submission:
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))

Buggy python submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

x = STR()
l = len(x)
ans = l
a = x[0]
st = []
tmp = 1
for i in range(1, l):
    if a[i] == a[i-1]:
        tmp += 1
    else:
        st.append(tmp)
        tmp = 1
st.append(tmp)

if a == 'S':
    for i in range(0, len(tmp), 2):
        ans -= min(tmp[i], tmp[i+1]) * 2
    print(ans)
else:
    for i in range(1, len(tmp), 2):
        ans -= min(tmp[i], tmp[i+1]) * 2
    print(ans)


Fixed submission:
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))

Buggy python submission (verdict: Runtime Error):
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif x[i] == 'T' and (len(stack) == 0 or stack[len(stack) - 1]) == 'T':
        stack.append('T')
    elif x[i] == 'T' and stack[len(stack) - 1] == 'S':
        stack.pop()
print(len(stack))


Fixed submission:
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))