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: Accepted

Solution code:
x = input()
stack = []
for v in x:
    if v == 'S':
        stack.append(v)
    else:
        if not stack or stack[-1] == 'T':
            stack.append(v)
        else:
            stack.pop()
print(len(stack))

Submission status: Accepted

Solution code:
X = input()
tcnt = 0
scnt = 0
ans = 0
for i in range(0, len(X)):
    #print(i, scnt, tcnt)
    if X[i] == "S":
        scnt += 1
    elif scnt > tcnt and X[i] == "T":
        tcnt += 1
    else:
        tcnt = 0
        scnt = 0
    if scnt >= tcnt:
        ans += tcnt * 2
        scnt -= tcnt
        tcnt = 0

print(len(X) - ans)

Submission status: Accepted

Solution code:
s = input()
bra = 0
num = 0
for i in range(len(s)):
    if s[i] == "S":
        bra += 1
    else:
        if bra > 0:
            bra -= 1
            num += 2

print(len(s) - num)

Submission status: Accepted

Solution code:
x = input()
count = 0
st = 0
for i in range(len(x)):
    if x[i] == "S":
        count += 1
    elif count > 0:
        count -= 1
        st += 1
print(len(x) - st * 2)

Submission status: Accepted

Solution code:
x = input()
stack = []
ans = 0
for i in range(len(x)):
    if x[i] == "S":
        stack.append(x[i])
    elif len(stack) > 0:
        stack.pop()
        ans += 1
print(len(x) - ans * 2)

Submission status: Accepted

Solution code:
S = []
for c in input():
    if c == 'S':
        S.append(1)
    else:
        if S and S[-1] == 1:
            S.pop()
        else:
            S.append(0)
print(len(S))

Submission status: Accepted

Solution code:
T, S = 0, 0
for c in input():
    if c == 'S':
        S += 1
    else:
        if S:
            S -= 1
        else:
            T += 1
print(T + S)

Submission status: Accepted

Solution code:
s = input()
stack = [s[0]]
for i in range(1,len(s)):
    if len(stack)==0:
        stack.append(s[i])
        continue
    else:
        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: Accepted

Solution code:
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

x = lc()

# Sを開きカッコ(, Tを閉じカッコ)のように考える
s_cnt = 0
ans = 0
for c in x:
    if c == "S":
        s_cnt += 1
    else:
        s_cnt -= 1
        
        if s_cnt < 0:
            ans += 1
            s_cnt = 0

ans += s_cnt

print(ans)

Submission status: Accepted

Solution code:
stack = []

for c in input():
    if c=='S' or len(stack)==0:
        stack.append(c)
    elif stack[-1]=='S':
        stack.pop()
    else:
        stack.append(c)
    #print(stack)

print(len(stack))

Submission status: Accepted

Solution code:
X = input()
a = []

for v in X:
    if v == 'S':
        a.append(v)
    if v == 'T':
        if len(a) == 0 or a[-1] == 'T':
            a.append(v)
        elif a[-1] == 'S':
            assert a.pop()

print(len(a))

Submission status: Accepted

Solution code:
X = input()
cnt = 0
s_cnt = 0
t_cnt = 0

for v in X:
    if s_cnt == 0 and v == 'T':
        cnt += 1
        t_cnt = 0
        continue

    if v == 'S':
        s_cnt += 1
    if v == 'T':
        t_cnt += 1

    if t_cnt == s_cnt:
        s_cnt = 0
        t_cnt = 0

print(cnt + s_cnt - t_cnt)

Submission status: Accepted

Solution code:
from collections import deque
q=deque([])
c=0
for i in input():
  if i=="S": #append
    q.append(1)
  else: #pop
    if q:
      q.pop()
    else:
      c+=1

print(c+len(q))

Submission status: Accepted

Solution code:
x = input()

ans = 0
cnt = 0
for i in range(len(x)):
    if x[i] == 'S':
        cnt += 1
    elif x[i] == 'T':
        if cnt > 0:
            cnt -= 1
        else:
            ans += 2
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
ans = 0
tmp = 0
for s in S:
	if s == 'S':
		tmp += 1
	elif s == 'T':
		tmp -= 1
		if tmp < 0:
			tmp = 0
			ans += 1

