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:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    X = input()

    # TTT .... SS

    cnt_head_T = 0
    for x in X:
        if x == 'T':
            cnt_head_T += 1
        else:
            break

    cnt_tail_S = 0
    for x in X[::-1]:
        if x == 'S':
            cnt_tail_S += 1
        else:
            break

    rest_T = len(X) // 2 - cnt_head_T
    rest_S = len(X) // 2 - cnt_tail_S
    rest_len = max(rest_T, rest_S) - min(rest_T, rest_S)
    print(cnt_head_T + rest_len + cnt_tail_S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

right = N - 1
cnt = 0

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

Submission status: Wrong Answer

Solution code:
# A_String
s=input()
from itertools import groupby
gr=groupby(list(s))
c=[]
for k,g in gr:
  c.append(len(list(g)))
n=len(c)
if n==1:
  print(0)
  exit(0)
ans=0
s_cnt=0
if s[0]=="S":
  if n%2==1:
      n-=2
  for i in range(n):
    if i%2==0:
      t=min(s_cnt+c[i],c[i+1])
      s_cnt=0
      s_cnt+=c[i]-t
      ans+=2*t
else:
  if n%2==1:
      n-=1
  else:
      n-=2
  for i in range(n):
    if i%2==1:
      t=min(s_cnt+c[i],c[i+1])
      s_cnt=0
      s_cnt+=c[i]-t
      ans+=2*t
print(len(s)-ans)

Submission status: Wrong Answer

Solution code:
x = list(input())
while x[0:int(len(x)/2)] != ['T'] * int(len(x)/2):
    for i in range(len(x)-1):
        if x[i] == 'S' and x[i+1] == 'T':
            x[i], x[i+1] = '', ''
    x.remove('')
print(len(x))

Submission status: Wrong Answer

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

def solve():
    nt, rs = 0, 0
    for i in range(N):
        if nt == NHALF:
            break
        if X[i] == 'T':
            nt += 1
        else:
            rs += 1
    ns, rt = 0, 0
    for i in range(N-1, -1, -1):
        if ns == NHALF:
            break
        if X[i] == 'S':
            ns += 1
        else:
            rt += 1
    return N - 2 * min(rs, rt)


print(solve())

Submission status: Wrong Answer

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

def solve2():
    leadt = 0
    nt, ns = 0, 0
    for i in range(N):
        if nt == NHALF:
            break
        if X[i] == 'T':
            nt += 1
            if ns == 0:
                leadt += 1
        else:
            ns += 1
    return N - 2 * min(ns, NHALF - leadt)


print(solve2())

Submission status: Wrong Answer

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

def solve2():
    nt, ns = 0, 0
    for i in range(N):
        if nt == NHALF:
            break
        if X[i] == 'T':
            nt += 1
        else:
            ns += 1
    return N - 2*ns


print(solve2())

Submission status: Wrong Answer

Solution code:
import sys
X = list(sys.stdin.readline().strip())
N = len(X)
NHALF = N // 2

def solve2():
    ns = 0
    nt = 0
    i = 0
    while nt < NHALF:
        if X[i] == 'T':
            nt += 1
            i += 1
        else:
            ns += 1
            i += 1
    return N - 2*ns


print(solve2())

Submission status: Wrong Answer

Solution code:
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve2():
    trailing = 0
    i = N-1
    while i >= 0 and X[i] == 'S':
        trailing += 1
        i -= 1
    return trailing * 2

print(solve2())

Submission status: Wrong Answer

Solution code:
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve2():
    heading = 0
    trailing = 0
    i = 0
    while i < N and X[i] == 'T':
        heading += 1
        i += 1
    i = N-1
    while i >= 0 and X[i] == 'S':
        trailing += 1
        i -= 1
    return max(heading, trailing) * 2

print(solve2())

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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
        else:
            answer -= 2
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    N = len(X)
    cnt_s = 0
    cnt_t = 0
    flag = 0
    answer = 0
    for i in range(N):
        if X[i] == "S":
            cnt_s += 1
        elif X[i] == "T":
            cnt_t += 1
            if cnt_t > cnt_s:
                answer += cnt_t - cnt_s
                cnt_t = 0
                cnt_s = 0
            elif cnt_t == cnt_s:
                cnt_t = 0
                cnt_s = 0

    if cnt_s > 0:
        answer += cnt_s
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    X = input()
    N = len(X)
    cnt_s = 0
    cnt_t = 0
    flag = 0
    answer = 0
    for i in range(N):
        if X[i] == "S":
            cnt_s += 1
            flag += 1
        elif X[i] == "T":
            cnt_t += 1
            flag = 0
            if cnt_t > cnt_s:
                answer += cnt_t - cnt_s
                cnt_t = 0
                cnt_s = 0
    if flag > 0:
        answer += flag
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X = input()

idx = None
for i in range(len(X) - 1, -1, -1):
    if X[i] == "T":
        idx = i
        break

n_s = X[: idx + 1].count("S")
n_t = X[: idx + 1].count("T")
ans = len(X) - 2 * min(n_s, n_t)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    input = stdin.readline

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

Solution code:
X=input()
l=[]
flag="-1"
cs=0
ct=0
for i in range(len(X)):
    if X[i]=="S":
        if flag=="T":
            l.append([cs,ct])
            cs=1
            ct=0
            flag="S"
        else:
            flag="S"
            cs+=1
    else:
        if flag=="S":
            flag="T"
            ct+=1
        elif flag=="T":
            ct+=1
        else:
            continue
if flag=="T":
    if cs>0:
        l.append([cs,ct])
ans=0
for i in range(len(l)):
    ans+=2*min(l[i][0],l[i][1])
print(len(X)-ans)

Submission status: Wrong Answer

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] == 'S':
            que.append(s[i])
        else:
            que.pop()
            
