Problem:


Score : 300 points

Problem Statement

We have a string X, which has an even number of characters. Half the characters are S, and the other half are T.

Takahashi, who hates the string ST, will perform the following operation 10^{10000} times:

Among the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.

Find the eventual length of X.

Constraints

2 ≦ |X| ≦ 200,000

The length of X is even.

Half the characters in X are S, and the other half are T.

Partial Scores

In test cases worth 200 points, |X| ≦ 200.

Input

The input is given from Standard Input in the following format:

X

Output

Print the eventual length of X.

Sample Input 1

TSTTSS

Sample Output 1

4

In the 1-st operation, the 2-nd and 3-rd characters of TSTTSS are removed.
X becomes TTSS, and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.
Thus, the answer is 4.

Sample Input 2

SSTTST

Sample Output 2

0

X will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.

Sample Input 3

TSSTTTSS

Sample Output 3

4

X will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.



Sample input:
TSTTSS


Sample output:
4

Submission status: Time Limit Exceeded

Solution code:
def ST_string():
	x = str(raw_input())
	len_changed = True
	l2 = 0
	while len_changed:
		l1 = len(x)
		x = x.replace("ST", "", 1)
		l2 = len(x)
		if l1==l2:
			len_changed = False
	print l2

if __name__ == "__main__":
	ST_string()

Submission status: Time Limit Exceeded

Solution code:
X = input()

len_prev = -1
while len_prev != len(X):
    len_prev = len(X)
    X = X.replace('ST', '')
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
import re
l = lambda w: re.sub("ST", "", w, count=1)
b = raw_input()
a = l(b)
while b != a:
	b = a
	a = l(b)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
p = s.find('ST')
while p != -1:
    s = s[:p] + s[p+2:]
    p = s.find('ST')
print len(s)

Submission status: Time Limit Exceeded

Solution code:
s=input()
while 'ST' in s:
    x=s.find('ST')
    s=s[:x]+s[x+2:]
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
X = list(input())
while True:
    before = len(X)
    for i in range(len(X) - 1):
        if X[i] == "S" and X[i + 1] == "T":
            del X[i:i + 2]
            break
    if len(X) == before:
        break     
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
while X.find("ST") != -1:
    Xlist = list(X)
    del Xlist[X.find("ST"):X.find("ST") + 2]
    X = "".join(Xlist)
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
while X.find("ST") != -1:
    X = X.replace("ST", "", 1)
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

x = input()
s = x.find('ST')
cnt = 0
while s != -1:
    x = x[:s] + x[s+2:]
    cnt += 1
    s = x.find('ST')
#     print(x)
# print(cnt)
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X = input()
while "ST" in X:
    X = X.replace("ST", "")
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
while True:
    t = s.replace("ST", "")
    if len(t) == len(s):
        break
    s = t
print len(s.replace("ST", ""))

Submission status: Time Limit Exceeded

Solution code:
import sys
X = sys.stdin.readline()
cnt = 10**10000
while cnt > 0:
    a = X.split("ST",min(0x7fffffff,cnt))
    if(len(a) == 1):
        break
    cnt -= len(a) - 1
    X = "".join(a)

print(len(X)-1)

Submission status: Time Limit Exceeded

Solution code:
X = input()
cnt = 10**10000
while cnt > 0:
    a = X.split("ST",min(0x7fffffff,cnt))
    if(len(a) == 1):
        break
    cnt -= len(a) - 1
    X = "".join(a)

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
# cook your code here
from sys import stdin
a = stdin.readline().strip()
l = len(a)
for i in xrange(l):
    a = a.replace('ST','')
print len(a)

Submission status: Time Limit Exceeded

Solution code:
#AGC005A

x=raw_input()
while x.count('ST')>0:
 x=x.replace('ST','')
print len(x)

Submission status: Time Limit Exceeded

Solution code:
#AGC005A

x=raw_input()
while x.count('ST')!=0:
 x=x.replace('ST','')
print len(x)

Submission status: Time Limit Exceeded

Solution code:
string = list(input())

string_len = len(string)

string.append("0")
complete_control = 1

while complete_control:
    complete_control = 0

    for char in range(string_len):
        if string[char] == "S" and string[char + 1] == "T":
            del string[char]
            del string[char]
            string_len -=2

            complete_control = 1
            break



print(string_len)

Submission status: Time Limit Exceeded

Solution code:
string = list(input())

string_len = len(string)

string.append("0")
complete_control = 1

