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()
s = []
for a in x:
    if len(s) == 0:
        s.append(a)
    else:
        t = s.pop()
        if t != 'S' or a != 'T':
            s.append(t)
            s.append(a)
print(len(s))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    x = S()
    s = 0
    ans = len(x)
    for i in x:
        if i == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ipt = raw_input()
l = ""
for s in ipt:
    if not l:
        l += s
    elif l[-1]+s == "ST":
        l = l[:-1]
    else:
        l += s
print len(l)

Submission status: Accepted

Solution code:
s = raw_input()
sn = 0
tn = 0
for i in s:
	if i == "S":
		sn += 1
	elif i == "T":
		tn += 1
		if sn > 0:
			sn -= 1
			tn -= 1
print sn + tn

Submission status: Accepted

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

s = raw_input()

s1 = []
for x in s:
	if not s1:
		s1.append(x)
		continue
	if x == 'T' and s1[-1] == 'S':
		# s1 = s1[:-1]
		del s1[-1]
	else:
		s1.append(x)

print len(s1)

Submission status: Accepted

Solution code:
s = raw_input()

head = 0
sub = 0

for i, v in enumerate(s):
    if v == 'S':
        head += 1

    if v == 'T' and head:
        head -= 1
        sub += 2

print(len(s) - sub)

Submission status: Accepted

Solution code:
X = list(input())

S_count = 0
ans = 0
for i in range(len(X)):
    if X[i] == 'S':
        S_count += 1
    else:
        if S_count:
            ans += 2
            S_count -= 1

print(len(X)-ans)

Submission status: Accepted

Solution code:
s = input()
t = []
cnt = 0
for a in s:
    t.append(a)
    cnt += 1
    if cnt >= 2:
        if t[-2] == 'S' and t[-1] == 'T':
            cnt -= 2
            for i in range(2):
                t.pop(-1)
print(cnt)

Submission status: Accepted

Solution code:
s = input()
t = []
for a in s:
    t.append(a)
    if len(t) >= 2:
        if t[-2] == 'S' and t[-1] == 'T':
            for i in range(2):
                t.pop(-1)
print(len(t))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
co = 0
su = 0
a = [n[0]]

for i in range(len(n)-1):
    if len(a) == 0:
        a.append(n[i+1])
    else:
        t = n[i+1]
        if t == "T":
            if a[-1] == "S":
                a.pop()
            else:
                a.append(t)
        else:
            a.append(t)
print(len(a))

Submission status: Accepted

Solution code:
from collections import deque

x = input()
q = deque(x[0])

for i in range(1, len(x)):
    if q:
        p = q.pop()
        if p == 'S' and x[i] == 'T':
            pass
        else:
            q.append(p)
            q.append(x[i])
    else:
        q.append(x[i])
print(len(q))

Submission status: Accepted

Solution code:
x = input()

ans = 0
cnt_s = 0
for xx in x:
    if xx == 'T':
        if cnt_s > 0:
            cnt_s -= 1
        else:
            ans += 2
    else:
        cnt_s += 1
print(ans)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
ans=N

stack=[]
stack.append(S[0])
for i in range(1,N):
  if len(stack)!=0 and stack[len(stack)-1]=='S' and S[i]=='T':
    ans-=2
    stack.pop()
  elif S[i]=='S':
    stack.append(S[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]

    stack = []

    for s in S:
        if len(stack) == 0:
            stack.append(s)
        else:
            if s == "T" and stack[len(stack) - 1] == "S":
                stack.pop()
            else:
                stack.append(s)
    print len(stack)


if __name__ == '__main__':
    main()

Submission status: Accepted

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[-1]]+X[r]=='ST'):
        ans+=2
        lt.pop()
        r+=1
        continue
    if(X[r]=='S'):
        lt.append(r)
        r+=1
    else:
        r+=1
        lt.clear()

print(len(X)-ans)

Submission status: Accepted

Solution code:
stack = 0
S = input()
ans = len(S)
for c in S:
    if c == "S":
        stack += 1
    elif stack != 0:
        stack -= 1
        ans -= 2
print(ans)

Submission status: Accepted

Solution code:
S = input()

result = ""
for s in S:
  if(s == "T" and result == ""):
    result += s
  elif(s == "T" and result[-1] == "S"):
    result = result[:-1]
  else:
    result += s
print(len(result))

Submission status: Accepted

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

if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

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