print(len(que))

Submission status: Wrong Answer

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

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


def run_length_encoding(s):
    '''
    連長圧縮を行う
    s ... iterable object e.g. list, str 
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx
    '''
    s_composed = []
    s_sum = []
    s_idx = [0]
    pre = s[0]
    cnt = 1
    for i, ss in enumerate(s[1:], start=1):
        if pre == ss:
            cnt += 1
        else:
            s_sum.append(cnt)
            s_composed.append(pre)
            s_idx.append(i)
            cnt = 1
            pre = ss
    s_sum.append(cnt)
    s_composed.append(pre)
    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


X = input()
X_composed, X_sum, X_idx = run_length_encoding(X)
if X_composed[0] == 'T':
    X_composed.insert(0, 'S')
    X_sum.insert(0, 0)
    X_idx.insert(0, None)
if X_composed[-1] == 'S':
    X_composed.append('T')
    X_sum.append(0)
    X_idx.append(None)

S_stock = 0  # Sの余り
ans = 0
for s, t in zip(X_sum[::2], X_sum[1::2]):
    S_stock += s
    if S_stock > t:
        S_stock -= t
    else:
        ans += t - s
        S_stock = 0

ans += S_stock

print(ans)
# print(X_composed)
# print(X_sum)
# print(X_idx)

Submission status: Wrong Answer

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

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


def run_length_encoding(s):
    '''
    連長圧縮を行う
    s ... iterable object e.g. list, str 
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx
    '''
    s_composed = []
    s_sum = []
    s_idx = [0]
    pre = s[0]
    cnt = 1
    for i, ss in enumerate(s[1:], start=1):
        if pre == ss:
            cnt += 1
        else:
            s_sum.append(cnt)
            s_composed.append(pre)
            s_idx.append(i)
            cnt = 1
            pre = ss
    s_sum.append(cnt)
    s_composed.append(pre)
    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


X = input()
X_composed, X_sum, X_idx = run_length_encoding(X)
if X_composed[0] == 'T':
    X_composed.insert(0, 'S')
    X_sum.insert(0, 0)
    X_idx.insert(0, None)
if X_composed[-1] == 'S':
    X_composed.append('T')
    X_sum.append(0)
    X_idx.append(None)

S_stock = 0  # Sの余り
ans = 0
for s, t in zip(X_sum[::2], X_sum[1::2]):
    s += S_stock
    if s > t:
        S_stock += s - t
    else:
        ans += t - s

ans += S_stock

print(ans)
# print(X_composed)
# print(X_sum)
# print(X_idx)

Submission status: Wrong Answer

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 x[-1]=='T':
            q.append(x[i])
        else:
            q.pop()
            ans+=1
print(l-ans)

Submission status: Wrong Answer

Solution code:
X = input()