while complete_control:
    complete_control = 0
    temp_index = 0
    for char in range(string_len):
        if string[char] == "S" and string[char + 1] == "T":
            temp_index = char
            string_len -=2
            complete_control = 1
            break
    try:
        del string[temp_index]
        del string[temp_index]
    except IndexError:
        break


print(string_len)

Submission status: Time Limit Exceeded

Solution code:
string = list(input())



max_num = 10**10000
string_len = len(string)

while max_num:
    complete_control = 1
    temp_index = 0
    for char in range(string_len):
        if string[char] == "S" and string[char + 1] == "T":
            temp_index = char
            string_len -=2
            complete_control = 0
            break

    if complete_control:
        break
    
    del string[temp_index]
    del string[temp_index]


    max_num -= 1
    

print(string_len)

Submission status: Time Limit Exceeded

Solution code:
s = input()
while "ST" in s:
	s = s.replace("ST", "", 100000)
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
x=input()
while len(x)>0:
    f=True
    if "ST" in x:
        x=x.replace("ST","")
        f=False
    if f:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X = input()
stack = []
for l in X:
	if stack == []:
		stack.append(l)
	elif stack[-1] == "S" and l == "T":
		stack = stack[:-1]
	else:
		stack.append(l)
print(len(stack))

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
ans=0
while S.find('ST')!= -1:
    S=S.replace('ST','')

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
while 1:
    i = s.find('ST')
    if i > -1:
        cnt = 0
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                cnt += 1
            else:
                break
        s = s[:i-cnt] + s[i+cnt+2:]
    else:
        break
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while cnt < 100000:
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) // 2
    else:
        break
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
l = len(s)
s = s.replace("ST","")
x = len(s)
while l != x:
    l = len(s)
    s = s.replace("ST","")
    x = len(s)
print len(s)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    for i in range(10**10000):
        sp = s.split('ST', 1)
        if len(sp) > 1:
            s = sp[0] + sp[1]
        else:
            break
    print(len(s))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
for i in range(10**10000):
    sp = s.split('ST', 1)
    if len(sp) > 1:
        s = sp[0] + sp[1]
    else:
        break
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())

st = []
X = list(s())
N = len(X)
st.append(X[0])
X.pop(0)
#for i in range(len(X)-2):
for i in range(N-1):
    st.append(X[0])
    X.pop(0)
    if len(st) >= 2:
        if st[-1] == 'T' and st[-2] == 'S':
            st.pop()
            st.pop()
print len(st)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())

st = []
X = list(s())

st.append(X[0])
X.pop(0)
#for i in range(len(X)-2):
while len(X) > 0:
    st.append(X[0])
    X.pop(0)
    if len(st) >= 2:
        if st[-1] == 'T' and st[-2] == 'S':
            st.pop()
            st.pop()
print len(st)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())

st = []
X = list(s())

st.append(X[0])
X.pop(0)
#for i in range(len(X)-2):
while len(X) > 0:
    st.append(X[0])
    X.pop(0)
    if st[-1] == 'T' and st[-2] == 'S':
        st.pop()
        st.pop()
print len(st)

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()

while s.find('ST') > -1:
    s = ''.join(s.split('ST'))

print len(s)

Submission status: Time Limit Exceeded

Solution code:
x = str(input())
while True:
    x = "".join(x.split("ST"))
    if "ST" not in x:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
import copy
x = str(input())
while True:
    prev_x = copy.deepcopy(x)
    x = "".join(x.split("ST"))
    if x == prev_x:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
import copy
x = str(input())
MAX = pow(10, 10000)
for i in range(MAX):
    try:
        prev_x = copy.deepcopy(x)
        x = "".join(x.split("ST"))
        if x == prev_x:
            break
    except ValueError:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X = input()

count = len(X) // 2

if count > 10 ** 10000:
    count = 10 ** 10000

for i in range(count):
    if not ("ST" in X):
        break
    X = X.replace("ST", "", 1)

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
s = input()
while "ST" in s:
	s = s.replace("ST", "")
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
X = input()

count = len(X) // 2

if count > 10 ** 10000:
    count = 10 ** 10000

for i in range(count):
    X = X.replace("ST", "", 1)

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
str = input()
while True:
       pos = str.find('ST')
       if pos != -1:
              str = str[0:pos]+str[pos+2:]
       else:
              break
print(len(str))

Submission status: Time Limit Exceeded

