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: Runtime Error

Solution code:
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    tmp=slen.popleft()+(stmp-ttmp)
    slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)

Submission status: Runtime Error

Solution code:
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    tmp=stmp.popleft()+(stmp-ttmp)
    slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)

Submission status: Runtime Error

Solution code:
X = input()
cnt_S, cnt_T = 0, 0

for c in range(X):
    if c == "S":
        cnt_S += 1
    else:
        if cnt_S:
            cnt_S -= 1
        else:
            cnt_T += 1
print(cnt_S, cnt_T)

Submission status: Runtime Error

Solution code:
x=input();a=0
for i in range(len(x)):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)

Submission status: Runtime Error

Solution code:
s=input()
ls=len(s)
c=0
for i in range(ls):
    if s[i]=='S':
        c+=1
    elif c>0:
        ans+=2
        c-=1
print(ls-ans)

Submission status: Runtime Error

Solution code:
s = raw_input()
n = int(raw_input())

head = []
sub = 0

for i, v in enumerate(s):
    if v == 'S':
        head.append(i)

    if v == 'T' and head:
        head.pop(0)
        sub += 2

print(len(s) - sub)

Submission status: Runtime Error

Solution code:
s = raw_input()
def cal(s):
	a= 0
	for idx in range(len(s)/2):
		if s[2*idx]==s[2*idx +1]:
			continue
		else:
			a = 1
			s = s[2*(idx+1):]
			break

	if a:
		return cal(s)
	else:
		return s

print(len(cal(s)))

Submission status: Runtime Error

Solution code:
@parallel
@roles('allgame')
def _last_redis_save():
	with cd(get_deploy_path()):
		redisSet = set()
		ret = run('supervisorctl status')
		for line in ret.split('\n'):
			line = line.strip()
			if line.find('RUNNING') >= 0 and line.find('redis') >= 0:
				name = line.split()[0].strip()
				redisSet.add(name)

		ret = []
		with cd('db'):
			for redis in sorted(list(redisSet)):
				port = redis[5:]
				ret.append(run('ls -l -h game%s.rdb' % port))
		return '\n'.join(ret)

def last_redis_save():
	result = execute(_last_redis_save)
	for k in sorted(result.keys()):
		print '-'*20
		print k, ':'
		v = result[k]
		print v

Submission status: Runtime Error

Solution code:
s = list(input())
cnt = 0
while True:
    if s[0] == 'T':
        s.pop(0)
        cnt += 1
    else:
        break
    
while True:
    if s[-1] == 'S':
        s.pop(-1)
        cnt += 1
    else:
        break

cs = 0
ct = 0
for i in range(len(s)):
    if s[i] == 'S':
        cs += 1
    else:
        ct += 1
print(cnt + abs(cs-ct))

Submission status: Runtime Error

Solution code:
s = list(input())
cnt = 0
while True:
    if s[0] == 'T':
        s.pop(0)
        cnt += 1
    else:
        break
    
while True:
    if s[-1] == 'S':
        s.pop(-1)
        cnt += 1
    else:
        break
        
i = 0
now = 'on'
ans = 0
cs = 0
while i < len(s):
    if s[i] == 'S':
        cs += 1
        now = 'on'
        i += 1
    elif now == 'on' and s[i] == 'T':
        i += cs
        cs = 0
        now = 'off'
    elif now == 'off' and s[i] == 'T':
        cnt += 1
        i += 1
        
    if i >= len(s):
        break
print(cnt)

Submission status: Runtime Error

Solution code:
x=input()
ans=len(x)
r=len(x)
if "ST" in x:
    x.remove("ST")
    ans-=2
while r!=len(x):
    r=len(x)
    if "ST" in x:
        x.remove("ST")
        ans-=2
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
sc=0
tc=0
for i in s:
  if i=="S":
    sc+=1
  elif sc!=0:
    sc-=1
  else tc+=1
print(tc+sc)

Submission status: Runtime Error

Solution code:
a = input()
b = a.replace("ST","")
if a[0] =="S" and b[-1] =="T":
    print(0)
