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() #sys.stdin.readlineは最後が改行
n = len(x)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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


def resolve1():
    x = input()

    cnt_S = 0
    cnt_T = 0
    res = 0
    i = 0
    while i < len(x):
        if x[i] == "S":
            cnt_S += 1
            i += 1

        elif x[i] == "T" and cnt_S != 0:
            while i < len(x) and x[i] == "T":
                cnt_T += 1
                i += 1
            res += min(cnt_S, cnt_T) * 2
            cnt_S -= min(cnt_S, cnt_T)
            cnt_T = 0
        else:
            i += 1

    print(len(x) - res)


def resolve2():
    x = input()
    n = len(x)

    stack = 0
    res = 0
    for i in range(n):
        if x[i] == "S":
            stack += 1
        elif stack > 0:
            stack -= 1
            res += 1

    print(n - res * 2)


if __name__ == '__main__':
    resolve2()

Submission status: Accepted

Solution code:
import sys

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


def resolve():
    x = input()

    cnt_S = 0
    cnt_T = 0
    res = 0
    i = 0
    while i < len(x):
        if x[i] == "S":
            cnt_S += 1
            i += 1

        elif x[i] == "T" and cnt_S != 0:
            while i < len(x) and x[i] == "T":
                cnt_T += 1
                i += 1
            res += min(cnt_S, cnt_T) * 2
            cnt_S -= min(cnt_S, cnt_T)
            cnt_T = 0
        else:
            i += 1

    print(len(x) - res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X = rl().rstrip()
    
    ans = len(X)
    cnt_s = 0
    for xi in X:
        if xi == 'S':
            cnt_s += 1
        elif xi == 'T' and cnt_s:
            ans -= 2
            cnt_s -= 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main():
    N = input().strip()
    stack = []
    for s in N:
        if len(stack)==0:
            stack.append(s)
        elif stack[-1]=="S" and s=="T":
            stack.pop()
        else:
            stack.append(s)
    print(len(stack))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
snum = 0
ans = 0
for i in s:
    if(i=='S'):
        snum+=1
    elif(snum>=1 and i=='T'):
        snum -=1
        ans +=1
print(len(s)-2*ans)

Submission status: Accepted

Solution code:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = read().rstrip().decode()[::-1]
p = 0
m = 0
for xx in x:
    if xx == 'S' and m != 0:
        m -= 1
        p += 1
    if xx == 'T':
        m += 1
print(len(x) - 2 * p)

Submission status: Accepted

Solution code:
from bisect import bisect_left
x=input()
s,t=[],[]
n=len(x)
for i in range(n):
    if x[i]=="S":
        s.append(i)
    else:
        t.append(i)
ans,cnt=0,0
#print(t)
for idx in t:
    if bisect_left(s,idx)-cnt>0:
        ans+=1
        cnt+=1
print(n-2*ans)

Submission status: Accepted

Solution code:
#import re
x=input()
ans=0
ns=0
nt=0
for i in range(len(x)):
  if x[i]=='S':
    ns+=1
  elif ns>0 and x[i]=='T':
    ns-=1
  else:
    ans+=1
print(ans+ns)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    X = input().strip()
    stack = list()
    for s in X:
        if s == "S" or len(stack) < 1:
            stack.append(s)
        elif s == "T" and stack[-1] == "T":
            stack.append(s)
        else:
            stack.pop()
    return len(stack)


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
s=input()
d=[]

for i in s:
    if i=="S":
        d.append("S")
    elif i=="T" and (not d or d[-1]=="T"):
        d.append("T")
    else:
        d.pop()
print(len(d))

Submission status: Accepted

Solution code:
from collections import deque
s=input()
d=deque()

for i in s:
    if i=="S":
        d.append("S")
    elif i=="T" and (not d or d[-1]=="T"):
        d.append("T")
    else:
        d.pop()
print(len(d))

Submission status: Accepted

Solution code:
s=input()
n,ans,l=len(s),len(s),0
for c in s:
	if c=='S':
		l += 1
	elif l:
		l -= 1
		ans -= 2
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

X = input()
n = len(X) # even

stack = deque([])

for char in X:
	if char == 'S':
		stack.append(char)
	elif char == 'T' and len(stack) == 0:
		stack.append('T')
	elif char == 'T' and stack[-1] == 'S':
		stack.pop()
	elif char == 'T' and stack[-1] == 'T':
		stack.append('T')

print(len(stack))

Submission status: Accepted

Solution code:
from collections import deque
s=input()

A=deque([])
for i in s:
    if len(A)<1:
        A.append(i)
    else:
        if A[-1]+i=="ST":A.pop()
        else:A.append(i)

print(len(A))

Submission status: Accepted

Solution code:
X = input()

left_S = 0
left_T = 0

for i in range(len(X)):
    if X[i] == "S":
        left_S += 1
    elif left_S == 0:
        left_T += 1
    else:
        left_S -= 1

print(left_S + left_T)

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

x = ins()
s = []
for c in x:
  s.append(c)
  while len(s)>1 and s[-2]=='S' and s[-1]=='T':
    s.pop()
    s.pop()
print(len(s))

Submission status: Accepted

Solution code:
from itertools import groupby as gb
l=[(a,len(list(b))) for a,b in gb(list(input()))]
ans=0
now=0
if l[0][0]=="T":
    ans+=l[0][1]
    now+=1
pres=0
for (k,x),(k1,y) in zip(l[now::2],l[now+1::2]):
    #print(ans,pres)
    if x+pres>=y:pres=(x+pres-y)
    else:
        ans+=y-x-pres
        pres=0
print(ans+pres+(0 if l[-1][0]=="T" else l[-1][1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()
p = X[0]
ls = []
cnt = 1
for c in X[1:]:
  if p!=c:
    ls.append(cnt)
    cnt = 1
    p = c
  else:
    cnt += 1
ls.append(cnt)
s = 0
t = 0
m = 0
if X[0]=='S':
  for i in range(len(ls)):
    if i%2==0:
      s += ls[i]
    else:
      t += ls[i]
    if s<t:
      m += t-s
      t = 0
      s = 0
  print(2*m)
else:
  for i in range(len(ls)):
    if i%2==0:
      t += ls[i]
    else:
      s += ls[i]
    if s<t:
      m += t-s
      t = 0
      s = 0
  print(2*m)

Submission status: Accepted

Solution code:
s=input()

s=list(s)

ans = ['G']

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc005/tasks/agc005_a
#
# Stackでやる

from collections import deque

stack = deque([])
X = input()

for ch in X:
    if ch == 'S':
        stack.append(ch)
    elif ch == 'T':
        if len(stack) == 0:
            stack.append(ch)
        elif stack[-1] == 'T':
            stack.append(ch)
        elif stack[-1] == 'S':
            stack.pop()

print(len(stack))

Submission status: Accepted

Solution code:
s = input()
s_cnt = puyo = 0
for si in s:
    if si == "S": s_cnt += 1
    elif s_cnt > 0:
        s_cnt -= 1
        puyo += 1
print(len(s) - puyo * 2)

Submission status: Accepted

Solution code:
from collections import deque
x = input()
n = len(x)
st = deque()

for i in range(n):
    if x[i] == "S":
        st.append("S")
    else:
        if st == deque([]):
            st.append("T")
        else:
            a = st.pop()
            if a == "T":
                st.append("T")
                st.append("T")
            else:
                continue
                
print(len(st))

Submission status: Accepted

Solution code:
def agc005_a():
  x = str(input())
  s_accum = [0]
  t_accum = [0]
  t_up = 0
  for ch in x:
    # SとTの出現回数の累積和
    if ch == 'S':
      s_accum.append(s_accum[-1] + 1)
      t_accum.append(t_accum[-1])
    else:
      s_accum.append(s_accum[-1])
      t_accum.append(t_accum[-1] + 1)
    # Tの左側にいるSとの差分が、残るTの数で、プラスの値ならTが先頭に残る
    if ch == 'T':
      t_up = max(t_up, t_accum[-1] - s_accum[-1])
  ans = 2 * t_up
  print(ans)

agc005_a()

Submission status: Accepted

Solution code:
from itertools import groupby
import heapq

X=input()
N=len(X)
X=[X[i] for i in range(0,N)]
X=groupby(X)
data=[]
i=0
for key,group in X:
    g=len(list(group))
    data.append((i,key,g))
    i+=1

if data[0][1]=='T':
    data=data[1:]
if data[-1][1]=='S':
    data=data[:len(data)-1]


heapq.heapify(data)
left=0
ans=0
while data:
    S=heapq.heappop(data)
    T=heapq.heappop(data)
    s=S[2]+left
    t=T[2]
    if s>=t:
        left=s-t
        ans+=t
    else:
        left=0
        ans+=s

print(N-2*ans)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    X = input()

    que = queue.LifoQueue()
    cnt = 0
    rest_T = 0
    for x in X:
        if x == 'S':
            que.put(x)
            cnt += 1
        elif x == 'T' and cnt > 0:
            _ = que.get()
            cnt -= 1
        else:
            rest_T += 1

    print(rest_T + cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = 0
for i in input():
  k += i=="S" or -(k>0)
print(k*2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc005/tasks/agc005_a

S = input()
ret = len(S)
stack = []
for s in S:
    if s == 'S':
        stack.append(S)
    if s == 'T' and stack:
        stack.pop()
        ret -= 2

print(ret)

Submission status: Accepted

Solution code:
from collections import deque
X = input()

scan = deque()

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

Submission status: Accepted

Solution code:
from collections import deque
X = input()

scan = deque()

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

Submission status: Accepted

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

right = 1
cnt = 0

for left in range(N - 1):
    if X[left] == 'S':
        right = max(right, left + 1)
        while right < N and X[right] != 'T':
            right += 1
        if right >= N:
            break
        if X[right] == 'T':
            # print(left, right)
            right += 1
            cnt += 1
print(N - cnt * 2)

Submission status: Accepted

Solution code:
s=input()
cnt,ans=0,len(s)
for ss in s:
  if ss=="S":
    cnt+=1
  else:
    if cnt>0:
        cnt-=1
        ans-=2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    cnt = 0
    ans = len(S)
    for s in S:
        if s == 'S':
            cnt += 1
        elif s == 'T':
            if cnt:
                cnt -= 1
                ans -= 2
        else:
            cnt = 0
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = str(input())
ans = 0
s_ctr = 0
# s の後の t をひたすら省く
for i in range(len(S)):
    if S[i] == "S":
        s_ctr += 1
    else:
        if s_ctr > 0:
            ans += 1
            s_ctr -= 1
print(len(S) - ans * 2)

Submission status: Accepted

Solution code:
s=0
for x in input():s+=x<'T'or-(s>0)
print(2*s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = list(input())
nt, ns = 0, 0
for x in X:
    if x == 'S':
        ns += 1
    elif ns > 0:
        ns -= 1
    else:
        nt += 1
print(nt+ns)

Submission status: Accepted

Solution code:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Submission status: Accepted

Solution code:
X=input()

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

Submission status: Accepted

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_cnt = 0
for m in S:
    if m == 'S':
        s_cnt += 1
    elif m == 'T' and s_cnt > 0:
        s_cnt -= 1

print(2 * s_cnt)
'''
from collections import deque
ans = deque()
for m in S:
    if m == 'S':
        ans.append(m)
    elif m == 'T':
        if ans and ans[-1] == 'S':
            ans.pop()
        else:
            ans.append(m)
print(len(ans))

Submission status: Accepted

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_cnt = 0
for m in S:
    if m == 'S':
        s_cnt += 1
    elif m == 'T' and s_cnt > 0:
        s_cnt -= 1

print(2 * s_cnt)
'''
ans = []
for m in S:
    if m == 'S':
        ans.append(m)
    elif m == 'T':
        if ans and ans[-1] == 'S':
            ans.pop(-1)
        else:
            ans.append(m)
print(len(ans))

Submission status: Accepted

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()
'''
f_cnt = b_cnt = 0
for m in S:
    if m != 'T':
        break
    f_cnt += 1

for m in S[::-1]:
    if m != 'S':
        break
    b_cnt += 1
print(max(f_cnt, b_cnt) * 2)
'''
s_cnt = 0
for m in S:
    if m == 'S':
        s_cnt += 1
    elif m == 'T' and s_cnt > 0:
        s_cnt -= 1

print(2*s_cnt)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    answer = len(X)
    cnt_s = 0
    for x in X:
        if x == "S":
            cnt_s += 1
            continue
        if cnt_s > 0:
            cnt_s -= 1
            answer -= 2
            
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    answer = 0
    cnt_s = 0
    for x in X:
        if x == "S":
            cnt_s += 1
            continue
        if cnt_s > 0:
            cnt_s -= 1
        else:
            answer += 1
    answer += cnt_s
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt_s = 0
ans = N
for i in range(N):
    if X[i] == "S":
        cnt_s += 1
    else:
        if cnt_s > 0:
            ans -= 2
            cnt_s -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()
def solve(X):
    ns = 0
    nt = 0
    for x in X:
        if x == 'S':
            ns += 1
        elif ns>0:
            ns -= 1
        else:
            nt += 1
    return ns+nt
print(solve(X))

Submission status: Accepted

Solution code:
X = input()
s_cnt, t_cnt = 0, 0
for i in range(len(X)):
  if X[i] == "S":
    s_cnt += 1
  elif s_cnt != 0:
    s_cnt -= 1
    t_cnt += 1
print(len(X) - 2*t_cnt)

Submission status: Accepted

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'):
            if(restS[-2] == 'S' and restS[-1] == 'T'): # Higher Speed than join ?
                #print("hit restS[-2] = {}, restS[-1] = {}".format(restS[-2], restS[-1]))
                #restS = restS[:-2] # TLE
                del restS[-2:]
                #print("new restS = {}".format(restS))
            else:
                #print("no hit restS = {}".format(restS))
                break # out of while

print(len(restS))

Submission status: Accepted

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] # TLE
                del restS[-2:]
                #print("new restS = {}".format(restS))
            else:
                #print("no hit")
                break # out of while

print(len(restS))

Submission status: Accepted

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

    s = 0
    count = 0
    for cur in x:
        if cur == "S":
            s += 1
        else:
            if s != 0:
                s -= 1
            else:
                count += 2

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X=input()
stack=[]
point=0
for i in range(len(X)):
    if X[i]=="S":
        stack.append(X[i])
        point+=1
    else:
        if point==0:
            stack.append(X[i])
            point+=1
        elif stack[point-1]=="T":
            stack.append(X[i])
            point+=1
        elif stack[point-1]=="S":
            del stack[point-1]
            point-=1
print(len(stack))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

s = input()
n = len(s)
que = deque()
for i in range(n):
    if s[i] == 'S':
        que.append(s[i])
    else:
        if len(que) == 0:
            que.append(s[i])
        elif que[-1] == 'T':
            que.append(s[i])
        else:
            que.pop()
    
print(len(que))

Submission status: Accepted

Solution code:
s = input()[::-1]
n = len(s)
tmp = 0
ans = 0
for i in range(n):
    if s[i] == 'S':
        tmp += 1
    else:
        tmp -= 1
    ans = max(ans, tmp)

print(ans * 2)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    x = list(input())
    sl = []
    ans = 0
    for i in x:
        if i == "S":
            sl.append(1)
        else:
            if len(sl) != 0:
                ans += sl.pop()

    print(len(x) - ans * 2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc005/tasks/agc005_a

# 'ST'を抜け。
# 文字列を連長圧縮、先頭は必ずSを、最後には必ずTになるようにする(0個を許容)
# そしたらSTSTSTSTの文字数なので二個ずつabs(n_s-n_t)を取っていけばよい。ただしTが先になくなるときは、Sの余りを次のSに移し替えなければ行けない
# とかいろいろ考えたけどおとなしくstackで実装
# ここでは何文字STができたかを数える


X = input()

# おとなしくstackで実装し直す
stack = []
n_poped = 0
for x in X:
    if x == 'S':
        stack.append(1)
    elif x == 'T':
        if stack:
            stack.pop()
            n_poped += 2

print(len(X) - n_poped)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=input()
l=len(x)
ans=0
q=[]
for i in range(l):
    if x[i]=='S':
        q.append(x[i])
    else:
        if not q or q[-1]=='T':
            q.append(x[i])
        else:
            q.pop()
            ans+=1
print(l-ans*2)

Submission status: Accepted

Solution code:
x=input()
l=len(x)
c=0
ans=0
for i in range(l):
    if x[i]=='S':
        c+=1
    else:
        if c>0:
            ans+=1
        c-=1
    if c<0:
        c+=1
print(l-ans*2)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    x = input()

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

    print(ans)

Submission status: Accepted

Solution code:
x = list(input())
s, t = 0, 0
ans = 0
for i in range(len(x)):
    if x[i] == "T":
        t += 1
        if s > 0:
            s -= 1
            t -= 1
    else:
        s += 1
print(s + t)

Submission status: Accepted

Solution code:
X = input()
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))

Submission status: Accepted

Solution code:

X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))

Submission status: Accepted

Solution code:
def resolve():
    X = input()
    stack = []
    for s in X:
        if not stack:
            stack.append(s)
            continue
        if s == 'T' and stack[-1] == 'S':
            stack.pop()
        else:
            stack.append(s)
    print(len(stack))

resolve()

Submission status: Accepted

Solution code:
X = input()
s, t = 0, 0
for i in X:
    if i=='S':
        s += 1
    else:
        if s==0:
            t += 1
        else:
            s-= 1
print(s+t)

Submission status: Accepted

Solution code:
X = input()
s_count = 0
ans = 0
for i in X:
    if i == 'S':
        s_count += 1
    elif s_count > 0:
        s_count -= 1
        ans += 2
print(len(X)-ans)

Submission status: Accepted

Solution code:
from collections import deque


def main():
    word = input()
    stack = deque()
    for w in word:
        if w == "S":
            stack.appendleft(w)
        elif w == "T" and (len(stack) == 0 or stack[0] == "T"):
            stack.appendleft(w)
        else:
            stack.popleft()
    print(len(stack))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()
"""
Tの前にSがどれだけあるか？
TSSTTTSS
"""
s_cnt = 0
t_cnt = 0
cnt = 0
for s in X:
    if s == "S":
        s_cnt += 1
    if s == "T":
        t_cnt += 1
        if t_cnt <= s_cnt:
            cnt += 2
        else:
            s_cnt = 0
            t_cnt = 0


print(len(X) - cnt)

Submission status: Accepted

Solution code:
X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input()

t = 0
s = 0

for i in x:
    if i == 'S':
        t += 1
    else:
        if t > 0:
            t -= 1
        else:
            s += 1

print(s+t)

Submission status: Accepted

Solution code:
x = list(input())
s_cnt = [0] * (len(x)+1)

lost_pair = 0

for i in range(1, len(x)+1):
    if x[i-1] == 'S':
        s_cnt[i] = s_cnt[i-1] + 1
    else:
        if s_cnt[i-1] > 0:
            s_cnt[i] = s_cnt[i-1] - 1
            lost_pair += 1

print(len(x) - 2*lost_pair)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = input()

num_s = 0
num_t = 0

ans = 0
for x in X:
	if x == "T" and num_s:
		ans += 1
		num_s -= 1
	if x == "S":
		num_s += 1
print(len(X)-2*ans)

Submission status: Accepted

Solution code:
S = input()
cnt = []
c = S[0]
tmp = 0
for i in range(len(S)):
	if S[i] == c:
		tmp += 1
	else:
		cnt.append(tmp)
		c = S[i]
		tmp = 1
cnt.append(tmp)

cnt_S, cnt_T = 0,0
delete = 0
if S[0] != 'S':
	cnt.pop(0)
cnt_S = cnt[0]
for i in range(1,len(cnt),2):
	if cnt_S >= cnt[i]:
		cnt_S -= cnt[i]
		delete += cnt[i]*2
	else:
		delete += cnt_S*2
		cnt_S = 0

	if i+1 >= len(cnt):
		break

	cnt_S += cnt[i+1]

print(len(S)-delete)

Submission status: Accepted

Solution code:
X = input()
cnt = 0
res = 0
for i in X:
  if i == 'S':
    cnt += 1
  else:
    if cnt > 0:
      cnt -= 1
    else:
      res += 1
print(cnt + res)

Submission status: Accepted

Solution code:
x = input()

stack = ["X"]
for e in x:
    stack.append(e)
    if stack[-2] == "S" and stack[-1] == "T":
        stack.pop()
        stack.pop()

ans = len(stack) - 1
print(ans)

Submission status: Accepted

Solution code:
X = input()
Sn = 0
Tn = 0
for ch in X:
    if ch == "S":
        Sn += 1
    if ch == "T":
        if Sn > 0:
            Sn -= 1
        else:
            Tn += 1
print(Sn + Tn)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    X = input()

    LENX = len(X)

    T_count = 0
    answer = LENX
    for i in range(LENX-1,-1,-1):
        if X[i] == "T":
            T_count += 1
        else:
            if T_count > 0 :
                T_count -= 1
                answer -= 2
        
    print(answer)

    return

if __name__ == '__main__':
    main()