Solution code:
#import re
X = raw_input()
iter = 100000
#pat = re.compile('(ST)')
for i in xrange(iter):
    if ('ST' not in X):
	break
    X = X.replace('ST','')
    if len(X) == 0:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    s = input()
    while 'ST' in s:
        s = s.replace('ST', '', 1)
    print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
iter = 100000
#pat = re.compile('(ST)')
for i in xrange(iter):
    X =	X.replace('ST','')
    if len(X) == 0:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
iter = 100000
pat = re.compile('(ST)')
for i in xrange(iter):
    X =	X.replace('ST','')
    if len(X) == 0:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
prelength = len(s) + 1
length = len(s)
while prelength - length > 0:
    s = re.sub("ST", "", s)
    prelength = length
    length = len(s)

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
prelength = len(s) + 1
length = len(s)
while prelength - length > 0:
    s = s.replace("ST", "")
    prelength = length
    length = len(s)
    #print(s, prelength, length)
    
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
iter = 100000
pat = re.compile('(ST)')

for i in xrange(iter):
    s =	pat.search(X)
    if len(X) == 0:
	break
    if s is	not None:
    	X =	X.replace('ST','')
    else:
	break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
iter = 100000
pat = re.compile('(ST)')

for i in xrange(iter):
    s =	pat.search(X)
    if len(X) == 0:
	break
    if s is	not None:
    	X =	X.replace('ST','')
    else:
	pass
print len(X)

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
iter = 100000
pat = re.compile('(ST)')

for i in xrange(iter):
    s =	pat.search(X)
    if s is	not None:
    	X =	X.replace('ST','',1)
    else:
	pass
print len(X)

Submission status: Time Limit Exceeded

Solution code:
from os import sys


X = input()

within_seq = False
start = -1 # start index of ST string to be removed
res = X
ST_found = False # was 'ST' ever found in the curr loop?

if len(X) < 2:
    print(0)
    sys.exit()
    
while True:
    i = 0
    while i < len(res):     
        c = res[i]    
        if not within_seq:
            if c == 'S':   
                within_seq = True
                start = i
        else:
            if c == 'S':
                start = i
            elif c == 'T':
                within_seq = False
                ST_found = True
                res = res[:start] + res[start+2:]
        i += 1

    if len(res) == 0 or not ST_found:
        break
    ST_found = False
    within_seq = False
 
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
def st(x):
    while 'ST' in x:
        x = x.replace('ST', '')
    return x

X = str(input())
l = len(st(X))
print(str(l))

Submission status: Time Limit Exceeded

Solution code:
def st(x):
    while 'ST' in x:
        x = x.replace('ST', '', 1)
    return x

X = str(input())
l = len(st(X))
print(str(l))

Submission status: Time Limit Exceeded

Solution code:
X = input()
N = 10**10000
for i in range(N):
	if "ST" in X:
		X = X.replace("ST","")
	else:
		print(len(X))
		break
else:
	print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
X2 = ""
N = 10**10000
for i in range(N):
	if X2 == X:
		print(len(X))
		break
	else:
		X2 = X
		X = X.replace("ST","")
else:
	print(0)

Submission status: Time Limit Exceeded

Solution code:
x = str(input())
MAX = pow(10, 10000)
for i in range(MAX):
    try:
        loc = x.index("ST")
        x = x[0:loc] + x[loc+2:]
        continue
    except ValueError:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X=raw_input()
while 1:
    if 'SSSSSSSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSTTTTTTTTTT','')
    elif 'SSSSSSSTTTTTTT' in X:
       X=X.replace('SSSSSSSTTTTTTT','')
    elif 'SSSSSTTTTT' in X:
       X=X.replace('SSSSSTTTTT','')
    elif 'SSSTTT' in X:
       X=X.replace('SSSTTT','')
    elif 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
x = raw_input()
while x.find("ST") != -1:
    x = x.replace("ST", "")
print len(x)

Submission status: Time Limit Exceeded

Solution code:
n=raw_input()
i=0
j=0
k=len(n)/2
n=list(n)
while j<k:
    if len(n)==0:
        break
    while i<len(n)-1:
        if n[i]=='S':
            if n[i+1]=='T':
                del n[i+1]
                del n[i]
        i+=1
    i=0
    j+=1

print len(n)

Submission status: Time Limit Exceeded

Solution code:
import re
X = raw_input()
pat = re.compile(r'(?:ST)+')
pos = 0
m = pat.search(X, pos)
while m:
  X = X[:m.start()]+X[m.end():]
  pos = max(0, m.start()-1)
  m = pat.search(X, pos)