while "ST" in b:
    b = b.replace("ST","")
print(len(b))

Submission status: Runtime Error

Solution code:
#root.search(x): ◯.data == x のものが存在するある場合それを出力、ない場合Noneを出力
#root.insert(x): ◯.data == xが存在する場合Falseを出力、ない場合◯.data == x なる頂点を作る
#y.to_s(): 頂点yのdataを出力
#y.left_s(): 頂点yのleftを出力(ない場合はNone)
#root.search_lower(x,None): ○.dataがxより小さいものの中で最も大きいものを出力、ない場合Noneを出力
#root.search_higher(x,None): xより大きいものの中で最も小さいものを出力、ない場合Noneを出力
 
################################################################################
class Avltree:
    def __init__(self,key=None):
        self.key = key
        self.left = None
        self.right = None 
        self.balance = "Even"

    def search_lower(self,key,key_lower):
        if self.key == None:
            return key_lower
        if self.key > key:
            if self.left == None:
                return key_lower
            else:
                return self.left.search_lower(key,key_lower)
        if self.key < key:
            key_lower = self.key
            if self.right == None:
                return key_lower
            else:
                return self.right.search_lower(key,key_lower)
        #self.key == keyの場合
        if self.left == None:
            return key_lower
        else:
            if key_lower == None:
                return self.left.end_higher(self.left.key)
            else:
                return max(key_lower,self.left.end_higher(self.left.key))
    
    def search_higher(self,key,key_higher):
        if self.key == None:
            return key_higher
        if self.key > key:
            key_higher = self.key
            if self.left == None:
                return key_higher
            else:
                return self.left.search_higher(key,key_higher)
        if self.key < key:
            if self.right == None:
                return key_higher
            else:
                return self.right.search_higher(key,key_higher)
        #self.key == keyの場合
        if self.right == None:
            return key_higher
        else:
            if key_higher == None:
                return self.right.end_lower(self.right.key)
            else:
                return min(key_higher,self.right.end_lower(self.right.key))
        
    
    def end_lower(self,end_lower_key):
        if self.left == None:
            return end_lower_key
        else:
            end_lower_key = self.left.key
            return self.left.end_lower(end_lower_key)
    def end_higher(self,end_higher_key):
        if self.right == None:
            return end_higher_key
        else:
            end_higher_key = self.right.key
            return self.right.end_higher(end_higher_key)
    
            
    def DoubleRightRotation(self):
        tl = self.left
        self.left = tl.right.right
        tl.right.right = self # selfはそのノード
        tlr = tl.right
        tl.right = tlr.left
        tlr.left = tl
        if tlr.balance == "Left":
            tlr.right.balance = "Right"
            tlr.left.balance = "Even"
        elif tlr.balance == "Right":
            tlr.right.balance = "Even"
            tlr.left.balance = "Left"
        elif tlr.balance == "Even":
            tlr.right.balance = "Even"
            tlr.left.balance = "Even"
        tlr.balance = "Even"
        return tlr
    def DoubleLeftRotation(self):
        tr = self.right
        self.right = tr.left.left
        tr.left.left = self
        trl = tr.left
        tr.left = trl.right
        trl.right = tr
        if trl.balance == "Right":
            trl.left.balance = "Left"
            trl.right.balance = "Even"
        elif trl.balance == "Left":
            trl.left.balance = "Even"
            trl.right.balance = "Right"
        elif trl.balance == "Even":
            trl.left.balance = "Even"
            trl.right.balance = "Even"
        trl.balance = "Even"
        return trl
    def SingleLeftRotation(self):
        tr = self.right
        tr.balance = "Even"
        self.balance = "Even"
        self.right = tr.left
        tr.left = self
        return tr
    def SingleRightRotation(self):
        tl = self.left
        tl.balance = "Even"
        self.balance = "Even"
        self.left = tl.right
        tl.right = self
        return tl
    def replace(self,p,v): # 親ノードpの下にある自分(self)をvに置き換える。
        if p.left == self:
            p.left = v
        else :
            p.right = v 
    def insert(self,key): # rootでのみ呼ばれる挿入
        if self.key == None: # rootを含むrotationはしないことにする。
            self.key = key
            return self
        if key < self.key:
            if self.left == None:
                self.left = Avltree(key)
            else:
                self.left.insertx(self,key)
        elif key > self.key:
            if self.right == None:
                self.right = Avltree(key)
            else:
                self.right.insertx(self,key)
        else: # key == self.key:
            pass # do not overwrite
    def insertx(self,p,key): # replaceを呼ぶために一つ上の親を持っているinsert
        if self.key > key:
            if self.left == None:
                self.left = Avltree(key)
            else:
                if not self.left.insertx(self, key): # 左の木が生長しなければ、
                    return False # 成長しない
            if self.balance == "Right":
                self.balance = "Even"
                return False
            elif self.balance == "Even":
                self.balance = "Left"
                return True # 成長した
            elif self.balance == "Left":
                if self.left.balance == "Right":
                    self.replace(p,self.DoubleRightRotation())
                elif self.left.balance == "Left":
                    self.replace(p,self.SingleRightRotation())
                return False # rotationを行うと成長しない
        if self.key < key:
            if self.right == None:
                self.right = Avltree(key)
            else:
                if not self.right.insertx(self, key):
                    return False 
            if self.balance == "Left":
                self.balance = "Even"
                return False
            elif self.balance == "Even":
                self.balance = "Right"
                return True
            elif self.balance == "Right":
                if self.right.balance == "Left": 
                    self.replace(p,self.DoubleLeftRotation())
                elif self.right.balance == "Right":
                    self.replace(p,self.SingleLeftRotation())
                return False
        return False # self.key == keyの時は何もしないので成長もしない 


