Problem:


Score : 300 points

Problem Statement

We have a string X, which has an even number of characters. Half the characters are S, and the other half are T.

Takahashi, who hates the string ST, will perform the following operation 10^{10000} times:

Among the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.

Find the eventual length of X.

Constraints

2 ≦ |X| ≦ 200,000

The length of X is even.

Half the characters in X are S, and the other half are T.

Partial Scores

In test cases worth 200 points, |X| ≦ 200.

Input

The input is given from Standard Input in the following format:

X

Output

Print the eventual length of X.

Sample Input 1

TSTTSS

Sample Output 1

4

In the 1-st operation, the 2-nd and 3-rd characters of TSTTSS are removed.
X becomes TTSS, and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.
Thus, the answer is 4.

Sample Input 2

SSTTST

Sample Output 2

0

X will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.

Sample Input 3

TSSTTTSS

Sample Output 3

4

X will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.



Sample input:
TSTTSS


Sample output:
4

Submission status: Wrong Answer

Solution code:
X=input()
ans = len(X)
def chk(X,a,b):
    if a<0 or b>len(X)-1:
        return 0
    if X[a]=="S" and X[b]=='T':
        return chk(X,a-1,b+1)+2
    else:
        return 0
for i in range(len(X)-1):
    ans -= chk(X,i,i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
X=input()
ans = len(X)
def chk(X,a,b):
    if X[a]=="S" and X[b]=='T':
        return chk(X,a-1,b+1)+2
    else:
        return 0
for i in range(len(X)-1):
    ans -= chk(X,i,i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

x = ns()
n = len(x)

ans = n
i = 0
while i < n:
    cs = 0
    ct = 0
    while i < n and x[i] == 'S':
        cs += 1
        i += 1
    while i < n and x[i] == 'T':
        ct += 1
        i += 1
    ans -= min(cs, ct) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
x=input()
ans=0
ind=x.find("ST")
while(ind!=-1):
    ans+=2
    s_ind=ind-1
    t_ind=ind+2
    while(0<=s_ind and t_ind<len(x) and x[s_ind]=="S" and x[t_ind]=="T"):
        ans+=2
        s_ind-=1
        t_ind+=1
    ind=x.find("ST",ind+1)
print(len(x)-ans)

Submission status: Wrong Answer

Solution code:
x=input()
ans=0
ind=x.find("ST")
while(ind!=-1):
    ans+=2
    s_ind=ind-1
    t_ind=ind+2
    if(0<=s_ind and t_ind<len(x) and x[s_ind]=="S" and x[t_ind]=="T"):
        ans+=2
        s_ind-=1
        t_ind+=1
    ind=x.find("ST",ind+1)
print(len(x)-ans)

Submission status: Wrong Answer

Solution code:
X = input()
current = None
s = 0
t = 0
ans = 0
for x in X:
    if x == 'S':
        if current != x:
            ans += min(s, t) * 2
            s = t = 0
        s += 1
    else:
        if current != x:
            t = 0
        t += 1
    current = x
ans += min(s, t) * 2
print(len(X) - ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x =  input()
ans = 0
for c in x:
    if c == 'T':
        ans += 1
    elif ans != 0:
        ans -= 1
print(ans * 2)

Submission status: Wrong Answer

Solution code:
def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

X=input()
RL=ranlength(X)
if X[0]=='T':
    RL.pop(0)
A=0
for i in range(len(RL)//2):
    A+=min(RL[2*i],RL[2*i+1])
print(len(X)-A*2)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
X = input()
ans = 0
cnt = 0
old = ""
for x in X:
    if x=="S":
        if (old != "S"):
            cnt = 0
        cnt+=1
    else:
        if (cnt>0):
            cnt-=1
            ans+=1
    old = x
print (len(X)-2*ans)

Submission status: Wrong Answer

Solution code:
X = input().strip()
flag = 0
cntS = 0
cntT = 0
num = 0
for i in range(len(X)):
    if X[i]=="S":
        if flag==0:
            num += min(cntS,cntT)
            cntS = 0
            cntT = 0
            flag = 1
        cntS += 1
    else:
        if flag==1:
            flag = 0
        cntT += 1
num += min(cntS,cntT)
print(len(X)-2*num)

Submission status: Wrong Answer

Solution code:
X = input().strip()
flag = 0
cntS = 0
cntT = 0
num = 0
for i in range(len(X)):
    if flag==0 and X[i]=="S":
        num += min(cntS,cntT)
        cntS = 0
        cntT = 0
        flag = 1
        cntS += 1
    elif flag==1 and X[i]=="S":
        cntS += 1
    elif flag==1 and X[i]=="T":
        cntT += 1
        flag = 0
    elif flag==0 and X[i]=="T":
        cntT += 1
num += min(cntS,cntT)
print(len(X)-2*num)

Submission status: Wrong Answer

Solution code:
x=list(input())
s=0
t=0
ans=len(x)
for i in range(len(x)):
    if x[i]=='S':
        ans-=2*min(s,t)
        if t!=0:
            s=0
        s+=1
        t=0
    elif x[i]=='T':
        t+=1
    if i==len(x)-1:
        ans-=2*min(s,t)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input()
i = len(x)

def find(s, b):
    n = len(s)
    m = len(b)

    if n == m:
        if s == b:
            return 0
        else:
            return -1

    for i in range(n - m - 1):
        if s[i:i+m] == b:
            return i
    return -1


while True:
    p = find(x, 'ST')
    if p == -1:
        break
    p1 = p
    p2 = p+2
    n = p
    while True:
        if len(x) -1 > 0:
            
            if x[n-1] == 'S' and x[n+2] == 'T':
                n -= 1
                p1 -= 1
                p2 += 1
            else:
                break
    # print(x, p1, p2)
    x = x[:p1] + x[p2:]
    # print(x)
print(len(x))

Submission status: Wrong Answer

Solution code:
x = input()
i = len(x)
cnt = 0


def find(s, b):
    n = len(s)
    m = len(b)

    if n == m:
        if s == b:
            return 0
        else:
            return -1

    for i in range(n - m - 1):
        if s[i:i+m] == b:
            return i
    return -1


while True:
    p = find(x, 'ST')
    if p != -1:
        cnt += 1
    else:
        break
    
    n = p
    while True:
        if len(x) -1 > 0:
            
            if x[n-1] == 'S':
                cnt += 1
                n -= 1
            else:
                break
    x = x[:p] + x[p+2:]
print(len(x))

Submission status: Wrong Answer

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

leftt = 0
while X[leftt] == 'T':
    leftt += 1

rights = 0
while X[n - rights -1] == 'S':
    rights += 1

ss, ts = 0, 0
for i in range(leftt, n-rights):
    if X[i] == 'S':
        ss += 1
    else:
        ts += 1

ans = leftt + rights + abs(ss-ts)
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
n = len(X)
cnt, ss, ts = 0, 0, 0
for i in range(n):
    if X[i] == 'S':
        if ts == 0:
            ss += 1
        else:
            cnt += min(ss, ts)*2
            ss = 1
            ts = 0
    else:
        ts += 1
else:
    cnt += min(ss, ts)*2

print(n-cnt)

Submission status: Wrong Answer

Solution code:
def sol():
  ti = 0
  ans = lenX
  for i in range(lenX//2):
    while S[i]>=T[ti]:
      ti += 1
      if ti>=lenX//2:
        return ans
    ans -= 2    
  return ans

X = input()
lenX = len(X)
S = []
T = []
for i,x in enumerate(X):
  if x == 'S':S.append(i)
  else:T.append(i)

print(sol())

Submission status: Wrong Answer

Solution code:
import bisect
X = input()
lenX = len(X)
si = 0
ei = 0
ans = lenX
for _ in range(lenX//2):
  try:
    si = bisect.bisect(X[si:],'S')-1 + si
    ei = bisect.bisect(X[max(si,ei):],'T')-1 + max(si,ei)
    if si<ei:ans-=2
    si += 1
    ei += 1
  except:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
X = input()
lenX = len(X)
si = 0
ei = 0
ans = lenX
for _ in range(lenX//2):
  try:
    si = bisect.bisect(X[si:],'S') + si
    ei = bisect.bisect(X[max(si,ei):],'T') + max(si,ei)
    if si<ei:ans-=2
    si += 1
    ei += 1
  except:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        ct +=1
        
        if cs >= ct:
            ans +=1
            cs -=1
           

print(len(arr)-2*ans)

Submission status: Wrong Answer

Solution code:
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        ct +=1
        
        if cs >= ct:
            ans +=1
           
    
    try:
        if arr[i] == "T" and arr[i+1] == "S":
            cs=0
            ct=0
    
    except:
        pass

print(len(arr)-2*ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
S = list(input())[: -1]
s = 0
t = 0
res = len(S)
if S[0] == "S": s += 1
for i in range(1, len(S)):
  if S[i] == "S":
    if t == 1:
      s = 0
      t = 0
    s += 1
  else:
    if s > 0:
      res -= 2
      s -= 1
      t = 1
print(res)

Submission status: Wrong Answer

Solution code:
X = str(input())
left_t_index = 0
right_s_index = 0
for i in range(len(X)):
    if X[i] == "S":  # 最も左にあるSの位置が分かる
        left_t_index = i
        break
for i in reversed(range(len(X))):
    if X[i] == "T":  # 最も右にあるTの位置が分かる
        right_s_index = i
        break
s_count = 0
t_count = 0
# print(left_t_index)
# print(right_s_index)
for i in range(left_t_index, right_s_index+1):
    if X[i] == "S":
        s_count += 1
    elif X[i] == "T":
        t_count += 1

print(len(X)-2*min(s_count, t_count))

Submission status: Wrong Answer

Solution code:

#
X = input()
len_X = len(X)

def find(c, i):
    j = i
    while j < len_X and X[j] == c:
        j += 1
    return min(j-i, len_X-i)

ans = 0
i = X.find('S')
while True:
    num_s = find('S', i)
    i += num_s
    if i == len_X:
        break

    num_t = find('T', i)
    i += num_t
    ans += min(num_s, num_t)
    # print(num_s, num_t)

    if i  == len_X:
        break


print(len_X - ans * 2)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    ans = 0
    for s in S[::-1]:
        if s == "S":
            ans += 1
        else:
            break
    print(ans*2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X = input()
N = len(X)
t = 0
flag = False
for i in range(N):
    if X[-1-i] == 'T':
        flag = True
    if flag:
        if X[-1-i] == 'T':
            t += 1
        else:
            t -= 1
print(2*t)

Submission status: Wrong Answer

Solution code:
msg=input()
lwbd=0
for lwbd in range(len(msg)):
    if msg[lwbd]=='S':
        break
upbd=len(msg)
for upbd in range(len(msg)-1,-1,-1):
    if msg[upbd]=='T':
        break

xs=msg[lwbd:upbd+1].count('S')
xt=msg[lwbd:upbd+1].count('T')

print(len(msg)-min(xs,xt)*2)

Submission status: Wrong Answer

Solution code:
x = input()

ans = len(x)
tmp_s = 0
mae = 1

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

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)

ans = N
i = 0
while i < N - 1:
    if S[i] == 'S' and S[i + 1] == 'T':
        cnt = 0
        while i - cnt >= 0 and i + 1 + cnt < N and S[i - cnt] == 'S' and S[i + 1 + cnt] == 'T':
            cnt += 1
        ans -= cnt * 2
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
x = list(input())
s = 0; t = 0
for i in range(len(x)):
    if x[i] == "T":
        t += 1
    else:
        break

for i in range(len(x)):
    if x[len(x)-i-1] == "S":
        s += 1
    else:
        break

print(s + t*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X = input()
ans = len(X)
N = len(X)
cnt_s = 0
cnt_t = 0
for i in range(N):
    if X[i] == "S":
        cnt_s += 1
    if X[i] == "T":
        cnt_t += 1
    if i < N -1:
        if X[i] == "T" and X[i + 1] == "S":
            ans -= 2 * min(cnt_s, cnt_t)
            cnt_s = 0
            cnt_t = 0
    else:
        ans -= 2 * min(cnt_s, cnt_t)
    
print(ans)

Submission status: Wrong Answer

Solution code:
x=input()

for i in range(1,10*10+1):
  a=x.replace("ST","D")
  b=a.replace("D","")

h=len(b)
print(h)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=input()
length=len(x)
x=x+"E"
ch=x[0]
lists=[]
counter=1
for i in range(length):
    if x[i]==x[i+1]:
        counter+=1
    elif x[i]!=x[i+1] :
        lists.append(counter)
        counter=1
uselist=[]
if x[0]=="S" and x[-2]=="S":
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="S" and x[-2]=="T":
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
   
elif x[0]=="T" and x[-2]=="S":
    lists.insert(0,0)
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="T" and x[-2]=="T":
    lists.insert(0,0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
num=len(uselist)
uselist.append((0,0))
minus=0
a=0
b=0
i=0
while i<=num-1:
    if uselist[i][0]<=uselist[i][1]:
        minus+=uselist[i][1]-uselist[i][0]
        i+=1
    elif uselist[i][0]>uselist[i][1]:
        j=0
        while a<=b and i+j<=num:
            a+=uselist[i+j][0]
            b+=uselist[i+j][1]
            j+=1
        if a<=b:
            minus+=b-a
        else:
            minus+=a-b
        a=0
        b=0
        i+=j
print(minus)

Submission status: Wrong Answer

Solution code:
x=input()
length=len(x)
x=x+"E"
ch=x[0]
lists=[]
counter=1
for i in range(length):
    if x[i]==x[i+1]:
        counter+=1
    elif x[i]!=x[i+1] :
        lists.append(counter)
        counter=1
uselist=[]
if x[0]=="S" and x[-2]=="S":
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="S" and x[-2]=="T":
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
   
elif x[0]=="T" and x[-2]=="S":
    lists.insert(0,0)
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="T" and x[-2]=="T":
    lists.insert(0,0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
 
        
num=len(uselist)
uselist.append((0,0))
minus=0
a=0
b=0
i=0
while i<=num-1:
    if uselist[i][0]<=uselist[i][1]:
        minus+=uselist[i][1]-uselist[i][0]
        i+=1
    elif uselist[i][0]>uselist[i][1]:
        a=uselist[i][0]
        b=uselist[i][1]
        while a<=b and i+1<=num:
            a+=uselist[i+1][0]
            b+=uselist[i+1][1]
            i+=1
        if a<=b:
            minus+=b-a
        else:
            minus+=a-b
        a=0
        b=0
        i+=1
print(minus)

Submission status: Wrong Answer

Solution code:
X=list(input())

f=True

while f and X:
    for i in range(len(X)-1):
        print(X) #DB
        if X[i:i+2]==['S','T']:
            del X[i:i+2]
            print (X) #DB
            break
        if i==len(X)-2:
            f=False

print(len(X))

Submission status: Wrong Answer

Solution code:
X=input()
for i,c in enumerate(X[::-1]):
    if c=='T':
        print(i*2)
        break

Submission status: Wrong Answer

Solution code:
x=str(input())
a=x.find('S')
b=x.rfind('T')
aa=x[a:b+1].count('S')
bb=x[a:b+1].count('T')
#print(aa,bb)
print(len(x)-2*min(aa,bb))

Submission status: Wrong Answer

Solution code:
x = input()

subt_num = 0
s_t_num = [0, 0]
s_t_flag = [0, 0]

for i in range(len(x)):
    if x[i] == 'S':
        if s_t_flag[0] == 1:
            pass
        else:
            subt_num += min(s_t_num)
            s_t_num = [0, 0]
            s_t_flag = [1, 0]
        s_t_num[0] += 1
    else:
        if s_t_flag[1] == 1:
            pass
        else:
            s_t_flag = [0, 1]
        s_t_num[1] += 1
    
if s_t_flag[1] == 1:
    subt_num += min(s_t_num)
    # print(i, subt_num)

print(len(x) - subt_num * 2)

Submission status: Wrong Answer

Solution code:
x = input()
ts = max([idx for idx,i in enumerate(x) if i == 'T'])
ss = [idx for idx,i in enumerate(x) if i == 'S' and idx > ts]

print(len(ss)*2)

Submission status: Wrong Answer

Solution code:
def main():
    X = str(input())
    N = len(X)
    s = []
    t = []
    s_ = 1
    t_ = 1
    for i in range(N-1):
        if X[i] == "S" and X[i+1] == "S":
            s_ += 1
        elif X[i] == "T" and X[i+1] == "T":
            t_ += 1
        elif X[i] == "S" and X[i+1] == "T":
            s.append(s_)
            s_ = 1
        else:
            t.append(t_)
            t_ = 1

    if X[-1] == "T":
        t.append(t_)
    else:
        s.append(s_)
    ans = 0
    if X[0] == "S":
        M = len(t)
        for i in range(M):
            ans += min(s[i],t[i])
    else:
        M = len(t)-1
        for i in range(M):
            ans += min(s[i],t[i+1])

    print(N-2*ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X=input()

L=len(X)
S=0

for i in range(L):
    if X[-(1+i)]=="S":
        S+=1
    else:
        break
print(2*S)

Submission status: Wrong Answer

Solution code:
X=input()

L=len(X)

S=0
T=0

for i in range(L):
    if X[i]=="S":
        S+=1
    else:
        T+=1
    if T==L//2:
        break
print(L-2*S)

Submission status: Wrong Answer

Solution code:
X = list(input())
print(len(X) - 2 * min(X[X.index("S"):].count("T"), X[:len(X) - X[::-1].index("T")].count("S")) 
)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    x = input().strip() + "x"
    c = []
    pre = x[0]
    count = 1
    for i in range(1, len(x)):
        if x[i] != pre:
            c.append(count)
            count = 1
        else:
            count += 1
        pre = x[i]

    ans = len(x) - 1
    if x[0] == "S":
        for i in range(1, len(c), 2):
            ans -= min(c[i-1], c[i]) * 2
    else:
        for i in range(2, len(c), 2):
            ans -= min(c[i-1], c[i]) * 2
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, = map(int, input().split())
S = list(input().strip())

t = 0
s = 0
for i in range(len(S)):
    if S[i] == "T":
        t += 1
    else:
        break

for i in reversed(range(len(S))):
    if S[i] == "S":
        s += 1
    else:
        break

m = len(S) // 2

print(s + t + abs((m - s) - (m - t)))

Submission status: Wrong Answer

Solution code:
s = input()
p = s.rfind("T") + 1
n = len(s)
print((n - p) * 2)

Submission status: Wrong Answer

Solution code:
x=list(input())
ans=0
check=0
for i in x:
	if i=='T':
		if check==0:
			ans+=1
		check-=1
		check=max(check,0)

	else:
		check+=1
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
X = X.replace('ST','')
print(len(X))

Submission status: Wrong Answer

Solution code:
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        X.insert(0,X.pop(i))
        X.insert(0,X.pop(i+1))


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

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    stack = []
    for i in range(len(S)):
        stack.append(S[i])
        while len(stack) > 1 and "".join(stack[-2:]) == "ST":
            stack.pop()
            stack.pop()
        print(stack)
    return len(stack)


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

Submission status: Wrong Answer

Solution code:
X = input()
l = len(X)
for i in range(100000):
  X = X.replace("ST", "")
print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=input()
n=len(x)
cs=0
ct=0
if n>100000:
    for i in range(n):
        if x[i]=="S":
            n-=min(cs,ct)*2
            ct=0
            cs+=1
        else:
            ct+=1
    n-=min(cs,ct)*2
    print(n)
else:
    while True:
        x=x.replace("ST","")
        if n==len(x):
            break
        else:
            n=len(x)
    print(n)

Submission status: Wrong Answer

Solution code:
x=input()
n=len(x)
cs=0
ct=0
if n>200:
    for i in range(n):
        if x[i]=="S":
            n-=min(cs,ct)*2
            ct=0
            cs+=1
        else:
            ct+=1
    n-=min(cs,ct)*2
    print(n)
else:
    while True:
        x=x.replace("ST","")
        if n==len(x):
            break
        else:
            n=len(x)
    print(n)

Submission status: Wrong Answer

Solution code:
x=input()
n=len(x)
cs=0
ct=0
for i in range(n):
    if x[i]=="S":
        n-=min(cs,ct)*2
        ct=0
        cs+=1
    else:
        ct+=1
n-=min(cs,ct)*2



print(n)

Submission status: Wrong Answer

Solution code:
def sol():
    X = input()
    leftT = 0
    while X[leftT] == 'T':
        leftT += 1

    rightS = 0
    while X[len(X) - rightS - 1] == 'S':
        rightS += 1

    if leftT == 0 and rightS == 0:
        print(0)
    else:
        print(leftT + rightS + 1)

sol()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
stop = 0
while stop == 0:
    ls = list(s)
    for i in range(len(ls)-1):
        if ls[i] == "S" and ls[i+1] == "T":
            l, r = i, i + 1
            stop2 = 0
            while stop2 == 0:
                ls[l], ls[r] = "", ""
                l, r = l - 1, r + 1
                if ls[l] != "S" or ls[r] != "T":
                    stop2 = 1


    new_s = "".join(ls)
    if s == new_s:
        stop = 1
    else:
        s = new_s 
print(len(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	s = input()
	a = []
	for i in s:
		a.append(-1 if i=='T' else 1)
	b = [a[0]]
	c = 0
	for i in range(1,len(s)):
		if(b[c] * a[i] > 0):
			b[c]+=a[i]
		else:
			c+=1
			b.append(a[i])
	c = b[1:] if(b[0]<0) else b
	c = c[:-1] if(b[-1]>0) else c
	ans = 0
	for i in range(len(c)//2):
		ans+=abs(c[i*2]) if c[i*2]+c[i*2+1]==0  else abs(min(c[i*2],-c[i*2+1]))
	print(len(s) - 2*ans)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

Solution code:
X = input()
cnt = 0
for i in range(len(X)):
    if X[i] == 'T':
        cnt += 1
    else:
        break


X2 = X[::-1]
cnt2 = 0
for i in range(len(X2)):
    if X2[i] == 'S':
        cnt2 += 1
    else:
        break

print(2*max(cnt, cnt2))

Submission status: Wrong Answer

Solution code:
X = input()[::-1]

cnt = 0
for i in range(len(X)):
    if X[i] == 'S':
        cnt += 1
    else:
        break

print(2*cnt)

Submission status: Wrong Answer

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

c = 0
for i, x in enumerate(X):
    if x == 'T':
        c += 1
    if c == N//2:
        ans = N - (i+1 - c)*2
        break

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
l=s.find("S")
r=s.rfind("T")
lens=(len(s))
if l==-1 or r==-1:
    print(lens)
else:
    rest=l+lens-r-1
    s=s[l:r+1]
    from collections import Counter
    s=list(Counter(s).values())
    if len(s)==0:
        print(rest)
    else:
        print(rest+abs(s[0]-s[1]))

Submission status: Wrong Answer

Solution code:
X = input()

count = 0

count_s = 0
last_x = ''
for x in X:
    if x == 'S':
        if last_x == 'T':
            count_s = 0
        count_s += 1
    elif x == 'T':
        if count_s > 0:
            count += 1
            count_s -= 1
    last_x = x

count = min(count, 10 ** 10000)
print(len(X) - count * 2)

Submission status: Wrong Answer

Solution code:
X = input()

count = 0
max_count = 10 ** 10000

count_s = 0
last_x = ''
for x in X:
    if x == 'S':
        if last_x == 'T':
            count_s = 0
        count_s += 1
    elif x == 'T':
        if count_s > 0:
            count += 1
            count_s -= 1
            if count > max_count:
                break
    last_x = x

print(len(X) - count * 2)

Submission status: Wrong Answer

Solution code:
X = input()

count = 0

count_s = 0
last_x = ''
for x in X:
    if x == 'S':
        if last_x == 'T':
            count_s = 0
        count_s += 1
    elif x == 'T':
        if count_s > 0:
            count += 1
            count_s -= 1
    last_x = x

print(len(X) - count * 2)

Submission status: Wrong Answer

Solution code:
s = input()
print(len(s)-2*s.count('ST'))

Submission status: Wrong Answer

Solution code:
S = input()
scount = 0
tcount = 0
ans = 0
for c in S:
    if c == "S":
        ans += min(scount, tcount) * 2
        tcount = 0
        scount += 1
    else:
        tcount += 1

ans += min (scount,tcount) * 2
ans = len(S) -ans
print(ans)

Submission status: Wrong Answer

Solution code:
# SはストックのS 存在するぶんだけTと相殺できる
# 消した数じゃなくて残った数を数えるってのを読み飛ばしてて1WA

x = input()
stock = 0
count = 0
for a in x:
    if a == "S":
        stock += 1
    else:
        if stock > 0:
            count += 2
            stock -= 1
print(len(x)-stock)

Submission status: Wrong Answer

Solution code:
# SはストックのS 存在するぶんだけTと相殺できる
x = input()
stock = 0
count = 0
for a in x:
    if a == "S":
        stock += 1
    else:
        if stock > 0:
            count += 1
            stock -= 1
print(count)

Submission status: Wrong Answer

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

print(s+t)

Submission status: Wrong Answer

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

print(s+t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print(input().replace('ST',''))

Submission status: Wrong Answer

Solution code:
S = input()

c = 0
for i in range(len(S)):
    if S[i] == "T":
        c +=1
    else:
        break

cc = 0
for i in range(len(S)-1,-1,-1):
    if S[i] == "S":
        cc += 1
    else:
        break

s,t = 0,0
for i in range(c,len(S)-cc):
    if S[i] == "S":
        s += 1
    elif S[i] == "T":
        t += 1

print(c+cc+abs(s-t))

Submission status: Wrong Answer

Solution code:
X = input()

Y = X[::-1]

ans = 0

for x in X:
    if x == 'T':
        ans += 1
    else:
        break
for y in Y:
    if y == 'S':
        ans += 1
    else:
        break

if ans % 2 == 0:
    print(ans)
else:
    print(ans + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
X = (stdin.readline().rstrip())
cnt_t = 0
cnt_s = 0
cumsum_t = [0] * len(X)
cumsum_s = [0] * len(X)
for ind,i in enumerate(X):
    if i == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    cumsum_s[ind] = cnt_s
    cumsum_t[ind] = cnt_t

ans = 0
for j in (np.array(cumsum_s) - np.array(cumsum_t)):
    if j < 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
X = (stdin.readline().rstrip())
X_l = X[:int(len(X)/2)]
X_r = X[int(len(X)/2):]
print(len(X) - min(X_l.count("S"),X_r.count("T")) * 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
a = list(s.split("ST"))
d = ""
for i in a:
  d = d + i
print(len(d))

Submission status: Wrong Answer

Solution code:
s = input()
a = list(s.split("ST"))
d = ""
for i in a:
  d = d + i
print(len(i))

Submission status: Wrong Answer

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