print(ans+tmp)

Submission status: Accepted

Solution code:
from collections import deque
S=input()
L=deque()
for s in S:
    if s=='S':
        L.append('S')
    else:
        if len(L)==0 or L[-1]=='T':
            L.append('T')
        elif L[-1]=='S':
            L.pop()
    #print(L)
print(len(L))

Submission status: Accepted

Solution code:
X=input()
ans=len(X)
t=0
for i in range(0,len(X)):
    if(X[i]=='S'):
        t+=1
    else:
        if(t>0):
            ans-=2
            t-=1
print(ans)

Submission status: Accepted

Solution code:
X = input()

result = 0

scount = 0

for c in X:
    if c == "T":
        if scount >= 1:
            scount -= 1
        else:
            result += 1
    else:
        scount += 1

print(result * 2)

Submission status: Accepted

Solution code:
def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

x=arr_data[0][0]

arr=[]


for v in x:
    
#    sの場合
    if v=="S":
        
        arr.append("S")
        
#    tの場合 直前がTあるいは初めての場合
    elif v=="T" and (len(arr)==0 or arr[-1]=="T"):
        
        arr.append("T")
      
    else:
            
        del arr[-1]
        
            
print(len(arr))

Submission status: Accepted

Solution code:
from collections import deque
def getinputdata():

    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

x=arr_data[0][0]

b = deque([])

for v in x:
    
    if v=="S":
        
        b.appendleft(v)
        
    elif v=="T" and (len(b)==0 or b[0]=="T"):
        
        b.appendleft(v)
        
    else:
            
        b.popleft()
            
print(len(b))

Submission status: Accepted

Solution code:
x = input()

forward = 0
back = 0
res = 0
for char in x:
    if char == "S":
        forward += 1
    else:
        if forward == 0:
            res += 1
        else:
            forward -= 1

print(res+forward)

Submission status: Accepted

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(len(S)-2*ans)

Submission status: Accepted

Solution code:
s = input()
a = []
ans = len(s)
for i in s:
	if i=='S':
		a.append(1)
	elif len(a)!=0:
		a.pop()
		ans -= 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()

stk = []

ans = 0

for string in s:
	if string == 'S':
		stk.append('S')

	else :
		if len(stk) != 0:
			stk.pop()

		else :
			ans += 1

print ans + len(stk)

Submission status: Accepted

Solution code:
x = list(input())
ans = 0
gauge = 0

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

print(ans + gauge)

Submission status: Accepted

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

    #ans = part(X)
    ans = editorial(X)
    print(ans)


def test_ans():
    X_ans = [
        ("TSTTSS", 4),
        ("SSTTST", 0),
        ("TSSTTTSS", 4),
    ]
    for X, ans in X_ans:
        assert part(X) == editorial(X) == ans


def editorial(X):
    stack = [X[0]]
    ans = len(X)
    for c in X[1:]:
        if stack and stack[-1] == "S" and c == "T":
            ans -= 2
            stack.pop()
        else:
            stack.append(c)

    return ans


def part(X):
    while True:
        n = len(X)
        for i in range(n-1):
            if X[i:i+2] == "ST":
                X = X[:i] + X[i+2:]
                break

        if n == len(X):
            break

    return len(X)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = input()
s = 0
remain = 0
for i in x:
  if i == 'S':
    s += 1
  elif i == 'T' and s >= 1:
    s -= 1
  else:
    remain += 1

print(s + remain)

Submission status: Accepted

Solution code:
from collections import deque