print len(X)

Submission status: Time Limit Exceeded

Solution code:
n=raw_input()
i=0
j=0
k=len(n)/2
n=list(n)
while j<k:
    while i<len(n)-1:
        if n[i]=='S':
            if n[i+1]=='T':
                del n[i+1]
                del n[i]
        i+=1
    i=0
    j+=1

print len(n)

Submission status: Time Limit Exceeded

Solution code:

src = raw_input()
dst = src.replace('ST', '')
while dst!=src:
	src = dst
	dst = src.replace('ST', '')
print(len(dst))

Submission status: Time Limit Exceeded

Solution code:
X = input()
while "ST" in X:
    X = X.replace("ST", "")
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
def s():
    return raw_input()
def li():
    return map(int,raw_input().split())
X = s()
while X.find("ST") >= 0:
    p = X.find("ST")
    X = list(X)
    del X[p]
    del X[p]
    X = ''.join(X)
print len(X)

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
t ='ST'
while s.find(t)>-1:
    s = s.replace(t, '')
print len(s)

Submission status: Time Limit Exceeded

Solution code:
string = input()

while "ST" in string:
    string = string.replace("ST","")

print(len(string))

Submission status: Time Limit Exceeded

Solution code:
import re

x = raw_input()

pattern = r'ST'

while(True):
    matchOB = re.search(pattern, x)
    if matchOB:
        y = x.split('ST')
        #print y
        x = ''.join(y)
    else:
        break

print len(x)

Submission status: Time Limit Exceeded

Solution code:
import sys
s = sys.stdin.readline().strip()                                                                                                                                                                                                      

i = 0
while i < len(s)-1:
        if s[i] == 'S' and s[i+1] == 'T':
                s = s[:i] + s[i+2:]
                if i > 0:
                        i -= 1
        else:   
                i += 1

print len(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
while 1:
    s1 = s.replace('ST','',1)
    if len(s1) == len(s):
        break
    s = s1
print(str(len(s1)))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

x=s()
cur=0
flag=False
while cur<=len(x)-1:
    if flag:
        if x[cur]=='T':
            flag=False
            x=x[0:cur-1]+x[cur+1:]
            cur-=2
            if cur<0:
                cur=0
        else:
            cur+=1
    else:
        if x[cur]=='S':
            flag=True
            cur+=1
        else:
            cur+=1
print len(x)

Submission status: Time Limit Exceeded

Solution code:
targ = input()
length = len(targ)
num = 0
while True:
    #print(targ)
    for num in range(length-1):
        if targ[num: num+2] == 'ST':
            #print(targ[:num],targ[num+2:])
            targ = targ[:num] + targ[num+2:]
            length -= 2
            break
    else:
        break
print(length)

Submission status: Time Limit Exceeded

Solution code:
a = raw_input()
b = a.find("ST")
while(b != -1):
  a = a[:b] + a[b:].replace("ST","")
  b = a.find("ST")
print len(a)

Submission status: Time Limit Exceeded

Solution code:
import sys

x = raw_input()

x = [i for i in x]

while(True):
    end = True
    for i in range(0,len(x)-1):
#        print len(x),i,x[i],x[i+1],end
        if(x[i]=='S' and x[i+1]=='T'):
            del x[i+1]
            del x[i]
            end = False
#            print x
        if end is False:
            break

    if end:
        print len(x)
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()

s_len = len(s)

while True:
    s_len_old = s_len
    s_list = list(s)
    for i in range(len(s_list) - 1):
        if s[i] == 'S' and s[i + 1] == 'T':
            s_len -= 2
            s_list[i] = ''
            s_list[i + 1] = ''
            for j in range(1, i + 1):
                if s_list[i - j] == 'S' and s_list[i + j + 1] == 'T':
                    s_len -= 2
                    s_list[i - j] = ''
                    s_list[i + j + 1] = ''
                else:
                    break

    if s_len_old == s_len:
        break
    else:
        s = ''.join(s_list)

print s_len

Submission status: Time Limit Exceeded

Solution code:
line = input()

ori = len(line)

count = 0 

while line.count("ST") is not 0:
    line = line.replace("ST", "") 

print(len(line))

Submission status: Time Limit Exceeded

Solution code:
x = input()
l = len(x)

before = l

for i in range(100000):
    x = x.replace("ST", "", 100000)
    current = len(x)
    #print(x)
    if current == 0 or current == before:
        break
    before = current

print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X=raw_input()
while 1:
    if 'SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSTTTTTTTTTT','')
    elif 'SSSSSSSTTTTTTT' in X:
       X=X.replace('SSSSSSSTTTTTTT','')
    elif 'SSSSSTTTTT' in X:
       X=X.replace('SSSSSTTTTT','')
    elif 'SSSTTT' in X:
       X=X.replace('SSSTTT','')
    elif 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
