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:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())
	while True:
		p=''
		pi=-1
		is_exist_st=False
		#pa(s)
		for i, c in enumerate(s):
			if p == 'S' and c == 'T':
				s[pi] = 'e'
				s[i] = 'e'
				#print(s)
				is_exist_st = True
				p=''
				for bj in range(i):
					if s[i-1-bj]!='e':
						p=s[i-1-bj]
						pi=i-1-bj
						break
				
			elif c == 'e':
				pass
			else:
				p=c
				pi=i
		
		if not is_exist_st:
			break	
	return len(s)-s.count('e')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())
	while True:
		p=''
		pi=-1
		#pa(s)
		for i, c in enumerate(s):
			if p == 'S' and c == 'T':
				s[pi] = 'e'
				s[i] = 'e'
				#print(s)
				break
			elif c == 'e':
				pass
			else:
				p=c
				pi=i
		else:
			break
		
	return len(s)-s.count('e')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	while True:
		p=''
		for i, c in enumerate(s):
			if p == 'S' and c == 'T':
				s = s[:i-1]+s[i+1:]
				#print(s)
				break
			p=c
		else:
			break
		
	return len(s)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = S.replace('ST','')
while T!=S:
    S = T
    T = T.replace('ST','')
print(len(T))

Submission status: Time Limit Exceeded

Solution code:
x = input()
for i in range(len(x)//2):
    x = x.replace('ST', '')
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X=input()
A=len(X)
B=X.count("S")
if B>A-B:
  K=A-B
else:
  K=B
for i in range(K):
  X=X.replace("ST","")
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X=input()
A=len(X)
for i in range(A//2):
  X=X.replace("ST","")
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x=input()
i = 0
while(i<len(x)):
    if x[i:i+2]=="ST":
        x=x[:i]+x[i+2:]
        i=i-2
    i+=1
print(str(len(x))+"\n")

Submission status: Time Limit Exceeded

Solution code:
x=input()
i = 0
while(i<len(x)):
    if x[i:i+2]=="ST":
        x=x[:i]+x[i+2:]
        i=-1
    i+=1
print(str(len(x))+"\n")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    x = input()
    le = len(x)
    while True:
        bit = 0
        for i in range(le-1):
            if x[i:i+2] == "ST":
                x = x[0:i]+x[i+2:le]
                bit = 1
                le -= 2
                break
        if bit == 0:
            print(len(x))
            break

    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
x = input()
le = len(x)
while True:
    bit = 0
    for i in range(le-1):
        if x[i:i+2] == "ST":
            x = x[0:i]+x[i+2:le]
            bit = 1
            break
    if bit == 0:
        print(len(x))
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    x = input()
    le = len(x)
    while True:
        bit = 0
        for i in range(le-1):
            if x[i:i+2] == "ST":
                x = x[0:i]+x[i+2:le]
                bit = 1
                break
        if bit == 0:
            print(len(x))
            break

    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys

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


def resolve():
    x = input()

    for _ in range(10 ** 5):
        if "ST" in x:
            x = x.replace("ST", "")
            x = list(x)
            x = "".join(x)
        else:
            break

    print(len(x))


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys

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


def resolve():
    x = input()

    for _ in range(10 ** 5):
        x = x.replace("ST", "")
        x = list(x)
        x = "".join(x)

    print(len(x))


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N = input().strip()
    while True:
        ngram_list=[]
        #round 1
        for i in range(len(N)-1):
            ngram_list.append(N[i:i+2])
        #round 2
        if "ST" in ngram_list:
            idx=ngram_list.index("ST")
            if idx+2 > len(N):
                N = N[:idx]
            else:
                N=N[:idx]+N[idx+2:]
        else:
            return print(len(N))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
X = str(input())
lx = len(X)
st = []

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st = ["T"] + st
   
print(len(st))

Submission status: Time Limit Exceeded

Solution code:
X = str(input())
X = X.replace("ST","")
lx = len(X)
st = []

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st = ["T"] + st
   
print(len(st))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
X = str(input())
X = X.replace("ST","")
lx = len(X)
st = deque([])

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st.appendleft("T")
   
print(len(st))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
X = str(input())
lx = len(X)
st = deque([])

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st.appendleft("T")
      
print(len(st))

Submission status: Time Limit Exceeded

Solution code:
X = str(input())
while X.count("ST") > 0:
  X = X.replace("ST","")

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x=input()
i=4
n=len(x)
while i>=0 and n>0:
  x=x.replace('S'*10**i+'T'*10**i,'')
  if n==len(x):
    i-=1
  n=len(x)
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
s=input()

while 1:
    num=len(s)
    s=s.replace("ST","")
    if num==len(s):break
print(num)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/agc005/tasks/agc005_a
# 半分はS, 半分はTからなる文字列
# STを取り除く，どうなるか (無限回)

X = input()
j = len(X) - 1
i = X.find("ST")

while i >= 0:
    X = X[:i] + X[i + 2:]
    i = X.find("ST")

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x = input()

while True:
    n = len(x)
    fl = 0
    for i in range(n-1):
        if x[i] == "S" and x[i+1] == "T":
            x = x[:i] + x[i+2:]
            fl = 1
            break
            
    if fl == 0:
        break
        
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
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())

Submission status: Time Limit Exceeded

Solution code:
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())