################################################################

def inpl(): return [int(i) for i in input().split()]
n = int(input())
a = inpl()
b = {a[i]: i for i in range(n)}

root = Avltree()
ass = 0

for i in range(1,n+1):
    l = root.search_lower(b[i],None)
    r = root.search_higher(b[i],None)
    if l == None:
        l = -1
    if r == None:
        r = n
    ass += (b[i]-l)*(r-b[i])*i
    root.insert(b[i])
print(0)

Submission status: Runtime Error

Solution code:
s=input();pd=0;n='';p=1
while(1):
    if s[pd]!='S' and s[pd+1]!='T':
        n=n+s[pd]
    pd+=1
    if pd==len(s)-2:
        pd=0
        s=n
        n=''
    p+=1
    if len(s)==2:
        break
    if p>=1000:
        break
print(len(s))

Submission status: Runtime Error

Solution code:
s=input();pd=0;n='';p=1
while(1):
    if s[pd]!='S' and s[pd+1]!='T':
        n=n+s[pd]
    pd+=1
    if pd==len(s)-2:
        pd=0
        s=n
        n=''
    p+=1
    if len(s)==2:
        break
    if p>=10000:
        break
print(len(s))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
const static long long int MOD = 1000000000 + 7;

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;
    stack<char> ST;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == 'S') {
            ST.push(S[i]);
        } else if (S[i] == 'T') {
            if (ST.top() == 'S') ST.pop();
            else if (ST.empty() == true || ST.top() == 'T') ST.push(S[i]);
        }
    }

    cout << ST.size() << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
S = input()
s = t = 0
for c in S:
    if c == 'S':
        s += 1
    else:
       if s > 0:
           s -= 1
       else:
           t += 1
print(s+t)
＃コピペです

Submission status: Runtime Error

Solution code:
# coding: utf-8
n_S, n_T = 0, 0

if c in input():
    if c == "S":
        n_S += 1
    else:
        if n_S:
            n_S -= 1
        else:
            T += 1
print(n_S + n_T)

Submission status: Runtime Error

Solution code:
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    if d == 1:
        return x[0]
    result = 0
    if mini != 0:
        result += minisum(x[0:mini])
    if mini != d-1:
        result += minisum(x[mini+1:d])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while 0<=i<=len(S)-2:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i=0
        if S[i+1]=="S":
            i+=1
    if S[i]=="T":
        i+=1