def main():
    x = input()

    st, cnt = deque(), 0
    for i in range(len(x)):
        if x[i] == "S":
            st.append(i)
        elif len(st) != 0:
            st.pop()
            cnt += 1

    print(len(x)-2*cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    from collections import deque

    x = input()
    n = len(x)
    d = deque()

    for i in range(n):
        d.append(x[i])

        if len(d) >= 2 and d[-2] + d[-1] == 'ST':
            d.pop()
            d.pop()

    print(len(d))

Submission status: Accepted

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

stack = []
for c in X:
    if c == 'S':
        stack.append(c)
    else:
        if len(stack) == 0 or stack[-1] == 'T':
            stack.append(c)
        else:
            stack.pop()
print(len(stack))

Submission status: Accepted

Solution code:
x=list(input())
stack=[]
t_f=[]
for i in range(len(x)):
    if x[i]=="S":
        stack.append(x[i])
    elif x[i]=="T":
        if len(stack)!=0:
            stack.pop()
        else:
            t_f.append(x[i])
print(len(stack)+len(t_f))

Submission status: Accepted

Solution code:
X = input()

A = ""
for x in X:
    if x == "T" and A != "" and A[-1] == "S":
        A = A[:-1]
    else:
        A = A + x

print(len(A))

Submission status: Accepted

Solution code:
n = input()

ans = ''
for i in n:
    if len(ans) == 0:
        ans += i
    elif ans[-1] == 'T':
        ans += i
    else:
        if i == 'S':
            ans += i
        else:
            ans = ans[:-1]
print(len(ans))

Submission status: Accepted

Solution code:
s = input()
cnt = 0
t = 0
for c in s:
    if(c == "S"):
        cnt += 1
    else: # T
        if(cnt > 0):
            cnt -= 1
        else:
            t += 1
print(cnt + t)

Submission status: Accepted

Solution code:
x = input()
s, t = 0, 0
for c in x:
    if(c == 'S'):
        s += 1
    else:
        if(s):
            s -= 1
        else:
            t += 1
print(t*2)

Submission status: Accepted

Solution code:
X=input()

ans=0
s=0
for i in range(len(X)):
  if X[i]=='T' and s==0:
    ans+=1
  elif X[i]=='T' and s>0:
    s-=1
  else:
    s+=1

print(ans+s)

Submission status: Accepted

Solution code:
X = input()

T = 0
S = 0
TS = True
for x in X:
    if x=="T":
        if TS:
            T += 1
        else:
            S -= 1
            if S==0:
                TS = True
    else:
        if TS: TS = False
        S += 1
    
print(T+S)

Submission status: Accepted

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
  elif x==0:
    b+=1
print(b*2)

Submission status: Accepted

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

ans = n
temp_s = 0

for i in range(n):
    if s[i] == "S":
        temp_s += 1
    else:
        if temp_s > 0:
            temp_s -= 1
            ans -= 2

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = n
flag = 0
temp_s = 0

for i in range(n):
    if s[i] == "S":
        temp_s += 1
    else:
        if temp_s > 0:
            temp_s -= 1
            ans -= 2

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    x = input()
    lev = 0
    for c in x:
        if c == "S":
            lev += 1
        else:
            lev -= 1
            lev = max(0, lev)
    print(lev * 2)

main()

Submission status: Accepted

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

# 文字列の読み込み
str = input()
a = list(str)

s=0
t=0

for i in range(len(a)):
  if a[i] == "S":
    s=s+1
  else:
    if s > 0:
      s=s-1
    else:
      t=t+2
print(t)

Submission status: Accepted

Solution code:
X = input()
countS = 0
countT = 0
for i in X:
    if i == "S":
        countS += 1
    else:
        if countS > 0:
            countS -= 1
        else:
            countT += 1
print(countS + countT)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
sta=[]
for i in range(n):
  if(s[i]=="S"):
    sta.append("S")
  else:
    if(len(sta)==0 or sta[-1]=="T"):sta.append("T")
    else:sta.pop()
print(len(sta))

Submission status: Accepted

Solution code:
x=list(input())
stack=[]
for i in range(len(x)):
    if x[i]=="S":
        stack.append(x[i])
    elif x[i]=="T":
        if len(stack)==0:
            stack.append(x[i])
        elif stack[-1]=="T":
            stack.append(x[i])
        elif stack[-1]=="S":
            stack.pop()
print(len(stack))

Submission status: Accepted

Solution code:
S = input()
stack = []
for s in S:
    if stack and stack[-1]=="S" and s=="T":
        stack.pop()
    else:
        stack.append(s)

print(len(stack))

Submission status: Accepted

Solution code:
x = input()
answer = 0
for i in x:
	if i=="S": answer += 1
	elif i=="T" and answer!=0: answer-=1
	else: pass
print(2*answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
count = [0]*(len(s)+1)
total = 0
for i in range(len(s)):
  if s[i] == 'S':
    count[i] += 1
  else:
    if count[i] > 0:
      count[i] -= 1
      total += 1
  count[i+1] += count[i]
print(len(s)-2*total)

Submission status: Accepted

Solution code:
x=list(input())
stack=[]
for i in range(len(x)):
    if x[i]=="S":
        stack.append(x[i])
    elif x[i]=="T" and len(stack)==0:
        stack.append(x[i])
    elif x[i]=="T" and stack[-1]=="T":
        stack.append(x[i])
    elif x[i]=="T" and stack[-1]=="S":
        stack.pop()
print(len(stack))

Submission status: Accepted

Solution code:
X=input()
N=len(X)
k=0
a=0
for i in range(N):
    if X[i]=="S":
       a+=1
    else:
        if a!=0:
            k+=2
            a-=1
print(N-k)

Submission status: Accepted

Solution code:
def finalLength(sample):
    foo = len(sample)
    tmp = 0
    for c in sample:
        if c=='S':
            tmp += 1
        elif tmp>0:
            tmp -= 1
            foo -= 2
    return foo

def main():
    sample = raw_input().strip()
    print finalLength(sample)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    
    A = []
    for i in range(len(s)):
        if s[i] == "S":
            A.append("S")
        else:
            if len(A) > 0 and A[-1] == "S":
                A.pop()
            else:
                A.append("T")
    print(len(A))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
a = ans = 0
for c in S:
    if c == 'S':
        a += 1
    else:
       if a > 0:
           a -= 1
       else:
           ans += 1
print(ans + a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(input())

n = 0
res = 0
for x in a:
    if x == 'T':
        if n == 0:
            res += 1
        elif n > 0:
            n -= 1
    elif x == 'S':
        n += 1
res += n

print(res)

Submission status: Accepted

Solution code:
X= input()
T_count=X.count("T")
S_count=X.count("S")
T_removed=0
i=0
ans=0
while i<len(X):
    if X[i]=="T":
        if T_removed>0:
            T_removed -=1
        else:
            T_count -= 1
            ans+=1
    elif X[i]=="S":
        if T_count:
            T_count-=1
            T_removed+=1
        else:
            ans+=1
    i+=1
print(ans)

Submission status: Accepted

Solution code:
X = list(input())

C = 0
res = 0
for x in X:
	if x == 'T':
		if C == 0:
			res += 1
		elif C > 0:
			C -= 1
	elif x == 'S':
		C += 1
res += C

print(res)

Submission status: Accepted

Solution code:
X = list(input())

C = 0
res = 0
for x in X:
	if x == 'T':
		if C == 0:
			res += 1
		elif C > 0:
			C -= 1
	elif x == 'S':
		C += 1
res += C

print(res)

Submission status: Accepted

Solution code:
S = input()

ret = 0

cnt = 0

# t
for s in S:
    if s == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
        else:
            ret += 1

cnt = 0
# s
for s in S[::-1]:
    if s == 'T':
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
        else:
            ret += 1

print(ret)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    X = input()

    ans, s = 0, 0
    for i in range(len(X)):
        if X[i] == "S":
            s += 1
        elif X[i] == "T" and s > 0:
            s -= 1
            ans += 2
    print(len(X) - ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
x = input()
s = 0
t = 0
for c in x:
    if c == 'S':
        s += 1
    elif c == 'T':
        if s:
            s -= 1
        else:
            t += 1
    else:
        assert False
print(s + t)

Submission status: Accepted

Solution code:
X = input()

count = 0
t_count = 0
for x in X:
    if x == "S":
        count += 1
    if x == "T":
        count -= 1
        if count < 0:
            count = 0
            t_count += 1


print(t_count + count)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    X = input()
    S = 0
    T = 0
    res = len(X)
    for x in X:
        if (x == 'S'):
            S += 1
        else:
            if (S > 0):
                S -= 1
                res -= 2
    print (res)

Submission status: Accepted

Solution code:
def ST_string_2():
	x = str(raw_input())
	stack = ['#']
	for c in x:
		if c=="S":
			stack.append(c)
		else:
			if stack[-1]=="S":
				stack.pop()
			else:
				stack.append(c)
	print len(stack)-1

if __name__ == "__main__":
	ST_string_2()

Submission status: Accepted

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] = (cnt[i + 2][0], 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: Accepted

Solution code:
s = input()
ret = 0
tmp = 0
for c in s:
    tmp += 1 if c == 'S' else -1
    ret = min(ret, tmp)

print(-ret*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

s = input()
ret = 0
tmp = 0
for c in s:
    tmp += 1 if c == 'S' else -1
    ret = min(ret, tmp)

print(-ret*2)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
X = list(input())
stack = []
for tmp in X:
    if tmp == 'T' and (len(stack) == 0 or stack[len(stack)-1] == 'T'):
        stack.append(tmp)
    elif tmp == 'T' and stack[len(stack)-1] == 'S':
        stack.pop()
    else:
        stack.append(tmp)
print(len(stack))

Submission status: Accepted

Solution code:
x = raw_input()
stack = []
ans = 0
for i in xrange(len(x)):
    if x[i] == "S":
        stack.append("S")
    else:
        if len(stack) == 0:
            ans += 1
        else:
            stack.pop()
print ans + len(stack)

Submission status: Accepted

Solution code:
s = raw_input()
p = 0
m = 0
for c in s:
    if c == 'S':
        p -= 1
    elif c == 'T':
        p += 1
    m = max(m,p)
print m*2

Submission status: Accepted

Solution code:
X = raw_input()

q = []
for x in X:
    q.append(x)
    if q[-2:] == ['S', 'T']:
        q.pop()
        q.pop()
print len(q)

Submission status: Accepted

Solution code:
S = input()
A = []
for c in S:
  A.append(c)
  while len(A) >= 2 and A[-2] == 'S' and A[-1] == 'T':
    A[-2:] = []
print(len(A))

Submission status: Accepted

Solution code:
X = input()
ans = 0

for c in X:
    if c == 'S':
        ans += 1
    if c == 'T' and ans > 0:
        ans -= 1
print(ans * 2)

Submission status: Accepted

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

x = input()
n = len(x)

s, t = 0, 0
cnt = 0
for i in range(n):
    if x[i] == 'T':
        if s > 0:
            s -= 1
            cnt += 2
    elif x[i] == 'S':
        s += 1

# 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: Accepted

Solution code:
S=list(str(input()))
ans=[]
for i in S:
    if i=='S':
        ans.append(i)
    elif i=='T' and len(ans)==0:
        ans.append(i)
    elif i=='T' and ans[-1]=='T':
        ans.append(i)
    elif i=='T' and ans[-1]=='S':
        del ans[-1]
print(len(ans))

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().strip()

have = 0
ret = 0
for v in s:
    if v == 'S':
        have += 1
    elif have:
        have -= 1
    else:
        ret += 1
print ret * 2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X= input()

T_count=X.count("T")
S_count=X.count("S")
T_removed=0
i=0
ans=0
while i<len(X):
    if X[i]=="T":
        if T_removed>0:
            T_removed -=1
        else:
            T_count -= 1
            ans+=1
    elif X[i]=="S":
        if T_count:
            T_count-=1
            T_removed+=1
        else:
            ans+=1
    i+=1
print(ans)

Submission status: Accepted

Solution code:
s = raw_input()
c = len(s)
l = 0
was_es = True
for i in xrange(len(s)):
    if s[i] == "S":
        if was_es == True:
            l += 1
        was_es = True
    else:
        if l > 0:
            l -= 1
            c -= 2
print c

Submission status: Accepted

Solution code:
s = input()

ans = 0
for c in s:
    if c == 'S':
        ans += 1
    if c == 'T' and ans > 0:
        ans -= 1
print(ans*2)

Submission status: Accepted

Solution code:
x = raw_input()

y = []
for i in x:
    if len(y) == 0:
        y.append(i)
    elif i == 'S':
        y.append(i)
    elif i == 'T' and y[-1] == 'T':
        y.append(i)
    else:
        y.pop()

print len(y)

Submission status: Accepted

Solution code:
mystr = raw_input()
s_count = 0
t_count = 0
pairs = 0
for x in mystr:
    if x == "S":
        s_count += 1
    else:
        if (t_count < s_count):
            pairs += 1
            t_count +=1
print len(mystr)-2*pairs

Submission status: Accepted

Solution code:
string = input()
stack = ""

for i in string:
    if i == "S":
        stack += i
    elif i == "T" and (stack == "" or stack[-1] == "T"):
        stack += i
    else:
        stack = stack[0:-1]

print(len(stack))

Submission status: Accepted

Solution code:
string = input()
stack = []
for s in string:
    if stack and  stack[-1] == "S" and s == "T":
        stack.pop()
    else:
        stack.append(s)
print(len("".join(stack)))

Submission status: Accepted

Solution code:
string = input()
stack = []
for s in string:
    if s == "T" and stack and stack[-1] == "S":
        stack.pop()
    else:
        stack.append(s)
print(len("".join(stack)))

Submission status: Accepted

Solution code:
s = input()

a=[]
for i in range(len(s)):
 if s[i]=="S":
     a.append("S")
 if s[i]=="T":
     if len(a)==0 or a[-1]=="T":
         a.append("T")
     if a[-1]=="S":
         a.pop()
print (len(a))

Submission status: Accepted

Solution code:
# cook your code here
from sys import stdin
a = stdin.readline().strip()
l = len(a)
s = 0
t = 0
i = l-1
while i>=0:
    if a[i]=='T':
        t+=1 
    else:
        if t>0:
            t-=1 
        else:
            s+=1
    i-=1 
print s+t

Submission status: Accepted

Solution code:
X = input()
nS = 0
ret = len(X)
for c in X:
    if c == 'S':
        nS += 1
    elif c == 'T':
        if nS > 0:
            nS -= 1
            ret -= 2
print(ret)

Submission status: Accepted

Solution code:
#AGC005A

s=raw_input()
res=0
for c in s:
 if c=='S':
  res+=1
 elif c=='T' and res>0:
  res-=1
print res*2

Submission status: Accepted

Solution code:
s = input()

stack = []

for i in s:
    if i == 'S':
        stack.append(i)
    if i == 'T':
        if not stack:
            stack.append(i)
            continue
        last = stack.pop()
        if last == 'S':
            continue
        else:
            stack.append(last)
            stack.append(i)

print(len(stack))

Submission status: Accepted

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

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

def main():
    x = input()
    s = []
    for c in x:
    	if len(s) == 0:
    		s.append(c)
    	elif c == 'T' and s[-1] == 'S':
    		s.pop()
    	else:
    		s.append(c)
    print(len(s))
 
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = raw_input()
cnt = 0
ans = 0
for x in X:
    if x is 'S':
        cnt += 1
    else:
        if not cnt:
            ans += 1
        else:
            cnt -= 1
print ans*2

Submission status: Accepted

Solution code:
def main():
    s = input()
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Submission status: Accepted

Solution code:
def main():
    s = input().replace('ST', '')
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = ''.join(input().split('ST'))
cnts = 0
cnt = 0
for i in s:
    if i == 'S' :
        cnts += 1
    elif cnts > 0:
        cnts -= 1
        cnt += 1
print(len(s)-cnt*2)

Submission status: Accepted

Solution code:
s = ''.join(input().split('ST'))
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: Accepted

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
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

Submission status: Accepted

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

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

Submission status: Accepted

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)
X.reverse()
st.append(X[-1])
X.pop()
#for i in range(len(X)-2):
for i in range(N-1):
    st.append(X[-1])
    X.pop()
    if len(st) >= 2:
        if st[-1] == 'T' and st[-2] == 'S':
            st.pop()
            st.pop()
print len(st)

Submission status: Accepted

Solution code:
X = raw_input()
cnt = 0
cnt_max = cnt
L = len(X)

for i in range(L):
   if X[i] == 'T':
      cnt += 1
   else:
      cnt -= 1
      
   if cnt > cnt_max: 
      cnt_max = cnt

print cnt_max * 2