s = input()
while 1:
    s1 = s.replace('ST','',1)
    if len(s1) == len(s):
        break
    s = s1
print(str(len(s1)) + "\n")

Submission status: Time Limit Exceeded

Solution code:
a = raw_input()
while(a.find("ST") != -1):
  a = a.replace("ST","")
  a = a.replace("ST","")
  a = a.replace("ST","")
  a = a.replace("ST","")
  a = a.replace("ST","")
  a = a.replace("ST","")
print len(a)

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
while 1:
    result = s.replace("ST", "")
    if result == s:
        s = result
        break
    else: s = result
print len(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)

cnt = 0
while "ST" in s:
    s = s.replace('ST', '',1)
    cnt += 1
    
print(slen-cnt*2)

Submission status: Time Limit Exceeded

Solution code:
s=raw_input()
while True:
    f=0
    for i in xrange(len(s)-1):
        if s[i]=="S" and s[i+1]=="T":
            s=s[0:i]+s[i+2:len(s)]
            f=1
            break
    if f==0:
        break
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
X = raw_input()
sw = True
while sw:
    X = X.replace('ST','')
    X = X.replace('SSTT','')
    X = X.replace('SSSSSTTTTT','')
    if 'ST' not in X:
        sw=False
print len(X)

Submission status: Time Limit Exceeded

Solution code:
X = raw_input()
sw = True
while sw:
    X = X.replace('ST','')
    X = X.replace('SSTT','')
    if 'ST' not in X:
        sw=False
print len(X)

Submission status: Time Limit Exceeded

Solution code:
x = input()
while(x != 'TTSS'):
    x = x.replace('ST', '')
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
a = raw_input()
while(a.find("ST") != -1):
  a = a.replace("ST","")
print len(a)

Submission status: Time Limit Exceeded

Solution code:
x = input()

flag = True
while flag:
    flag = False
    for i in range(len(x) - 1):
        if x[i:i+2] == "ST":
            flag = True
            x = x[:i] + x[i + 2:]

print(len(x))

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()
while True:
    new_S = S.replace('ST', '')
    if len(S) == len(new_S):
        break
    S = new_S
print len(S)

Submission status: Time Limit Exceeded

Solution code:
X = raw_input()
sw = True
while sw:
    X = X.replace('ST','')
    if 'ST' not in X:
        sw=False
print len(X)

Submission status: Time Limit Exceeded

Solution code:
X=raw_input()
while 1:
    if 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)

Submission status: Time Limit Exceeded

Solution code:
x = input()
l = 0
while l != len(x):
    l = len(x)
    x = x.replace('ST', '')
print(l)

Submission status: Time Limit Exceeded

Solution code:
s = input()


while s.find('ST') != -1:
	k = s.find('ST')
	s = s[:k] + s[k+2:]


print(len(s))

Submission status: Time Limit Exceeded

Solution code:
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    while 'ST' in x:
        x = x.replace('ST', '')
    print(len(x))

main()

Submission status: Accepted

Solution code:
x = input()
s=0
ans=0
for i in x:
  if i == "S":
    s+=1
  else:
    if s==0:
      ans +=1
    else:
      s-=1
print(ans+s)

Submission status: Accepted

Solution code:
s = input()
 
l = 0
r = 0
for si in s:
  if si == "S":
    r += 1
  else:
    if r == 0:
      l += 1
    else:
      r -= 1
ans = l + r
print(ans)

Submission status: Accepted

Solution code:
X = input()

s_cnt = 0
t_cnt = 0

ans = 0

for n in range(len(X)):
  if X[n] == "S":
    s_cnt += 1
  else:
    t_cnt += 1
  ans = max(ans,t_cnt-s_cnt)
print(ans*2)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x = ns()
ct = 0
ans = 0
for c in x:
    if c == 'S':
        ct += 1
    else:
        if ct > 0:
            ct -= 1
            ans += 2
