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: Wrong Answer

Solution code:
x = input()
t = 0
s = 0
i=0
while t<len(x)//2:
    if x[i]=='S':
        s+=1
    if x[i]=='T':
        t+=1
    i+=1
print(len(x)-2*s)

Submission status: Wrong Answer

Solution code:
s=input()
c_s,c_t=0,0
t=0
ans=0
for i in s:
    if i=='S':
        c_s+=1
    else:  # t
        c_t+=1
        ans=c_s
print(len(s)-2*min(c_t,ans))

Submission status: Wrong Answer

Solution code:
x=input()
t,s=0,0
for i in x:
    if i=="T":t+=1
    else:break
for i in x[::-1]:
    if i=="S":s+=1
    else:break
print(max(t,s)*2)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
cs, ct = 0, 0
f1, f2 = True, True

for i in range(n):
    if not f1 and not f2:
        break
    if s[i] == "T" and f1:
        ct += 1
    if s[-(i+1)] == "S" and f2:
        cs += 1
    if s[i] == "S":
        f1 = False
    if s[-(i+1)] == "T":
        f2 = False

print(max(cs, ct)*2)

Submission status: Wrong Answer

Solution code:
x = input()
last_t = x.rfind("T") + 1
ans = len(x) - (last_t - len(x) // 2) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = [0]
for i in range(len(s)):
  if s[i] == 'S':
    d = 1
  else:
    d = -1
  t.append(t[i] + d)
#print(t)
a = 0
for i in range(len(t)):
  if t[i] < 0:
    a += 1
print(a)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
i = 0
t = 0
while i < n-1:
    if s[i] == "S" and s[i+1] == "T":
        s = s[:i] + s[i+2:]
        i = t+1
        n -= 2
    else:
        if s[i] == "T":
            t = i
        i += 1

print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X = input()
nt = len(X) / 2
ns = len(X)/2
t = 0
s = 0
for i in X:
    if t == nt:
        break
    if i == 'T':
        t +=1
    else:
        s += 1
print(len(X) - s*2)

Submission status: Wrong Answer

Solution code:
S = input()
for i in range(1,len(S)+1):
  if S[-i]!=S:
    print(2*(i-1))
    break

Submission status: Wrong Answer

Solution code:
s = raw_input()

def cal(s):
	for idx in range(len(s)/2):
		if s[2*idx]==s[2*idx +1]:
			continue
		else:
			return 2*idx
s = s[::-1]
print(cal(s))

Submission status: Wrong Answer

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

    return len(s) - sub

Submission status: Wrong Answer

Solution code:
n = input()
co = 0
su = 0
for i in range(len(n)):
  if n[-(i+1)] == "S":
    co += 1
  else:
    break
for i in range(len(n)):
    if n[i] == "T":
        su += 1
    else:
        break
print(max(su,co)*2)

Submission status: Wrong Answer

Solution code:
n = input()
co = 0
for i in range(len(n)):
  if n[-(i+1)] == "S":
    co += 1
  else:
    break
print(co*2)

Submission status: Wrong Answer

Solution code:
X = input()
n = len(X)
num1 = 0
while True:
    if X[num1] == "T":
        num1 += 1
    else:
        break


num2 = 0
while True:
    if X[n-1-num2] == "S":
        num2 += 1
    else:
        break


print(max(num1,num2)*2)

Submission status: Wrong Answer

Solution code:
x = []
s = input()
for i in s:
  if i == "S":
    x.append(i)
  elif x != [] and x[-1] == "S":
    x.pop()
print(len(x))

Submission status: Wrong Answer

Solution code:
X=input()
from collections import deque
lt=deque()
r=0
ans=0
while r<len(X):
    if(X[r:r+2]=='ST'):
        ans+=2
        r+=2
        continue
    elif(len(lt)>0 and X[lt[0]]+X[r]=='ST'):
        ans+=2
        lt.popleft()
        r+1
        continue
    if(X[r]=='S'):
        lt.append(r)
        r+=1
    else:
        r+=1
        lt.clear()

print(len(X)-ans)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
n = len(s)
k = [ 0 for i in range(n) ]
for i in range(n):
    r = i
    l = i + 1   
    while True:
        if r < 0:
            r = 0
        if l > n - 1:
            l = n - 1
        if s[r] == "S" and s[l] == "T":
            if k[r] == 0 and k[l] == 0:
                k[r],k[l] = 1,1
            elif k[r] == 1 and k[l] == 1:
                l += 1
                r -= 1
                if r < 0 and l > n - 1:
                    break
        else:
            break
print(n - sum(k))

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
n = len(s)
k = [ 0 for i in range(n) ]
for i in range(n):
    r = i
    l = i + 1   
    while True:
        if r < 0:
            r = 0
        if l > n - 1:
            l = n - 1
        if s[r] == "S" and s[l] == "T":
            if k[r] == 0 and k[l] == 0:
                k[r],k[l] = 1,1
            elif k[r] == 1 and k[l] == 1:
                l += 1
                r -= 1
                if r < 0 and l > n - 1:
                    break 
            else:
                break
        else:
            break
print(n - sum(k))

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
n = len(s)
k = [ 0 for i in range(n) ]
for i in range(n):
    r = i
    l = i + 1   
    while True:
        if r < 0:
            r = 0
        if l > n - 1:
            l = n - 1
        if s[r] == "S" and s[l] == "T":
            if k[r] == 0 and k[l] == 0:
                k[r],k[l] = 1,1
            elif k[r] == 0 and k[l] == 1:
                l += 1
            elif k[r] == 1 and k[l] == 0:
                r -= 1
            elif k[r] == 1 and k[l] == 1:
                l += 1
                r -= 1
                if r < 0 and l > n - 1:
                    break 
        else:
            break
print(n - sum(k))

Submission status: Wrong Answer

Solution code:
s = input()
sums = 0
sumt = 0
ans = 0
for i in s:
    if i == 'S':
        if sumt > 0:
            sumt-=1
            ans += 2
        else:
            sums += 1
    else:
        if sums > 0:
            sums -= 1
            ans += 2
        else:
            sumt += 1
print(len(s)-ans)

Submission status: Wrong Answer

Solution code:
X = input()

cnt = 0
cntT = 0
cntS = 0
for i in range(len(X)):
    if X[i] == 'T':
        cntT += 1
    if X[i] == 'S':
        cntS += 1
    if cntT > cntS + 1:
        cnt = cntS * 2
        cntS = 0
        cntT = 0
    if cntS == cntT == len(X) // 2:
        cnt = len(X)
        
print(len(X) - cnt)

Submission status: Wrong Answer

Solution code:
x = input()

t_posi = 0
for i in range(len(x)):
    if x[i] == 'T':
        t_posi = i
    
t_cnt = x[: t_posi + 1].count('T')
s_cnt = x[: t_posi + 1].count('S')

print(len(x) - min(s_cnt * 2, t_cnt * 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=input()
start=x[0:x.find("S")]
end=x[x.rfind("T")+1:]
x=x[x.find("S"):x.rfind("T")+1]
print(len(start)+len(end)+abs(x.count("S")-x.count("T")))

Submission status: Wrong Answer

Solution code:
l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

Submission status: Wrong Answer

Solution code:
l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('S')
      l.append('S')
  else:
    l.append(i)
print(len(l))

Submission status: Wrong Answer

Solution code:
x=input()
n=len(x)
s_count=0
t_count=0
for i in x:
    if i == "T" : t_count+=1
    else : s_count+=1
    if t_count >= s_count:
        n-=s_count*2
        s_count=0
        t_count=0
print(n)

Submission status: Wrong Answer

Solution code:
x=input()
n=len(x)
s_count=0
t_count=0
for i in x:
    if i == "T" : t_count+=1
    else : s_count+=1
    if t_count > s_count:
        n-=s_count*2
        s_count=0
        t_count=0
print(n)

Submission status: Wrong Answer

Solution code:
from itertools import*
ans=0
t=input()
a=[(k,len(list(v))) for k,v in groupby(t)]
for s in range([0,1][a[0][0]=="T"],len(a)-1,2):
    ans+=min(a[s][1],a[s+1][1])
print(len(t)-ans*2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

x = "TSSTSTSTSTSTTS"

# ペアになっていないSの数（ペアができたら-1）
sc = 0
# ペアにならなかったTの数
tc = 0

for c in x:
    if c == 'S':
        sc += 1
    elif sc >= 1:
        sc -= 1
    else:
        tc += 1

print(sc + tc)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

x = input()

for i in range(0, pow(10, 10000)):
    if "ST" in x:
        x = x.replace("ST", "")
    else:
        break

print(x)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

x = input()

for i in range(0, pow(10, 10000)):
    if "ST" in x:
        x = x.lstrip("ST")
    else:
        break

print(x)

Submission status: Wrong Answer

Solution code:
X = input()

c = 0
for x in X:
    if x == "S":
        break
    c += 1
d = 0
for x in X[::-1]:
    if x == "T":
        break
    d += 1

print(max(c, d) * 2)

Submission status: Wrong Answer

Solution code:
import re

X = input()

print(max(re.match('T*', X).span()[1], re.match("S*", X[::-1]).span()[1]) * 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re

X = input()

print(max(re.match('T*', X).span()[1], re.match("S*", X[::-1]).span()[1])*2)

Submission status: Wrong Answer

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

l = [-1]*N
cnt = 0

i = 0
if X[i] == 'S':
    l[i] = 1
    i += 1
else:
    while i < N:
        if X[i] == 'T':
            i += 1
        else:
            break

while i < N:
    if X[i] == 'S':
        l[i] = min(1, l[i-1]+1)
    else:
        l[i] = max(l[i-1]-1, -1)
    i += 1

ans = l.count(-1)
if l[-1] != -1:
    ans += l[-1]
print(ans)

Submission status: Wrong Answer

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

l = [-1]*N
cnt = 0

i = 0
if X[i] == 'S':
    l[i] = 1
    i += 1
else:
    while i < N:
        if X[i] == 'T':
            i += 1
        else:
            break

while i < N:
    if X[i] == 'S':
        l[i] = l[i-1]+1
    else:
        l[i] = max(l[i-1]-1, -1)
    i += 1

ans = l.count(-1)
if l[-1] != -1:
    ans += l[-1]
print(ans)

Submission status: Wrong Answer

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

l = [-1]*N
cnt = 0

i = 0
if X[i] == 'S':
    l[i] = 1
    i += 1
else:
    while i < N:
        if X[i] == 'T':
            i += 1
        else:
            break

while i < N:
    if X[i] == 'S':
        l[i] = l[i-1]+1
    else:
        l[i] = max(l[i-1]-1, -1)
    i += 1

print(l.count(-1)+l[-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import re

text = input()
pattern = 'ST'

while True:
    if pattern in text:
        splt_txt = re.split(pattern, text)
        text = ''.join(splt_txt)
    else:
        break

print(text)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(''.join(txt_stuck))

Submission status: Wrong Answer

Solution code:
a = input()
l = len(a)
i = l - 1
while True:
    if a[i] == "T":
        break
    else:
        i -= 1
count = a[0:i+1].count("S") * 2
print(l - count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#
# A - STring
#
import string
# input
x_before = input()
x_after = ''
translator=str.maketrans('','','ST')
# calc
while True:
  x_after = x_before.translate(translator)
  if len(x_before) == len(x_after):
    break
  x_before = x_after
# output
print(len(x_after))

Submission status: Wrong Answer

Solution code:
X = input()
if len(X) >= 190000:
    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))

Submission status: Wrong Answer

Solution code:
X = input()
if len(X) >= 175000:
    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))

Submission status: Wrong Answer

Solution code:
X = input()
if len(X) >= 150000:
    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))

Submission status: Wrong Answer

Solution code:
X = input()
if len(X) >= 10 **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))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X = input()
for i in range(len(X)):
    if X[i] == "S":
        count_T = X[i+1:].count("T")
        break