t, s = 0, 0
flag_t, flag_s = True, True
for i in range(len(X)):

    if flag_t:
        if X[i] == 'T':
            t += 1
        else:
            flag_t = False

    if flag_s:
        if X[-(i+1)] == 'S':
            s += 1
        else:
            flag_s = False

    if flag_t==False and flag_s==False:
        break

print(max(t, s)*2)

Submission status: Wrong Answer

Solution code:
s = [i for i in input()]
ans = len(s)
s_cnt = t_cnt = idx = 0
s_ = s[0]
while idx < len(s):
    if s_ == s[idx]:
        if s_ == "T" and s_cnt != 0:
            t_cnt += 1
        elif s_ == "S":
            s_cnt += 1
    else:
        if s_ == "T" and s_cnt == 0:
            s_ = "S"
            s_cnt += 1
        elif s_ == "T" and s_cnt != 0:
            ans -= min(s_cnt, t_cnt) * 2
            s_ = "S"
            s_cnt = 1
            t_cnt = 0
        elif s_ == "S":
            s_ = "T"
            t_cnt += 1
    if idx == len(s) - 1 and s_cnt != 0 and t_cnt != 0:
        ans -= min(s_cnt, t_cnt) * 2
    idx += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input()
x = x[::-1]
begin = x.index('T')
c = x[begin:].count('S')
print(len(x) - c * 2)

Submission status: Wrong Answer

Solution code:
X = input()
mLoop = 10 ** 1000
mode = 'Ti' if X[0] == 'T' else 'I'
sum = 0
total = 0
for i in X:
  if i != mode[0]:
    if i == 'S':
      total += sum
      sum = 1
      mode = 'S'
    else:
      mode = 'Td'
      sum -= 1
  else:
    if i == 'S':
      sum += 1
    else:
      if sum == 0:
        mode = 'Ti'
        sum = 1
      elif mode == 'Td':
        sum -= 1
      else:
        sum += 1
  #print(sum, total, sep=' ')

total += sum      
print(total)

Submission status: Wrong Answer

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 += 0
print(Sn + Tn)

Submission status: Wrong Answer

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)

    S = 0
    last_T_index = 0
    for i in range(LENX-1,-1,-1):
        if X[i] == "T":
            last_T_index = i 
            break

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

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

    S = 0

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

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

    left_T = 0
    right_S = 0

    for i in range(LENX):
        if X[i] == "T":
            left_T += 1
        else:
            break
    
    for i in range(LENX-1,-1,-1):
        if X[i] == "S":
            right_S += 1
        else:
            break
    
    print(left_T+right_S)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
lS = len(S)
tmp = ["S","T"]
f = 0
cnt = 0
l = []
for i in range(lS):
    if (S[i] == tmp[f]):
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1
        f ^= 1
if (cnt != 0):l.append(cnt)
if (len(l) % 2 != 0) : l.append(0)
ll = len(l)
for i in range(0,ll,2):
    m = min(l[i],l[i+1])
    l[i] -= m
    l[i+1] -= m

print(sum(l))

Submission status: Wrong Answer