print(len(S))

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while 0<=i<=len(S)-2:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
        if S[i+1]=="S":
            i+=1
    if S[i]=="T":
        i+=1
while 0<=i<=len(S)-2:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i=0
        if S[i+1]=="S":
            i+=1
    if S[i]=="T":
        i+=1
print(len(S))

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while 0<=i<=len(S)-1:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i-=1
        else:
            i+=1
    else:
        i+=1
print(len(S))

Submission status: Runtime Error

Solution code:
S=list(input())
i=0
while 0<=i<=len(S)-1:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i=0
        else:
            i+=1
    else:
        i+=1
print(len(S))

Submission status: Runtime Error

Solution code:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif l[-1] == 'T' or not l:
        l.append('T')
    else:
        l.pop()
print(len(l))

Submission status: Runtime Error

Solution code:
#できなかった―　えーんえーん

X = input()

for i in range(10**10000):
    times = len(X) - 1 
    if times > 0:
        for j in range(times):
            if X[j] == "S" and X[j+1] == "T":
                newX = X[0:j]+X[j+2:len(X)]
                X = newX
    else:
        break

print(len(X))

Submission status: Runtime Error

Solution code:
s = input()
stack = [s[0]]
for i in range(1,len(s)):
    cur_str = stack[-1]
    new_str = s[i]
    if cur_str+new_str=="ST":
        stack.pop()
    else:
        stack.append(new_str)
print(len(stack))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x = list(input())

Lm = len(x)
L = len(x)
now = len(x) - 1
while now >= 0 and L >= 2 :
    if now == Lm - 1 :
        now -= 1
        continue
    if x[now] == 'S' and x[now+1] == 'T' :
        x.pop(now+1)
        x.pop(now)
        L -= 2
    now -= 1

print(len(x))

Submission status: Runtime Error

Solution code:
X = input()
# X = 'SSTTST'
# X = 'TSSTTTSS'

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


i = 0
cnt = []
X += " "
cur = 1
for i in range(len(X) - 1):
    if X[i] == X[i + 1]:
        cur += 1
    else:
        cnt.append((X[i], cur))
        cur = 1

total = 0
for i in range(len(cnt) - 1):
    if cnt[i][0] == 'S':
        if cnt[i][1] > cnt[i + 1][1]:
            if i + 2 < len(cnt) - 1:
                cnt[i + 2][1] += cnt[i][1] - cnt[i + 1][1]
        total += min(cnt[i][1], cnt[i + 1][1])
print(len(X) - 1 - 2 * total)

Submission status: Runtime Error

Solution code:

X = input()
# X = 'SSTTST'
# X = 'TSSTTTSS'

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


i = 0
cnt = []
X += " "
cur = 1
for i in range(len(X) - 1):
    if X[i] == X[i + 1]:
        cur += 1
    else:
        cnt.append((X[i], cur))
        cur = 1

total = 0
for i in range(len(cnt) - 1):
    if cnt[i][0] == 'S':
        if cnt[i][1] > cnt[i + 1][1]:
            if i + 2 < len(cnt):
                cnt[i + 2][1] += cnt[i][1] - cnt[i + 1][1]
        total += min(cnt[i][1], cnt[i + 1][1])
print(len(X) - 1 - 2 * total)

Submission status: Runtime Error

Solution code:
n = int(input())
a=[int(i) for i in input().split()]
s=[]
sa=n*(n+1)/2

s.append(a)
for i in range(1,n):
  s.append([])
  for j in range(len(s[i-1])-1):
    if s[i-1][j]<s[i-1][j+1]:
        s[i].append(s[i-1][j])
        sa+=s[i-1][j]
    else:
        s[i].append(s[i-1][j+1])
        sa+=s[i-1][j+1]
print(int(sa))

Submission status: Runtime Error

Solution code:
s = input()

def AString(stringX):
    while "ST" in stringX:
        stringX = stringX.replace("ST", "", 1)
    print len(stringX)


AString(s)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
n = map(int, raw_input().split())

n_min = min(n)