if __name__ == '__main__':
    s = input()
    print(solve(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()
Q = []
for i in range(len(X)):
    if X[i] == 'T':
        if len(Q) > 0 and Q[-1] == 'S':
            Q.pop()
        else:
            Q.append('T')
    else:
        Q.append('S')
print(len(Q))

Submission status: Accepted

Solution code:
from collections import deque
X = input()
Q = deque()
for i in range(len(X)):
    if X[i] == 'T':
        if len(Q) > 0 and Q[-1] == 'S':
            Q.pop()
        else:
            Q.append('T')
    else:
        Q.append('S')
print(len(Q))

Submission status: Accepted

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

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

print( N - 2 * ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    x=input()
    cnt=0
    ans=len(x)
    for i in range(len(x)):
        if(x[i]=='S'):
            cnt+=1
        else:
            if(cnt>0):
                cnt-=1
                ans-=2
    print(ans)
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
x=input()
s_cnt=0
t_cnt=0
for i in x:
    if i=="S":
        s_cnt+=1
    elif s_cnt>0:
        s_cnt-=1
    else:
        t_cnt+=1
print(s_cnt+t_cnt)

Submission status: Accepted

Solution code:
def solve():
  s =input()
  n =len(s)
  queue = 0
  ans = 0
  for i in range(n):
    if s[i] == 'S': queue+=1
    else: 
      if queue >0:
        queue -= 1
        ans += 2
  return (n-ans)  
  
  
if __name__ == '__main__':
  print(solve())

Submission status: Accepted

Solution code:
s = input()
lisS = []
lisT = []
for i in range(len(s)):
  if s[i] == 'S':
    lisS.append(i)
  else:
    lisT.append(i)
ans = 0
cnt = 0
cs = 0
ct = 0
while cnt < len(s)//2:
  if lisS[cs] < lisT[ct]:
    cs += 1
    ct += 1
    ans += 2
  else:
    ct += 1
  cnt += 1
print(len(s)-ans)

Submission status: Accepted

Solution code:
S = input()

s = 0
t = 0
res = len(S)
stack = [S[0]]
for i in range(1, len(S)):
    if stack != []:
        if stack[-1] == 'S' and S[i] == 'T':
            stack.pop()
        else:
            stack.append(S[i])
    else:
        stack.append(S[i])

print(len(stack))

Submission status: Accepted

Solution code:
ans=0
stack=[]
for s in input():
    if len(stack)>0 and s=="T":
        if stack[-1]=="S":
            del stack[-1]
        else:
            stack.append(s)
    else:
        stack.append(s)
print(len(stack))

Submission status: Accepted

Solution code:
x = input()

st_10_2 = "S" * 10 * 10 + "T" * 10 * 10
st_10_3 = "S" * 10 * 10 * 10 + "T" * 10 * 10 * 10

while True:
    x = x.replace(st_10_3,"").replace(st_10_2,"").replace("ST","")
    if "ST" not in x:
        break

print(len(x))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ruiseki = [0]*(n+1)

for i in range(n):
  if s[i]=="S":
    ruiseki[i+1] = ruiseki[i]-1
  else:
    ruiseki[i+1] = ruiseki[i]+1
print(max(ruiseki)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
xx = input()

remove = 0
s_num=0
for x in xx:
    if x=='S':
        s_num += 1
    else:
        if s_num>0:
            remove += 1
            s_num -= 1
print(len(xx) - 2 * remove)

Submission status: Accepted

Solution code:
X = input()
st = []
for s in X:
    if s == 'S': st.append(s)
    if s == 'T':
        if (not st) or st[-1] == 'T': st.append(s)
        if st[-1] == 'S': st.pop()
print(len(st))

Submission status: Accepted

Solution code:
x=input()
y=[0]
z=[]
for t in x:
    if t=="S":
        y.append(t)
    elif y[-1]=="S":
        del y[-1]
    else:
        z.append(t)
print(len(y)+len(z)-1)

Submission status: Accepted

Solution code:
s = input()

stack = []
for c in s:
    if c == 'S':
        stack.append(c)
    else:
        if not stack:
            stack.append(c)
        elif stack[-1] == 'T':
            stack.append(c)
        else:
            stack.pop()

print(len(stack))
# print(*stack, sep='')

Submission status: Accepted

Solution code:
s = input()

ans = 0
cnt = 0
for c in s:
    if c == 'S':
        cnt += 1
    else:
        if cnt:
            ans += 1
            cnt -= 1

print(len(s) - 2 * ans)

Submission status: Accepted

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

x = input()

# ペアになっていない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: Accepted

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

Submission status: Accepted

Solution code:
a = input()
s,t = 0,0
for i in a:
    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, t = 0, 0
for x in X:
    if x == "S":
        s += 1
    else:
        if s == 0:
            t += 1
        else:
            s -= 1

print(s+t)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

scnt = 0
dlt = 0

for si in s:
    if si == 'S':
        scnt += 1
        
    if scnt > 0 and si == 'T':
        scnt -= 1
        dlt += 2
        
print(len(s)-dlt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input
X = input()

ss = []
ans = len(X)

for c in X:
    if ss == []:
        if c == 'T':
            continue
        else:
            ss.append(c)
    else:
        if c == 'T':
            ans -= 2
            ss.pop()
        else:
            ss.append(c)

print(ans)

Submission status: Accepted

Solution code:
x = input()

count = 0
s = 0
t = 0

for w in x:
    if w == "T":
        if s > 0:
            s -= 1
            count += 1
    else:
        s += 1

print(len(x)-count*2)

Submission status: Accepted

Solution code:
x = input()

count = 0
s = 0
t = 0

for w in x:
    if w == "T":
        if s > 0:
            s -= 1
            count += 1
    else:
        s += 1

print(len(x)-count*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
SSS = 0
len = 0
for c in s:
    if c == 'S':
        SSS += 1
        len += 1
    elif SSS == 0:
        len += 1
    else:
        SSS -= 1
        len -= 1
    # print(len)
print(len)

Submission status: Accepted

Solution code:
def solve(X):
    ans = 0
    count = 0
    for c in X:
        if c == "S":
            count += 1
        else:
            if count > 0:
                count -= 1
            else:
                ans += 1
    ans += count
    return ans

if __name__ == "__main__":
    X = input()
    print(solve(X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c=0
for x in input():c+=x=='S'or-(c>0)
print(2*c)

Submission status: Accepted

Solution code:
c=0
for x in input():c+=x=='S'or(c>0)*-1
print(2*c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

stack = collections.deque()

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

Submission status: Accepted

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

sum_s = 0
ans = 0
for i in range(N):
    if X[i] == 'S':
        sum_s += 1
    elif X[i] == 'T':
        if sum_s > 0:
            sum_s -= 1
        else:
            ans += 1

print(ans+sum_s)

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X = input()
N = len(X)

cnt = 0
s = 0
for i in range(N):
    if X[i] == 'S':
        s += 1
        cnt += 1
    elif X[i] == 'T':
        if s != 0:
            s -= 1
            cnt -= 1
        else:
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
s = 0
r=0
for i in a:
    if i == "S":
        s+=1
    if i == "T" and s > 0:
        s-=1
        r+=1
print(len(a)-2*r)

Submission status: Accepted

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(len(txt_stuck))

Submission status: Accepted

Solution code:
S_count = 0

for item in input():
    if item == 'S':
        S_count += 1
    elif item == 'T' and S_count > 0:
        S_count -= 1

print(2 * S_count)

Submission status: Accepted

Solution code:
X = input()

S_count = 0
T_count = 0
for item in X:
    if item == 'S':
        S_count += 1
    elif item == 'T' and S_count > 0:
        S_count -= 1


print(2 * S_count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#
# A - STring
#
# input
x = list(input())
n = 0
# calc
for i in range(len(x)):
  if x[i] == 'S':
    n += 1
  elif n>0:
    n -= 1
# output
print(n*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

tmp = []
ans = 0

for i in range(len(S)):
    if S[i] == 'S':
        tmp.append(S[i])
        ans = ans + 1
    else:
        if ans == 0:
            tmp.append(S[i])
            ans = ans + 1
        elif tmp[ans-1] == 'T':
            tmp.append(S[i])
            ans = ans + 1
        else:
            tmp.pop(ans-1)
            ans = ans-1
            
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X=input()

cntS=0
SUM=0
for i in range(len(X)):
    if X[i]=="T":
        if cntS>0:
            cntS-=1
        else:
            SUM+=1
    if X[i]=="S":
        cntS+=1
print(SUM*2)

Submission status: Accepted

Solution code:
V = str(input())
k = []
for i in V:
    if i == "S":
        k.append("S")
    elif k.__len__() == 0 or k[-1] == "T":
        k.append("T")
    else:
        k.pop()
print(len(k))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_x = input()
x = []
for i in _x:
    x.append(i)
count = 0

# 今まで確認してきたものはスタックに入れる
# スタックの頂上がSで次の入力がTならスタックをポップ
stack = []
i = 0
while i < len(x):
    if len(stack) > 0 and stack[-1] == "S" and x[i] == "T":
        del stack[-1]
    else:
        stack.append(x[i])
    i += 1
print(len(stack))
# print(stack)

Submission status: Accepted

Solution code:
X = input()
ans = ''
for i in range(len(X)):
    ans += X[i]
    if ans[-2:] == 'ST':
        ans = ans[:-2]
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = []
for i in s:
  a.append(i)
  if len(a) >= 2 and a[-1] == "T" and a[-2] == "S":
    a.pop()
    a.pop()
print(len(a))

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

Solution code:
x = list(input())
n = len(x)

a = 0
c = 0
for i in range(n):
    if x[n-1-i] == 'S':
        if a >= 1:
            a -=1
            c += 1
    else:
        a += 1

print(n-c*2)

Submission status: Accepted

Solution code:
X = input()
ctr = 0
ans = 0
for i in X:
    if i == 'T':
        if ctr > 0:
            ctr -= 1
        else: 
            ans += 1
    else:
        ctr += 1
print(2*ans)

Submission status: Accepted

Solution code:
S=input()
t=0
u=0
for v in S:
    if v=="S":
        t+=1
    else:
        if t>=1:
            u+=2
            t-=1
print(len(S)-u)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x = input()
n = len(x)
r = 0
cnt = 0
for i in range(n):
    if x[i]=="S":
        cnt += 1
    else:
        if cnt>0:
            r += 2
            cnt -= 1

print(n-r)

Submission status: Accepted

Solution code:
X=input().strip()
N=len(X)
sl=0
tl=0
sp=0
for i in range(N-1,-1,-1):
    if X[i]=='S':
        if tl==0:
            sl+=1
        else:
            tl-=1
    else:
        tl+=1
print(sl+tl)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
cnt = 0
pair = 0
for c in s:
  if c == 'T':
    if cnt > 0:
      cnt -= 1
      pair += 1
  else:
    cnt += 1
print(N-2*pair)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X=input()
L = len(X)
ans = L
stack = 0
for i in range(L):
  if X[i] == "T" and stack:
    ans -= 2
    stack -= 1    
  if X[i] == "S":
    stack += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()

x_length = len(X)
stack = []

for i in range(x_length):
    x = X[i]
    if x == "S":
        stack.append(x)

    elif x == "T" and stack and stack[-1] == "S":
        stack.pop()

    else:
        stack.append(x)
print(len(stack))

Submission status: Accepted

Solution code:
import sys


def main() -> None:
    x = input()
    s_cnt = 0
    ans = 0

    for v in x:
        if v == 'S':
            s_cnt += 1
        if v == 'T':
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1

    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main() -> None:
    x = next_str()
    s_cnt = 0
    ans = 0

    for v in x:
        if v == 'S':
            s_cnt += 1
        if v == 'T':
            if s_cnt == 0:
                ans += 1
            else:
                s_cnt -= 1

    ans += s_cnt
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

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)

Submission status: Accepted

Solution code:
X = list(input())

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

	if c >= ans:
		ans = c

print(ans * 2)

Submission status: Accepted

Solution code:
x=input()
s=0;t=0
for i in range(len(x)):
  if x[i]=='S':s+=1
  elif s==0:t+=1
  else:s-=1
print(s+t)

Submission status: Accepted

Solution code:
Xs = input()

ans = len(Xs)
numS = 0
for X in Xs:
    if X == 'S':
        numS += 1
    else:
        if numS > 0:
            ans -= 2
            numS -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = str(input())
list_x = list(x)
n = 0
for i in range(len(x)):
    if list_x[i] == "S":
        n += 1
    else:
        if n > 0:
            n -= 1
        else:
            pass
print(2*n)

Submission status: Accepted

Solution code:
S = input()

S_c, T_c = 0, 0

# TSTTSS -> 4
ans = 0
for ch in S:
  if ch == "T" and S_c > 0:
    S_c -= 1
  elif ch == "T" and S_c == 0:
    ans += 2
  else:
    S_c += 1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

stack = []
for s in S:

    if s == 'S':
        stack.append(s)
    elif s == 'T' and len(stack) == 0 or stack[-1] == 'T':
        stack.append(s)
    elif s == 'T' and stack[-1] == 'S':
        stack.pop()

print(len(stack))

# #部分点
# while 'ST' in S:
#     num = S.count('ST')
#     S = S.replace('ST','',num)

#print(len(S))

Submission status: Accepted

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