Submission status: Time Limit Exceeded

Solution code:
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())

Submission status: Time Limit Exceeded

Solution code:
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())

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
S_ = 'ST'+S
while S_ != S:
    S = S_
    S_ = S.replace('ST', '', 1)

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()

for i in range(len(S)//2+1):
    S_ = S.replace('ST', '', 1)
    if S_ == S:
        break
    S = S_

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()

for i in range(len(S)//2+1):
    S = S.replace('ST', '', 1)

print(len(S))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: cp932 -*-

import sys
import os
import re
import datetime
import bisect

### main ###

X = input()

restS = []
for c in X:
    #print("c = {}".format(c))
    restS.append(c)
    if c == 'T':
        while(len(restS) >= 2):
            #print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
            if("".join(restS[-2:]) == 'ST'):
                #print("hit")
                restS = restS[:-2]
                #print("new restS = {}".format(restS))
            else:
                #print("no hit")
                break # out of while

print(len(restS))

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 = [i for i in input()]
idx = 0
ans = len(s)
while idx < len(s) - 1:
    if s[idx] == "S" and s[idx+1] == "T":
        ans -= 2
        s.pop(idx)
        s.pop(idx)
        idx -= 1
    else:
        idx += 1
print(ans)

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:
x = input()
while ("ST" in x):
    x = x.replace("ST", '')
print(len(x))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
X = input()
for i in range(10 ** 1000):
  p = X.find('ST')
  if p == -1:
    break
  X = ''.join([X[:p],X[p + 2:]])
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
for i in range(10 ** 1000):
  p = X.find('ST')
  if p == -1:
    break
  X = X[:p] + X[p + 2:]
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x = input()

l = len(x)
r = 0
while l != r:
    l = len(x)
    x = x.replace("ST", "")
    r = len(x)

print(r)

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:
def main():
    X = input()
    count = 0
    for i in range(10**3):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    X = input()
    count = 0
    for i in range(10**4):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    X = input()
    count = 0
    for i in range(10**6):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  X = input()

  st = "ST"
  con = X.count(st)
  
  while con > 0:
    X = X.replace(st,"")
    con = X.count(st)
    
  print(len(X))
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def rem():
  X = input()
  N = len(X)
  
  st = "ST"
  con = X.count(st)
  
  while con > 0:
    X = X.replace(st,"")
    con = X.count(st)
    
  print(len(X))
  
rem()

Submission status: Time Limit Exceeded

Solution code:
X = input()
N = len(X)

st = "ST"
con = X.count(st)

while con > 0:
  X = X.replace(st,"")
  con = X.count(st)
  
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X = input().strip()
    while X.count("ST"):
        a = X.find("ST")
        X = X[:a] + X[a + 2:]

    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
x = input()

for _ in range(len(x)//2+1):
    x = x.replace("ST","")

print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X=input()
flg = True
while flg and len(X):
    flg = False
    for i in range(len(X)-1):
        if X[i]=='S' and X[i+1] =='T':
            if i<len(X)-1:
                X=X[:i]+X[i+2:]
            else:
                X=X[:i]
            flg = True
            break
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x=input()
ans=len(x)
ind=x.find("ST")
while(ind!=-1):
    ans-=2
#     s_ind=ind-1
#     t_ind=ind+2
#     while(0<=s_ind and t_ind<len(x) and x[s_ind]=="S" and x[t_ind]=="T"):
#         ans-=2
#         s_ind-=1
#         t_ind+=1
    x=x[:ind]+x[ind+2:]
    ind=x.find("ST")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x=input()
lenx=len(x)
ans=0
ind=x.find("ST")
while(ind!=-1):
    ans+=2
    xlist=list(x)
    xlist.pop(ind)
    xlist.pop(ind)
    x=''.join(xlist)
    ind=x.find("ST")
print(lenx-ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
end = len(S) // 2
for i in range(end):
    S = S.replace("ST","")

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()

for i in range(60000):
    S = S.replace("ST","")

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()

for i in range(100000):
    S = S.replace("ST","")

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
s=input()
for i in range(10**5):
  s=s.replace("ST","")

print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = input()

for i in range(2*10**5):
    tmp = x
    x = x.replace('ST', '', 1)
    if len(tmp)==len(x):
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
x = input()

for i in range(2*10**5):
    x = x.replace('ST', '', 1)
    if len(x)<2:
        break
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
x = input()

while x.find("ST") != -1:
    index = x.find("ST")
    x = x[:index] + x[index+2:]

print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X = input()

for i in range(len(X)):
    X = X.replace('ST', '')

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()

for i in range(len(X)):
    X = X.replace('ST', '')

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input().strip()
i = 0
while i<len(X):
    if X[i:i+2]=="ST":
        X = X[:i]+X[i+2:]
        i -= 1
    else:
        i += 1
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:
X = input()
lenX = len(X)
si = 0
ei = 0
ans = lenX
for _ in range(lenX//2):
  try:
    si = X[si:].index('S') + si
    ei = X[max(si,ei):].index('T') + max(si,ei)
    if si<ei:ans-=2
    si += 1
    ei += 1
  except:
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
for i in range(1,100000)[::-1]:
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
S=input()
for i in range(1,10)[::-1]:
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
S=input()
for i in range(1,10):
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Submission status: Time Limit Exceeded

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

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:
s = list(input())
i = 0
leng = len(s)
while i < len(s)-1:
    if s[i:i+2] == ["S", "T"]:
        s.pop(i)
        s.pop(i)
        i -= 1
        leng -= 2
        continue
    i += 1
print(leng)

Submission status: Time Limit Exceeded

Solution code:
X = input()
X_length = len(X)
change = True
while change:
    X = X.replace("ST", "", 1)
    change = len(X) != X_length
    X_length = len(X)
print(X_length)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())+["G"]*2
n=0
while s[n+1]!="G":
    if s[n]+s[n+1]=="ST":
        del s[n]
        del s[n]
        if n!=0: n-=1
    else:
        n +=1
print(len(s)-2)

Submission status: Time Limit Exceeded

Solution code:
msg=input()
while True:
    msg=msg.replace("ST","")
    if msg.count("ST")==0:
        break
print(len(msg))

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()
while 1:
    if "ST" in X:
        X = X.replace("ST", "")
    else:
        break
##print(X)
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x=input()
 
for i in range(1,10**10000+1):
  b=x.replace("D","")

h=len(b)
print(h)

Submission status: Time Limit Exceeded

Solution code:
x=input()

for i in range(1,10**10000+1):
  a=x.replace("ST","D")
  b=a.replace("D","")

h=len(b)
print(h)

Submission status: Time Limit Exceeded

Solution code:
X = input()

while X.find('ST') != -1:
    X = ''.join(X.split('ST'))

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
X=(input())
ans=0
pre=[]
pre=X
    
while True:
    X=X.replace("ST","")
    if pre==X:
        break
    else:
        pre=X

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
# [[num of subsentence S, num of subsentence T], [,], ...]

x = input()

t_flag = 0
s_t_tmp_num = [0, 0]
s_t_num = []
for i in range(len(x)):
    if x[i] == "T":
        s_t_tmp_num[1] += 1
        t_flag = 1
    if x[i] == "S":
        if t_flag == 1:
            s_t_num.append(s_t_tmp_num)
            s_t_tmp_num = [0, 0]
            t_flag = 0
        s_t_tmp_num[0] += 1
s_t_num.append(s_t_tmp_num)
subt_num = 0

while True:
    for i in range(len(s_t_num) - 1, -1, -1):
        if s_t_num[i][0] >= 1 and s_t_num[i][1] >= 1:
            s_t_num[i][0], s_t_num[i][1] = s_t_num[i][0] - min(s_t_num[i]), s_t_num[i][1] - min(s_t_num[i])
        
        if i != 0 and s_t_num[i][0] == 0:
            s_t_num[i - 1][1] += s_t_num[i][1]
            s_t_num.pop(i)
    
        # print(s_t_num)

    if len(s_t_num) == 0:
        print(0)
        break
    elif len(s_t_num) == 1 and (s_t_num[0][0] == 0 or s_t_num[0][1] == 0):
        print(sum(s_t_num[0]))
        break
    elif len(s_t_num) == 2 and s_t_num[0][0] == 0 and s_t_num[1][1] == 0:
        print(sum(s_t_num[0]) + sum(s_t_num[1]))
        break

Submission status: Time Limit Exceeded

Solution code:
x = input()

i = 1
while i <= len(x) - 1:
    if x[i - 1:i + 1] == "ST":
        x = x[:i - 1] + x[i + 1:]
        i = i - 1
    else:
        i = i + 1

print(len(x))

Submission status: Time Limit Exceeded

Solution code:
X=input()
pre="a"
while True:
    X=X.replace("ST","")
    if pre==X:
        break
    else:
        pre=X

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

while True:
  flag=True
  for i in range(len(S)-1):
    if S[i]=='S' and S[i+1]=='T':
      S.pop(i)
      S.pop(i)
      flag=False
      break
  if flag:
    break
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])
A2.pop(0)
for i in range(1,L):
    A1.append(A2[0])
    A2.pop(0)
    if len(A1)>=2 and A1[-2]=="S" and A1[-1]=="T":
        A1.pop(-1)
        A1.pop(-1)
print(len(A1))

Submission status: Time Limit Exceeded

Solution code:
X=list(input())

L=len(X)
cnt=0
i=0
while cnt<=L//2 and i<len(X)-1:
    if X[i]=="S" and X[i+1]=="T":
        X.pop(i+1)
        X.pop(i)
        cnt+=1
        i=-1
    i+=1

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
S = [X[0]]
for i in range(2, len(X)+1):
    if X[i-1] == 'S':
        S.append('S')
    else:
        if 'S' in S:
            S.remove('S')
        else:
            S.append('T')
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
X = input()
dp = [0] * (len(X)+1)
dp[1] = 1
S = [X[0]]
for i in range(2, len(X)+1):
    if X[i-1] == 'S':
        S.append('S')
        dp[i] = dp[i-1] + 1
    else:
        if 'S' in S:
            S.remove('S')
            dp[i] = dp[i-1] - 1
        else:
            S.append('T')
            dp[i] = dp[i-1] + 1
print(dp[-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
for i in range(len(s)//2):
  s=s.replace("ST", "")
print(len(s))

Submission status: Time Limit Exceeded

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

bef=s
while True:
    aft=bef.replace("ST", "")
    if len(bef)==len(aft):
        break
    bef=aft

print(len(aft))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

def main():
    X = input().strip()

    for i in range(9,-1,-1): # 注: 長さは根拠なし
        # "S..ST..T"
        s = "S"*(2**i) + "T"*(2**i)
        while X.find(s) != -1:
            X = X.replace(s,"")
        # "ST..ST"
        s = "ST"*(2**i)
        while X.find(s) != -1:
            X = X.replace(s,"")
    print(len(X))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    while 1:
        si = X.find("ST")
        if si == -1:
            break
        sc = 1
        for i in range(si-1,-1,-1):
            if X[i] != "S":
                break
            sc += 1
        tc = 1
        for i in range(si+2,len(X)):
            if X[i] != "T":
                break
            tc += 1
        c = min(sc,tc)
        X = X[:max(0,si-c+1)] + X[min(len(X),si+c+1):]
    print(len(X))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
X = input()
num = len(X) // 2

for j in range(num):
    X = X.replace('ST', '')
    if 'ST' not in X:
        break

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input().replace('ST', '')

for j in range(len(X)//2):
    X = X.replace('ST', '')
    if 'ST' not in X:
        break

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()

for j in range(len(X)):
    X = X.replace('ST', '')
    if 'ST' not in X:
        break

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:
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        a = X.pop(i + 1)
        b = X.pop(i)
        c = [b,a]
        X = c + X

for i in range(0, len(X)):
    if X[len(X) - (i+1)] == "T":
        print(i * 2)
        break

Submission status: Time Limit Exceeded

Solution code:
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        a = X.pop(i + 1)
        b = X.pop(i)
        X = [b,a]+X

for i in range(0, len(X)):
    if X[len(X) - (i+1)] == "T":
        print(i * 2)
        break

Submission status: Time Limit Exceeded

Solution code:
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        X.insert(0,X.pop(i))
        X.insert(1,X.pop(i+1))


for i in range(0, len(X)):
    if X[len(X) - (i+1)] == "T":
        print(i * 2)
        break

Submission status: Time Limit Exceeded

Solution code:
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        a = X.pop(i + 1)
        b = X.pop(i)
        X.insert(0,b)
        X.insert(1,a)

for i in range(0, len(X)):
    if X[len(X) - (i+1)] == "T":
        print(i * 2)
        break

Submission status: Time Limit Exceeded

Solution code:
import copy
X = input()
X = list(X)
prev = ""
while(1):
    prev = copy.copy(X)
    for i in range(len(X) - 1):
        if X[i]+X[i + 1] == "ST":
            X.pop(i+1)
            X.pop(i)
            break
    if prev == X:
        break
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
for i in range(100000):
  X = X.replace("STSTST", "")
  X = X.replace("SSTT", "")
  X = X.replace("ST", "")
  if "ST" not in X:
    break
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
for i in range(100000):
  X = X.replace("ST", "")
  if "ST" not in X:
    break
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
X = input()
l = len(X)
for i in range(100000):
  l = len(X)
  X = X.replace("ST", "")
  if l == len(X):
    break
print(len(X))

Submission status: Time Limit Exceeded

Solution code:
x=input()
n=len(x)
while True:
    x=x.replace("ST","")
    if n==len(x):
        break
    else:
        n=len(x)
print(n)

Submission status: Time Limit Exceeded

Solution code:
x = input()

l = len(x)
for i in range(l//2):
    if "ST" in x:
        x = x.replace("ST", "")

print(len(x))