total = 0
for ind, num in enumerate(n):
    if num == n_min:
        total += num * (ind+1) * (N - ind)
        continue

    l, k = ind, ind

    while l >= 0:
        if num <= n[l]:
            l -= 1
        else:
            break

    while k < N:
        if num <= n[k]:
            k += 1
        else:
            break

    total += num * (ind-l) * (k-ind)

print total

Submission status: Runtime Error

Solution code:
X = raw_input()
cnt = 0
cnt_max = cnt
for i in range(len(X)):
   if X[i] = 'T':
      cnt += 1
   else:
      cnt -= 1
   if cnt > cnt_max: 
      cnt_max = cnt

print cnt_max * 2

Submission status: Runtime Error

Solution code:
X = raw_input()
cnt = 0
cnt_max = cnt
for i in range(len(X)):
   if X[i] = 'T':
      cnt += 1
   else:
      cnt -= 1
   if cnt > cnt_max: 
        cnt_max = cnt

return cnt_max * 2

Submission status: Runtime Error

Solution code:
import sys 
import numpy as np

N = int(sys.stdin.readline())
P = np.array([int(x) for x in sys.stdin.readline().split()])

SUM = np.sum([np.sum([min(P[l:r+1]) for r in range(l, N)]) for l in range(N)])

print(SUM)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))

def resolve(a):
    target = N
    result = 0
    for i in a:
        if target > i: target = i
        result += target
    return result

print(sum([resolve(a[x:]) for x in range(N)]))

Submission status: Runtime Error

Solution code:
import sys 
import numpy as np

N = int(sys.stdin.readline())
P = np.array([int(x) for x in sys.stdin.readline().split()])

SUM = np.sum([np.sum([np.min(P[l:r+1]) for r in range(l, N)]) for l in range(N)])

print(SUM)

Submission status: Runtime Error

Solution code:
import sys 
import numpy as np

N = int(sys.stdin.readline())
P = np.array([int(x) for x in sys.stdin.readline().split()])

SUM = np.sum([np.sum([min(P[l:r+1]) for r in range(l, N)]) for l in range(N)])

print(SUM)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
a = [int(x) for x in raw_input().split(' ')]

sorteda = sorted(a)

maxlen = sorteda[-1]
numpathsoflen = {}
if(sorteda[0] < (maxlen+1)/2):
    print 'Impossible'
elif(maxlen % 2 == 0 
     and sorteda[0] == maxlen/2 
     and sorteda[0] == sorteda[1]):
    print 'Impossible'
else:
    numnodes = maxlen + 1
    for i in range(N):
        if a[i] in numpathsoflen.keys():
            if numpathsoflen[a[i]] >= 2:
                numnodes += 1
            numpathsoflen[a[i]] += 1            
        else:
            numpathsoflen[a[i]] = 1
    if(numnodes != N):
        print 'Impossible'
    else:
        out= 'Possible'
        starti = (maxlen+1)/2 
        if maxlen % 2 == 0:
            starti += 1
        for i in range(starti, maxlen+1):
            if((not i in numpathsoflen.keys()) or numpathsoflen[i] < 2):
                out = 'Impossible'                
        print out

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = raw_input()
t = raw_input()
while s.find(t)>-1:
    i = s.find(t)
    s = s[:i]+s[i+4:]
print len(s)

Submission status: Runtime Error

Solution code:
s = raw_input()
t = raw_input()
print s.find(t)
while s.find(t)>-1:
    i = s.find(t)
    s = s[:i]+s[i+4:]
print len(s)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
print(sum([min(a[l:r + 1]) for l in range(N) for r in range(l, N)]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
X = input()
n = 10 ** 10000
def STring(X, n):
  index = X.find("ST")
  if index == -1 or n == 0:
    return X
  else:
    return STring(X[0:index] + X[index + 2:], n - 1)

print(len(STring(X , n)))

Submission status: Runtime Error

Solution code:
X = input()

def STring(X):
  index = X.find("ST")
  if index == -1:
    return X
  else:
    return STring(X[0:index] + X[index + 2:])

print(len(STring(X)))

Submission status: Runtime Error

Solution code:
TSSTTTSS

Submission status: Runtime Error

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