print(len(x)-ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


X = S()
num_S = [0] * len(X)
t_count = 0
s_count = 0
ans = 0
prev = X[-1]
if (prev == 'S'):
    s_count = 1
else:
    t_count = 1
for x in reversed(X[:-1]):
    if (prev == 'S' and x == 'T'):
        # リセット
        rest = max(s_count - t_count, 0)
        ans += (rest*2)
        t_count = max(t_count - s_count, 0)
        s_count = 0
    if (x == 'S'):
        s_count += 1
    if (x == 'T'):
        t_count += 1
    prev = x
print(ans)


# for i, x in enumerate(X):
#     if(x == 'S'):
#         num_S[i] = 1

# num_S = list(accumulate(num_S))
# print(num_S)

Submission status: Accepted

Solution code:
X = input()
ans = 0
sc = 0
for x in X:
    if x == "S":
        sc += 1
    else:
        if sc:
            sc -= 1
        else:
            ans += 2
print(ans)

Submission status: Accepted

Solution code:
s=input() ; n=len(s)
ss=n//2; tt=n//2
ans=0
for i in range(n):
    if s[i]=="S":
        ans=max(ans, ss-tt)
        ss-=1
    else:
        tt-=1
print(ans*2)

Submission status: Accepted

Solution code:
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    S = input()
    
    #solve
    N = len(S)
    cnt=0
    ans=0
    for i in range(N):
        if S[i]=='S':
            cnt+=1
        else:
            if cnt:
                cnt-=1
                ans+=2
    print(N-ans)


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
x = input()

ans = len(x)
l = 0
r = 0
for i in range(len(x)):
    if x[i] == "S":
        l += 1
    else:
        l -= 1

        if l < 0:
            l = 0
        else:
            ans -= 2

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0

for i in range(N):
    if S[i] == 'T':
        cnt += 1
    else:
        cnt -= 1
    ans = max(ans,cnt)

print(ans * 2)

Submission status: Accepted

Solution code:
X = input()
n = len(X)
cnt = 0
S_check = 0

for i in range(n):
    if X[i] == 'S':
        S_check += 1

    if X[i] == 'T':
        if S_check > 0:
            S_check -= 1
        else:
            cnt += 1

print(cnt + S_check)

Submission status: Accepted

Solution code:
x=list(input())
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]=="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Submission status: Accepted

Solution code:
x = input()
ans = []

for i in x:
    if i == 'S':
        ans.append(i)
    else:
        if len(ans) == 0 or ans[-1] == 'T':
            ans.append(i)
        else:
            ans.pop()
print(len(ans))

Submission status: Accepted

Solution code:
X = input()
N = len(X)
stack = []
for x in X:
  if x == "S":
    stack.append(x)
  else:
    if len(stack) == 0 or stack[-1] == "T":
      stack.append(x)
    else:
      stack.pop()
      
print(len(stack))

Submission status: Accepted

Solution code:
X = input()
N = len(X)
cnt = 0
ans = 0
for x in X:
  if x == "S":
    cnt += 1
  else:
    if cnt == 0:
      ans += 1
    else:
      cnt -= 1

print(ans * 2)

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import deque
s=input()
n=len(s)
A=deque()
for i in range(n):
    if s[i]=="S":
        A.append(s[i])
    else:
        if len(A)==0:
            A.append(s[i])
        elif A[-1]=="S":
            A.pop()
        else:
            A.append(s[i])
print(len(A))

Submission status: Accepted

Solution code:
from collections import deque

s = input()
q = deque()

for si in s:
    if si == "S":
        q.append(si)
    elif si == "T" and len(q) == 0:
        q.append(si)
    elif q[-1] == "T":
        q.append(si)
    elif q[-1] == "S":
        q.pop()
print(len(q))

Submission status: Accepted

Solution code:
X = input()

ans = 0
t = 0
for x in X:
  if x == "S":
    t -= 1
  else:
    t += 1
  ans = max(ans, t)

print(ans * 2)

Submission status: Accepted

Solution code:
x = list(input())
x = x[::-1]
counter = 0
ans = len(x)
for i in x:
    if i == "T":
        counter += 1
    elif i == "S" and counter:
        counter -= 1
        ans -= 2
print(ans)

Submission status: Accepted

Solution code:
X = input().rstrip()
cnt = 0
res = len(X)
for x in X:
    if x=="S":
        cnt += 1
    else:
        if cnt > 0:
            res -= 2
            cnt -= 1
print(res)