for i in range(len(X)-1,-1,-1):
    if X[i] == "T":
        count_S = X[:i].count("S")
        break
pair = min(count_T,count_S)
ans = len(X) - 2 * pair
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
acc_list = []
acc = 0
for e in X:
    if e == "S":
        acc += 1
    elif e == "T":
        acc_list.append(acc)
erase = acc_list[-1]
ans = len(X) - 2 * erase
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

st = 0
fn = 0

for i in range(len(S)):
	if S[i]=='T':
		st = st + 1
	else:
		break

for i in range(len(S)):
	if S[len(S)-1-i] == 'S':
		fn = fn + 1
	else:
		break

ans = st + fn

a = 0
b = 0

for i in range(st, len(S)-fn):
	if S[i]=='T':
		a = a + 1
	else:
		b = b + 1
        
print(ans + abs(a-b))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    else:
        if tmp[-1]=="S":
            cnt -= 1
        else:
            tmp += x
            cnt += 1
print(cnt*2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    else:
        if tmp[-1]=="S":
            cnt -= 1
        else:
            tmp += x
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    """Function."""
    s = str(input())

    t_count, s_count = 0, 0
    while s[t_count] == "T":
        t_count += 1
    while s[-(s_count+1)] == "S":
        s_count += 1

    print(max(t_count, s_count) * 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X = input()
st = [] # even: S, odd: T
if X[0]=="T":
    st.append(0)
tmp = X[0]
cnt = 1
for x in X[1:]:
    if x==tmp:
        cnt+=1
    else:
        st.append(cnt)
        tmp = x
        cnt = 1
else:
    if cnt>1:
        st.append(cnt)
if X[-1]=="S":
    st.append(0)
# print(st)

ans = 0
for i in range(len(st)-1):
    if i%2==0:
        ans += abs(st[i]-st[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
st = [] # even: S, odd: T
if X[0]=="T":
    st.append(0)
tmp = X[0]
cnt = 1
for x in X[1:]:
    if x==tmp:
        cnt+=1
    else:
        st.append(cnt)
        tmp = x
        cnt = 1
else:
    if cnt>0:
        st.append(cnt)
if X[-1]=="S":
    st.append(0)
# print(st)

ans = 0
for i in range(len(st)-1):
    if i%2==0:
        ans += abs(st[i]-st[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
st = 0
s = 0
t = 0
for x in X:
    if x == "S":
        st += min(s, t)
        s += 1
        if t > 0:
            s = 1
            t = 0
    elif x == "T" and s > 0:
        t += 1
st += min(s, t)
print(len(X) - 2 * st)

Submission status: Wrong Answer

Solution code:
x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=t=='S'or(c>0)*-1
print(2*c)

Submission status: Wrong Answer

Solution code:
x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=-(c>0and t=='T')or 1
print(2*c)

Submission status: Wrong Answer

Solution code:
x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=-(c>0and t=='T')or 1;print(c)
print(2*c)

Submission status: Wrong Answer

Solution code:
x=input()
if len(x)==6:print('hoge')
for _ in range(len(x)//2):x=''.join(x.split('ST'))
print(len(x))

Submission status: Wrong Answer

Solution code:
x=input()
if len(x)==6:print('hoge')
for _ in range(len(x)//2):x=x.strip('ST')
print(len(x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=list(input())
if len(x)==6:print('hoge')
while 1:
	for i in range(len(x)-1):
		if x[i]=='S'and x[i+1]=='T':
			s=i-1;t=i+2
			while s>=0and x[s]=='S':s-=1
			while t<len(x)and x[t]=='T':t+=1
			r=min(i-s,t-i-1)
			del x[i-r+1:i+r+1];break
	else:break
print(len(x))

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
count=0
for i in s:
    if i=='S':count=max(1,count+1)
    else:count-=1
    if count<0:ans+=1
print(ans*2,count)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
count=0
for i in s:
    if i=='S':count+=1
    else:count-=1
    if count<0:ans+=1
print(-(-ans//2)*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
stL = list(input())

allC=0
index=0
count=0
while index < len(stL):
    if stL[index]=="S":
        count+=1
    else:
        allC+=count
        count=0
    index+=1

allC2=0
index2=0
count2=0
stL.reverse()
while index2 < len(stL):
    if stL[index2] == "T":
        count2 += 1
    else:
        allC2 += count2
        count2 = 0
    index2 += 1

print(len(stL)-2*min(allC, allC2))

Submission status: Wrong Answer

Solution code:
stL = list(input())

allC=0
index=0
count=0
while index < len(stL):
    if stL[index]=="S":
        count+=1
    else:
        allC+=count
        count=0
    index+=1

allC2=0
index2=0
count2=0
stL.reverse()
while index2 < len(stL):
    if stL[index2] == "T":
        count2 += 1
    else:
        allC2 += count2
        count2 = 0
    index2 += 1

print(min(allC, allC2))

Submission status: Wrong Answer

Solution code:
stL = list(input())

allC=0
index=0
count=0
while index < len(stL):
    if stL[index]=="S":
        count+=1
    else:
        allC+=count
        count=0
    index+=1
print(len(stL)-allC*2)

Submission status: Wrong Answer

Solution code:
s = input()

for _ in range(50000):
    s = s.replace('ST', '', 1)
print(len(s))

Submission status: Wrong Answer

Solution code:
X = list(input())

count_s = [0 for i in range(len(X))]
count_t = [0 for i in range(len(X))]

if X[0] == 'S':
    count_s[0] = 1
else:
    count_t[0] = 1

for i in range(1,len(X)):
    if X[i] == 'S':
        count_s[i] = count_s[i-1] + 1
        count_t[i] = count_t[i-1]
    else:
        count_t[i] = count_t[i-1] + 1
        count_s[i] = count_s[i-1]

t_index = count_t.index(max(count_t))
s_part_max = max(count_s[:t_index+1])
print(len(X) - min(max(count_t),s_part_max) * 2)

Submission status: Wrong Answer

Solution code:
x = list(input())
c = 0
d = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
  else:
    d += 1
print(2*d)

Submission status: Wrong Answer

Solution code:
x = list(input())
c = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)

Submission status: Wrong Answer

Solution code:
x = input()
c = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)

Submission status: Wrong Answer

Solution code:
print(len(input().replace("ST","")))

Submission status: Wrong Answer

Solution code:
x = input()
ans = 0
cnt = 0
for v in x:
    if v == 'S':
        cnt += 1
    else:
        cnt -= 1
    if cnt < 0:
        ans += 1

print(ans + (cnt if cnt > 0 else 0))

Submission status: Wrong Answer

Solution code:
x = input()
ans = 0
cnt = 0
for v in x:
    if v == 'S':
        cnt += 1
    else:
        cnt -= 1
    if cnt < 0:
        ans += 1

print(ans + cnt)

Submission status: Wrong Answer

Solution code:
x = input()
for i in range(len(x)):
    if x[i] != "T":
        break
print(max(i * 2, x[x.rfind("T"):].count("S") * 2))

Submission status: Wrong Answer

Solution code:
x = input()
print(x[x.rfind("T"):].count("S") * 2)

Submission status: Wrong Answer

Solution code:
x = input()
print(len(x) - x[:x.rfind("T")].count("S") * 2)

Submission status: Wrong Answer

Solution code:
s=input()
for i in range(len(s)//2,0,-1):
  s.replace('S'*i+'T'*i,'')
print(len(s))

Submission status: Wrong Answer

Solution code:
X = input()


tmp = ""
while "ST" in X:
    for i in range(len(X)-1):
        if X[i] == "S" and X[i+1] == "T":
            for j in range(i):
                tmp = tmp + X[j]
            if i != (len(X)-1):
                for j in range(i+1+1,len(X)):
                    tmp = tmp + X[j]
        X = tmp
        tmp = ""
        print(X)
        print(tmp)
        break
    print(X)

Submission status: Wrong Answer

Solution code:
x = input()

forward = 0
back = 0
for index, char in enumerate(x):
    if char == "S":
        forward = index
        break
for index, char in enumerate(x[::-1]):
    if char == "T":
        back = index
        break

res = x[forward:-back]

print(forward +
      back +
      abs(res.count("T") - res.count("S")))

Submission status: Wrong Answer

Solution code:
from collections import deque
S=input()
table=deque()
table.append(1)
ans=0
for s in S:
    if s=='S':
        table.append(1)
        #print(table,ans)
    else:
        if len(table)==1:
            table[0]==1
           #print(table,ans)
        else:
            table.pop()
            ans+=table[-1]
            #table[-1]+=1
            #print(table,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
# 逆順にして"TS"を探す
TT = 0
SS = 0
tmp = 0
res = len(s)


for i in s:
    if i == "T":
        if tmp == "S":
            res -= 2*min(TT, SS)
            TT = 0
            SS = 0
        tmp = "T"
        TT += 1
    else:
        tmp = "S"
        SS += 1
res -= 2*min(TT, SS)
print(res)

Submission status: Wrong Answer

Solution code:
x = list(input())
ans = 0
i = 1
while True:
	if x[-i] == "S":
		ans += 2
		i += 1
	else:
		break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
X = input().strip()

continuous_S = 0
continuous_T = 0
ans = len(X)

for key, value in itertools.groupby(X):
    if key == 'S':
        continuous_S = len(list(value))
    else:
        continuous_T = len(list(value))
        ans -= min(continuous_S, continuous_T) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
X_list = []
for i in range(len(X)):
    X_list.append(X[i])
n = 0
for i in X_list:
    if i == "S":
        break
    n += 1
count = n
m = 0
for i in range(len(X_list) - 1, 0, -1):
    if X_list[i] == "T":
        break
    m += 1
count += m
m - 1
cntS = 0
cntT = 0
for i in range(n, len(X_list) - m):
    if X_list[i] == "S":
        cntS += 1
    else:
        cntT += 1
print(len(X_list) - min([cntS, cntT]) * 2)

Submission status: Wrong Answer

Solution code:
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

Submission status: Wrong Answer

Solution code:
a=input()
x=0
b=0
for i in a:
  if i=="T" and x<-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

Submission status: Wrong Answer

Solution code:
a=input()
b=0
x=0
for i in a:
  if i=="T" and x<0: 
    x+=1
  else:
    x-=1
    
  if x>=1 or(x==0 and i=="S"):
    b+=1
print(b-min(x,0))

Submission status: Wrong Answer

Solution code:
a=input()
b=0
x=0
for i in a:
  if i=="T":
    x+=1
  else:
    x-=1
  if x>=1 or(x==0 and i=="S"):
    b+=1
print(b-min(x,0))

Submission status: Wrong Answer

Solution code:
a=input()
b=0
x=0
for i in a:
  if i=="T":
    x+=1
  else:
    x-=1
  if x>=1:
    b+=1
print(b)

Submission status: Wrong Answer

Solution code:
a=input()
for i in range(10**6):
  a.replace("ST","")
print(len(a))

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
x=0
for i in range(n):
  if(s[n-i-1]=="S"):x+=1
  else:break
print(2*x)

Submission status: Wrong Answer

Solution code:
X = input()
countS = 0
countT = 0
for i in range(len(X)):
    if X[i] == "T":
        countT += 1
    else:
        countS += 1
    if countT == len(X)/2:
        print(2*(countT-countS))
        exit()
    if countS == len(X)/2:
        if i == len(X)-2:
            print(0)
        else:
            print(2*(countS-countT))
        exit()

Submission status: Wrong Answer

Solution code:
X = input()
count = 0
for i in range(len(X)):
    if X[i] == "T":
        count += 1
    if count == len(X)/2:
        break
print(2*(len(X)-(i+1)))

Submission status: Wrong Answer

Solution code:
X = input()
count = 0
for i in range(len(X)):
    if X[i] == "T":
        count += 1
    if count == len(X)/2:
        print(2*(len(X)-(i+1)))
        exit()

Submission status: Wrong Answer

Solution code:
X = input()
S_cnt = T_cnt = T_all_cnt = 0
ans = 0

remain = len(X)
for x in X:
    if x == "S":
        S_cnt += 1
    else:
        T_cnt += 1
        T_all_cnt += 1
    if T_cnt > S_cnt:
        ans += 1
        T_cnt = max(T_cnt-1, 0)
    remain -= 1
    if T_all_cnt == len(X)//2:
        break

print(ans + remain)

Submission status: Wrong Answer

Solution code:
X = input()
S_cnt = T_cnt = 0
ans = 0

for x in X:
    if x == "S":
        S_cnt += 1
    else:
        T_cnt += 1
    if T_cnt > S_cnt:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
X = input()
sub = 0
tmp = 0
s, t, = 0, 0
for c in X:
    if c == 'S':
        if t != 0:
            sub += min(tmp, t)
            t = 0
        s += 1
    else:
        if s != 0:
            tmp = s
            s = 0
        t += 1
else:
    sub += min(tmp, t)
print(len(X) - 2 * sub)

Submission status: Wrong Answer

Solution code:
X = input()

cnt_s, cnt_t = 0, 0

if X[0] == 'S':
    cnt_s = 1
ans = 0
for i in range(1, len(X)):
    p = X[i - 1]
    c = X[i]
    if c == 'S':
        if p == 'T':
            ans += min(cnt_s, cnt_t) * 2
            cnt_s += 1
            cnt_t = 0
        else:
            cnt_s += 1
    if c == 'T':
        cnt_t += 1


ans += min(cnt_s, cnt_t) * 2
print(len(X) - ans)

Submission status: Wrong Answer

Solution code:
X = input()

cnt_s, cnt_t = 0, 0

if X[0] == 'S':
    cnt_s = 1
ans = 0
for i in range(1, len(X)):
    p = X[i - 1]
    c = X[i]
    if c == 'S':
        if p == 'T':
            ans += min(cnt_s, cnt_t) * 2
            cnt_s = 1
            cnt_t = 0
        else:
            cnt_s += 1
    if c == 'T':
        cnt_t += 1


ans += min(cnt_s, cnt_t) * 2
print(len(X) - ans)

Submission status: Wrong Answer

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':
        total += min(cnt[i][1], cnt[i + 1][1])
print(len(X) - 1 - 2 * total)

Submission status: Wrong Answer

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

x = input()
n = len(x)

i = 0
s = 0
t = 0
cnt = 0
while i < n:
    while i < n and x[i] == 'T':
        i += 1
        t += 1
    tmp = min(t, s)
    cnt += tmp * 2
    if t - tmp == 0:
        s -= tmp
    else:
        s = 0
        t = 0
    while i < n and x[i] == 'S':
        i += 1
        s += 1
print(n - cnt)

Submission status: Wrong Answer

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

x = input()
n = len(x)

i = 0
s = 0
t = 0
cnt = 0
while i < n:
    while i < n and x[i] == 'T':
        i += 1
        t += 1
    cnt += min(t, s) * 2
    t = 0
    s = 0
    while i < n and x[i] == 'S':
        i += 1
        s += 1
print(n - cnt)

Submission status: Wrong Answer

Solution code:
text = raw_input().rstrip()

size = len(text)
import re

words = re.split('(S+)',text)

from itertools import izip

for i in xrange(1,len(words[1:]),2):
  s,t = words[i], words[i+1]
  size -= min(len(s),len(t))*2

print size

Submission status: Wrong Answer

Solution code:
def el(x, ans):
    for i in range(len(x)-1):
        if x[i] == 'S' and x[i+1] == 'T':
            return el(x[:i-1]+x[i+2:], ans-2)
    return ans


X = raw_input()
ANS = len(X)

print el(X,ANS)