Solution code:
def main():
    s = input().rstrip()
    cnt_t, cnt_s = 0, 0
    for i in range(len(s)):
        if s[i] == "S":
            cnt_t = i
            break
    for i in range(len(s)):
        if s[len(s)-1-i] == "T":
            cnt_s = i
            break
    print(2*max(cnt_t, cnt_s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x=input();print(len(x)-2*min(map(x.lstrip("T").rstrip("S").count,"ST")))

Submission status: Wrong Answer

Solution code:
s = input()
l = 0
for k in range(len(s)):
    if s[k] != "T":
        l = k
        break
r = 0
for k in range(len(s)):
    if s[-k-1] != "S":
        r = k
        break
print(2*max(l,r))

Submission status: Wrong Answer

Solution code:

X = input()
N = len(X)
t = 0
ans = N
for c in X[::-1]:
    if c == 'T':
        t += 1
    elif t > 0:
        ans -= 2
print(ans)

Submission status: Wrong Answer

Solution code:

X = input()
N = len(X)
l, r = 0, N
while l < N and X[l] == 'T':
    l += 1
while r > 0 and X[r-1] == 'S':
    r -= 1
s = X[l:r].count('S')
t = r - l - s
ans = N - min(s, t) * 2
print(ans)

Submission status: Wrong Answer

Solution code:

X = input()
s = 0
t = 0
for i in range(len(X)):
    if X[i] == 'S':
        t = i
        break
for i in range(len(X)):
    j = len(X) - i - 1
    if X[len(X)-i-1] == 'T':
        s = j
        break
ans = len(X) - min(X[:s].count('S'), X[t:].count('T')) * 2
print(ans)

Submission status: Wrong Answer

Solution code:

X = input()
idx = 0
for i in range(len(X)):
    j = len(X) - i - 1
    if X[len(X)-i-1] == 'T':
        idx = j
        break
print(len(X) - X[:idx].count('S')*2)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

x = STR()
l = len(x)
a = x[0]
st = []
tmp = 1
for i in range(1, l):
    if x[i] == x[i-1]:
        tmp += 1
    else:
        st.append(tmp)
        tmp = 1
st.append(tmp)

ll = len(st)
ans = l
if a == 'S':
    if ll % 2 == 1:
        ll -= 1
    for i in range(0, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)
else:
    if ll % 2 == 0:
        ll -= 1
    for i in range(1, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)

Submission status: Wrong Answer

Solution code:

X = input()
s = 0
t = 0
ans = len(X)
for c in X:
    if c == 'T':
        t += 1
    elif t > 0:
        ans -= min(s, t) * 2
        s = t = 0
    if c == 'S':
        s += 1
if t > 0:
    ans -= min(s, t) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
s=str(input())
co=int(1)
n=len(s)
A=[]
for i in range(1,n):
    if s[i]!=s[i-1]:
        A.append(co)
        co=1
    else:
        co+=1
A.append(co)
m=len(A)
how=0
if s[0]=='T':
    how=1

S=int(0)
T=int(0)
for i in range(how,m-how):
    if i%2==how:##s
        S+=A[i]
    else:##t
        T+=A[i]
        if S<T:
            n-=2*S
            T-=S
            S-=S
        else:
            n-=2*T
            S-=T
            T-=T


print(n)

Submission status: Wrong Answer

Solution code:
s=str(input())
co=int(1)
n=len(s)
A=[]
for i in range(1,n):
    if s[i]!=s[i-1]:
        A.append(co)
        co=1
    else:
        co+=1
A.append(co)
m=len(A)
how=0
if s[0]=='T':
    how=1

A.append(0)
for i in range(how,m-how):
    if i%2!=how:
        continue

    if A[i]<A[i+1]:
        n-=2*A[i]
    else:
        n-=2*A[i+1] 
print(n)

Submission status: Wrong Answer

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

tt = 0
while(s[tt]=="T"):
    tt+=1
    
ss=n
while(s[ss-1]=="S"):
    ss -= 1
print(max(tt, n-ss)*2)

Submission status: Wrong Answer

Solution code:
X = str(input())
x = X.index('S')
y = X.rindex('T')
A = X[x:y+1]
a = A.count('S')
b = A.count('T')
ans = len(X)-len(A)
ans += abs(a-b)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
m = [{"char": c, "exists": True, "go_to_when_deleted": idx - 1} for idx, c in enumerate(s)]
for idx in range(0, len(s) - 1):
    jdx = idx
    while not m[jdx]["exists"]:
        jdx = m[jdx]["go_to_when_deleted"]
    if m[jdx]["char"] + m[idx + 1]["char"] == "ST":
        m[jdx]["exists"] = False
        m[idx+1]["exists"] = False
        m[idx+1]["go_to_when_deleted"] = m[jdx]["go_to_when_deleted"]
print(len("".join([c['char'] for c in m if c["exists"]])))

Submission status: Wrong Answer

Solution code:
x = input()

x = x.replace("ST", "")

ans = len(x)
s = 0
t = 0
f = 1
for xi in x:
    if xi == "S":
        if f:
            s += 1
        else:
            ans -= min(s, t) * 2
            s = 1
            t = 0
            f = 1
    if s and xi == "T":
        t += 1
        f = 0

ans -= min(s, t) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
x = input()

x = x.replace("ST", "")
ans = len(x)
s = 0
t = 0
f = 1
for xi in x:
    if f and xi == "S":
        if f:
            s += 1
        else:
            ans -= min(s, t) * 2
            s = 1
            t = 0
            f = 1
    if s and xi == "T":
        t += 1
        f = 0

ans -= min(s, t) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
x = input()

ans = len(x)
s = 0
t = 0
f = 1
for xi in x:
    if f and xi == "S":
        s += 1
    if s and xi == "T":
        t += 1
        f = 0
    if not f and xi == "S":
        ans -= min(s, t) * 2
        s = 1
        t = 0
        f = 1

ans -= min(s, t) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
X=input()
print(max(X.find("S"),X[::-1].find("T"))*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input()
x = "T" + x + "S"
ar = []
c = 1
for i in range(1, len(x)):
    if x[i-1] == x[i]:
        c += 1
    else:
        ar.append(c)
        c = 1
ar.append(c)
mi = 0
for i in range((len(ar)-2)//2):
    k = i*2 + 1
    mi += min(ar[k], ar[k+1])*2
print(len(x)-2-mi)

Submission status: Wrong Answer

Solution code:
s = input()
if s[0]=='S':
    print(0)
else:
    while 'ST' in s:
        s = s.replace('ST', '')
    print(len(s))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def main():
    X = input()
    count = 0
    gp = []
    for key,value in groupby(X):
        gp.append(list(value))
    for i in range(len(gp)-1):
        if gp[i][0] == "S":
            count += min(len(gp[i]),len(gp[i+1]))*2
    tmp = len(X)-count
    count = 0
    for i in range(450):
        count += X.count("ST")
        X = X.replace("ST","")
    print(min(len(X),tmp))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X = input()
    count = 0
    for i in range(450):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X = input()
    count = 0
    for i in range(4*10**2):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X = input()
    count = 0
    for i in range(2*10**2):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X = input()
    count = 0
    for i in range(10**2):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def main():
    X = input()
    gp = []
    for key,value in groupby(X):
        gp.append(list(value))
    count = 0
    for i in range(len(gp)-1):
        if gp[i][0] == "S":
            count += min(len(gp[i]),len(gp[i+1]))*2
    print(len(X)-count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x = input()
s_count = x.count('S')
t_count = x.count('T')
count = 0
l = 0
r = len(x)-1

for i in range(len(x)):
    if s_count == 0 or t_count == 0:
        break
    if x[i]=='S':
        s_count -= 1
        if t_count > 0:
            count += 1
    else:
        t_count -= 1
print(len(x)-count*2)

Submission status: Wrong Answer

Solution code:
x = input()
s_count = x.count('S')
t_count = x.count('T')
count = 0
l = 0
r = len(x)-1

for i in range(len(x)):
    if s_count == 0 or t_count == 0:
        break
    if x[i]=='S':
        s_count -= 1
        if t_count > 0:
            t_count -= 1
            count += 1
    else:
        t_count -= 1
print(len(x)-count*2)

Submission status: Wrong Answer

Solution code:
x = input()
s_count = x.count('S')
t_count = x.count('T')
count = 0
for i in range(len(x)):
    if s_count == 0 or t_count == 0:
        break
    if x[i]=='S':
        s_count -= 1
        if t_count > 0:
            count += 1
    else:
        t_count -= 1
print(len(x)-count*2)

Submission status: Wrong Answer

Solution code:
S = input()

count = len(S)
N = count
s_count = 0
t_count = 0

i = 0
while i < N:
    if S[i] == 'S':
        s_count += 1
        i += 1
    else:
        if s_count != 0:
            tmp = i
            while tmp < N and S[tmp] == 'T':
                tmp += 1
                t_count += 1
            cut = min(s_count, t_count)
            count -= cut*2
            s_count = t_count = 0
            i += cut
        else:
            i += 1

        
print(count)

Submission status: Wrong Answer

Solution code:
X = input()
N = len(X)
S = N // 2
T = S

con = 0
ans = N

for i in range(N):
  j = i + 1
  if X[i] == "S":
    con += 1
    remain = N - j
    rems = S - con
    remt = remain - rems
    if remt > 0:
      ans -= 2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = "T"+input()+"S"
ans = len(x)-2
s = t = 0
for i in x:
    if i=="S":
        ans -= min(s,t)*2
        if t: s = t = 0
        s += 1
    else: t += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=list(input())
n=len(x)
word=[('S','S'),('S','T'),('T','T'),('T','S')]

if x[0]=='S':
  cnt_t=0
  cnt_s=1
else:
  cnt_t=1
  cnt_s=0

ans=0
for i in range(n-1):
    if (x[i],x[i+1])==word[0]:
      cnt_s+=1
    elif (x[i],x[i+1])==word[1]:
      cnt_t+=1
    elif (x[i],x[i+1])==word[2]:
      cnt_t+=1
    else:
      ans+=max(cnt_t,cnt_s)-min(cnt_t,cnt_s)
      cnt_s=1
      cnt_t=0

ans+=max(cnt_t,cnt_s)-min(cnt_t,cnt_s)
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()

sleft = X.find('S')
tright = X.rfind('T')
Y = X[sleft:tright + 1]
print(len(X) - 2 * min(Y.count('S'), Y.count('T')))

Submission status: Wrong Answer

Solution code:
X = input()

tright = X.rfind('T')
print(len(X) - 2 * X[0:tright].count('S'))

Submission status: Wrong Answer

Solution code:
X=list(map(str,input()))
t=0
s=0
i=0
TL=0
SR=0
h=len(X)//2
#print(h,len(X))
while s==0:
  if X[i]=="T":
    TL=TL+1
    i=i+1
    #print("i",i,"TL",TL)
  else:
    s=s+1
    break
i=len(X)-1
while t==0:
  if X[i]=="S":
    SR=SR+1
    i=i-1
    #print("i",i,"SR",SR)
  else:
    t=t+1
    break
print(max(SR,TL)*2)

Submission status: Wrong Answer

Solution code:
X=list(map(str,input()))
t=0
s=0
i=0
rt=0
h=len(X)//2
#print(h)
while t!=h:
  if X[i]=="T":
    t=t+1
    i=i+1
    if s==0:
      rt=rt+1
    #print("t",t)
  else:
    s=s+1
    i=i+1
    #print("s",s)
print(min((len(X)-s*2+rt*2),len(X)))

Submission status: Wrong Answer

Solution code:
X=list(map(str,input()))
t=0
s=0
i=0
rt=0
h=len(X)//2
#print(h)
while t!=h:
  if X[i]=="T":
    t=t+1
    i=i+1
    if s==0:
      rt=rt+1
    #print("t",t)
  else:
    s=s+1
    i=i+1
    #print("s",s)
print(len(X)-s*2+rt*2)

Submission status: Wrong Answer

Solution code:
X=list(map(str,input()))
t=0
s=0
i=0
h=len(X)//2
#print(h)
while t!=h:
  if X[i]=="T":
    t=t+1
    i=i+1
    #print("t",t)
  else:
    s=s+1
    i=i+1
    #print("s",s)
print(len(X)-s*2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
S = len(s)

start = 0
goal = S-1

for i,j in enumerate(s):
    if j == "S":
        start = i
        break
for i,j in enumerate(s[::-1]):
    if j == "T":
        goal = S-i
        break

s = s[start:goal]
print(S-min(s.count("T"),s.count("S"))*2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

s = list(stdin.readline().rstrip())
S = len(s)

li = []
for key, value in groupby(s):
    li.append((key,len(list(value))))

point = 0
amari = 0

for i in range(len(li)-1):
    if li[i][0] == "S" and li[i+1][0] == "T":
        point += min(li[i][1]+amari,li[i+1][1])
        amari = max(li[i][1]+amari,li[i+1][1]) - min(li[i][1]+amari,li[i+1][1])
print(S-point*2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

s = list(stdin.readline().rstrip())
S = len(s)

li = []
for key, value in groupby(s):
    li.append((key,len(list(value))))

point = 0

for i in range(len(li)-1):
    if li[i][0] == "S" and li[i+1][0] == "T":
        point += min(li[i][1],li[i+1][1])

print(S-point*2)

Submission status: Wrong Answer

Solution code:
x = input()
ans = len(x)
s = 0
t = 0
tar = "S"

for c in x:
    if c == "S":
        if tar == "T":
            ans -= min(s,t)*2
            s,t = 0,0
        s += 1
    else:
        t += 1
    tar = c
else:
    if tar == "T":
        ans -= min(s,t)*2

print(ans)

Submission status: Wrong Answer

Solution code:
x = input()
ans = len(x)
cnt = {"S":0,"T":0}
tar = "S"

for c in x:
    if c == "S" and tar == "T":
        ans -= min(cnt.values())*2
        cnt = {"S":0,"T":0}
    cnt[c] +=  1
    tar = c
else:
    if tar == "T":
        ans -= min(cnt.values())*2
        
print(ans)