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:
s = raw_input()

#while s.find('ST') > -1:
#    s = ''.join(s.split('ST'))
#
#print len(s)

temp = []
for i in range(len(s)):
    now = s[i]
    if len(temp) == 0:
        temp.append(now)
    elif temp[-1] + now == 'ST':
        temp.pop()
    else:
        temp.append(now)

print len(temp)

Submission status: Accepted

Solution code:

str = input()
res=0
s=0
for e in str:
       if e == 'S':
              s=s+1
       elif s>0:
              res=res+1
              s=s-1
print(len(str)-res*2)

Submission status: Accepted

Solution code:
line = input()

ori = len(line)

count = 0 

T = 0 
S = 0 

for i in line:
    if i is "S":
        S += 1
    else:
        if S is not 0:
            S -= 1
            count += 1

print(ori - count * 2)

Submission status: Accepted

Solution code:
X=raw_input()
l=[0,0]
for i in X:
    if i=='S':
        l[0]+=1
    elif i=='T' and l[0]>0:
        l[0]-=1
    else:
        l[1]+=1
print sum(l)

Submission status: Accepted

Solution code:
x = str(input())

s_count = 0
st = 0

for i in range(len(x)):
    if(x[i]=='S'):
        s_count+=1
    else:   # x[i]=='T'
        if(s_count>0):
            st+=1
            s_count-=1

print(len(x) - 2*st)

Submission status: Accepted

Solution code:
s=list(input())

def solve(s):
    c=1 if s[0] == 'S' else 0
    ans=1 if s[0] == 'T' else 0

    for i in range(1, len(s)):
        if s[i] == 'S':
            if s[i-1] == 'S':
                c += 1
            else:
                ans+=c
                c=1
        else:
            if c > 0:
                c -= 1
                s[i] = 'S'
            else:
                ans += 1
    return ans+c

print(solve(s))

Submission status: Accepted

Solution code:
X = raw_input()

y = []
for n in xrange(len(X)):
    y.append(X[n])

    while (1):
        if len(y) < 2: break
        if y[-2] == 'S' and y[-1] == 'T':
            y.pop()
            y.pop()
        else:
            break

print len(y)

Submission status: Accepted

Solution code:
st = input()
sc = 0
tc = 0
for s in st:
    if s == "S":
        sc += 1
    if s == "T":
        if sc > 0:
            sc -= 1
        else:
            tc += 1

print(sc + tc)

Submission status: Accepted

Solution code:
#coding=UTF-8

X=input()

ans=0
dep=0
for moji in X:
    if moji == 'S':
        dep=dep+1
    else:
        if dep == 0:
            ans=ans+1
        else:
            dep=dep-1

print(ans*2)

Submission status: Accepted

Solution code:
s = raw_input().strip()
st = []
for x in s:
    st.append(x)
    while len(st) >= 2 and st[-1] == 'T' and st[-2] == 'S':
        st.pop()
        st.pop()
print len(st)

Submission status: Accepted

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

num = 0
ans = l
for i in range(l):
    if s[i] == "S":
        num += 1
    else:
        if num == 0:
            continue
        else:
            num -= 1
            ans -= 2

print(ans)

Submission status: Accepted

Solution code:
x = raw_input()

l = len(x)

s = 0
for i in x:
    if(i=='S'): s+=1
    if(i=='T' and s>0): 
        s-=1
        l-=2

print l

Submission status: Accepted

Solution code:
input_string = raw_input()

s_num = 0
str_len = len(input_string)

for c in input_string:
    if c == 'S':
        s_num += 1

    elif c == 'T':
        if s_num > 0:
            s_num -= 1
            str_len -= 2

print str_len

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
st=raw_input()
n=len(st)
ans=n
ssc=0
for c in st:
    if c=='S':
        ssc+=1
    elif c=='T' and ssc>0:
        ans-=2
        ssc-=1
print ans

Submission status: Accepted

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

print(len(string) - 2 * count),

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=raw_input()
stack=[]
for i in xrange(len(s)):
    if len(stack)==0 or s[i]=="S":
        stack.append(s[i])
        continue
    if s[i]=="T":
        if stack[-1]=="S":
            stack.pop()
        else:
            stack.append(s[i])
print(len(stack))

Submission status: Accepted

Solution code:
def solve(s: str) -> int:
    ans = 0
    s_cnt = 0
    for c in s:
        if c == 'S':
            s_cnt += 1
        else:
            if s_cnt > 0:
                s_cnt -= 1
            else:
                ans += 1
    return ans + s_cnt

print(solve(input().strip()))

Submission status: Accepted

Solution code:
instring = raw_input()

finallen = len(instring)
num_open = 0
for char in instring:
    if (char == 'S'):
        num_open += 1
    elif(num_open > 0):
        num_open -= 1
        finallen -= 2
print finallen

Submission status: Accepted

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

Submission status: Accepted

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


def final_length(st):
    s = 0
    t = 0
    for c in st:
        if c == "S":
            s += 1
        elif c == "T":
            if s > 0:
                s -= 1
            else:
                t += 1
    return s + t


def main():
    print(final_length(input()))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X = raw_input()
t = []
for x in X:
    if len(t)>0 and t[-1]=="S" and x=="T":
        t.pop()
    else:
        t += [x]
print len(t)

Submission status: Accepted

Solution code:
from sys import stdin

compteur=0
chaine=stdin.readline()
reste=len(chaine)-1
for caractere in chaine:
    if caractere=="S":
        compteur+=1
    elif caractere=="T" and compteur>0:
        compteur-=1
        reste-=2
print(reste)

Submission status: Accepted

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

Submission status: Accepted

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

X = input()
S = ""
for ch in X:
    if ch == 'S':
        S += ch
    else:
        if len(S) > 0 and S[-1] == 'S':
            S = S[:-1]
        else:
            S += ch
print(len(S))

Submission status: Accepted

Solution code:
# import sys; sys.stdin = open('input.txt')

s = raw_input()

a = []
for c in s:
	if c == 'S':
		a.append(c)
	else:
		if len(a) > 0 and a[-1] == 'S':
			a.pop()
		else:
			a.append(c)

print len(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

X = s()

con = 0
dec = 0
for c in X:
    if c == 'S':
        con += 1
    elif con > 0:
        con -= 1
        dec += 2
    else:
        con = 0

print len(X) - dec

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def f():
    s = input()
    r = 0
    n = 0
    for c in s:
        if c == 'S':
            n -= 1
        else:
            n += 1
        if r < n:
            r = n

    return r*2

print(f())

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict

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

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

X = input()

n = 0
for x in X:
  if x == "S":
    n += 1
  else:
    if n > 0:
      n -= 1

print(2*n)

Submission status: Accepted

Solution code:
X = raw_input()
ans = ""
for c in X:
    ans += c
    if len(ans) >= 2 and ans[-2:] == "ST":
        ans = ans[:-2]
print len(ans)

Submission status: Runtime Error

Solution code:
s=input() ; n=len(s)
for i in range(10000):
    s=s.replace("ST","")
    if a==s:
      print(len(s));exit()
    a=s
print(len(s))

Submission status: Runtime Error

Solution code:
x=list(input())
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Submission status: Runtime Error

Solution code:
x=input()
x=list(x)
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Submission status: Runtime Error

Solution code:
X = input()

idx = 0

while idx < len(X):
    print(idx, X)
    if X[idx] == 'S':
        if idx+1 < len(X) and X[idx+1] == 'T':
            X = X[:idx] + X[idx+2:]
            idx = max(-1, idx-2)
    idx += 1

print(len(X))

Submission status: Runtime Error

Solution code:
ans = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        ans += cnt_s
        cnt_s = cnt_t = 0
ans += cnt_s
print(len(s) - ans*2)

Submission status: Runtime Error

Solution code:
X = input()

cache = 0
ans = len(X)

for c in X:
    if c == 'S'
        cache += 1
    else:
        if cache > 0:
            cache -= 1
            ans -= 2

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[i-j for i,j in zip(a[::2],a[1::2]) if i!=j]
    while a and a[0]<0:
        ans+=abs(a.pop(0))
    while a and a[-1]>0:
        ans+=a.pop(-1)
    b=[]    
    if a:
        b=[a[0]]
        for i in range(1,len(a)):
            if a[i]*a[i-1]>0:
                b[-1]+=a[i]
            else:b+=a[i]
    a=[abs(i) for i in b]
            
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[i-j for i,j in zip(a[::2],a[1::2]) if i!=j]
    while a and a[0]<0:
        ans+=abs(a.pop(0))
    while a and a[-1]>0:
        ans+=a.pop(-1)
    b=[]    
    if a:
        b=a[0]
        for i in range(1,len(a)):
            if a[i]*a[i-1]>0:
                b[-1]+=a[i]
            else:b+=a[i]
    a=[abs(i) for i in b]
            
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[i-j for i,j in zip(a[::2],a[1::2]) if i!=j]
    if a and a[0]<0:
            ans-=a.pop(0)
    if a and [-1]>0:
            ans+=a.pop(-1)
    a=[abs(i) for i in a if i!=0]
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    a=[i for i in a if i!=0]
    if a:
        if a[0]<0:
            ans-=a.pop(0)
    if a:
        if a[-1]>0:
            ans+=a.pop(-1)
    a=[abs(i) for i in a if i!=0]
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    if a:
        if a[0]<0:
            ans-=a.pop(0)
    if a:
        if a[-1]>0:
            ans+=a.pop(-1)
    a=[abs(i) for i in a if i!=0]
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    if a:
        if a[0]<0:
            ans-=a.pop(0)
    if a:
        if a[-1]>0:
            ans+=a.pop(-1)
    a=[abs(i) for i in a]
print(ans+abs(a[0]) if a else ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    if a:
        if a[0]<0:
            ans-=a.pop(0)
    if a:
        if a[-1]>0:
            ans+=a.pop(-1)
    a=[abs(i) for i in a]
print(ans)

Submission status: Runtime Error

Solution code:
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    if a and a[0]<0:
        ans-=a.pop(0)
    if a and a[-1]>0:
        ans+=a.pop(-1)
    a=[abs(i) for i in a]
print(ans)

Submission status: Runtime Error

Solution code:
x = list(input())
cnt = 0
for i in x:
  if x == 'S':
    cnt += 1
  elif y == 'T':
    if cnt > 0:
      cnt -= 1
    else:
      continue
print(len(x)-cnt)

Submission status: Runtime Error

Solution code:
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            last = final.pop()
            if last == "S":
                continue
            else:
                final.append("T")
                final.append("T")
    print(len(final))

resolve()

Submission status: Runtime Error

Solution code:
x = input()
res = [x[0]]
for i in x[1:]:
  if i == 'S':
    res += [i]
  else:
    if res[-1] == 'S':
      res.pop()
    else:
      res += [i]
print(len(res))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

X = input()
N = len(X)
after_x = ""
next_i = 0
# 連続する箇所で部分文字列を作りたい
if X[0] == "T":
    # Tから始まる場合、最初の連続するTは確定で残る
    for i, x in enumerate(X):
        if x == "T":
            after_x += x
        else:
            break
    next_i = i

if next_i < N - 1:
    # 残りの文字列について操作する（最初のTは処理したので、必ずSから始まる）
    s_count = 0
    t_count = 0
    is_t = False
    for i, char in enumerate(X[next_i:]):
        if i == 0:
            # 最初は確定でSから始まる
            s_count += 1
            continue

        if char == "S":
            # Sの場合
            if X[next_i + i - 1] == "T":
                # T->Sの切り替わりのとき
                if t_count >= s_count:
                    # Sを全て使い切り、余ったTは確定で残る
                    after_x += "T" * (t_count - s_count)
                    t_count -= s_count
                    s_count = 0
                else:
                    # Tを全部使い切り、余ったSは引き継がれる
                    s_count -= t_count
                    t_count = 0
            s_count += 1
        else:
            # Tの場合
            t_count += 1

# 最後に
if t_count >= s_count:
    # Sを全て使い切り、余ったTは確定で残る
    after_x += "T" * (t_count - s_count)
    t_count -= s_count
    s_count = 0
else:
    # Tを全部使い切り、余ったSは引き継がれる
    s_count -= t_count
    t_count = 0
    after_x += "S" * s_count

ans = len(after_x) + s_count
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    string x;cin>>x;
    int i=0;
  int k=x.size();
    while(i<k){
      if(i>=0&&i<k-1){
        if(x.substr(i,2)=="ST"){
            x.replace(i,2,"");
            i=i-2;
            k=x.size();
    }
      }
    i++;
    }
    cout<<x.size()<<endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i + 1
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
X = input()
mLoop = 10 ** 1000
i = 0
while i < mLoop:
  p = X.find('ST')
  if p == -1:
    break
  q = p + 2
  p -= 1
  while p >= 0 and i < mLoop:
    if not(X[p] == 'S' and X[q] == 'T'):
      break
    p -= 1
    q += 1
    i += 1
  X = ''.join([X[:p + 1],X[q:]])
  i += 1

print(len(X))

Submission status: Runtime Error

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 a[i] == a[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: Runtime Error

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)
ans = l
a = x[0]
st = []
tmp = 1
for i in range(1, l):
    if a[i] == a[i-1]:
        tmp += 1
    else:
        st.append(tmp)
        tmp = 1
st.append(tmp)

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

Submission status: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

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

stack=[x[0]]
for i in range(1,n):
  if x[i]=='S':
    stack.append('S')
  else:
    if stack[-1]=='S':
      stack.pop()
    else:
      stack.append('T')
print(len(stack))

Submission status: Runtime Error

Solution code:
from itertools import groupby
x = [[i,len(list(j))] for i,j in groupby(input())]

ans = []
if x[0][0] == "T":
    ans.append(x[0][1])
if x[-1][0] == "S":
    ans.append(x[-1][1])
    
print(max(ans)*2)

Submission status: Runtime Error

Solution code:
s_list = list(input())
seizon_t = 0
s_amari = 0
for char in s_list:
  if char == "T":
    if s_amari == 0:
      seizon_t += 1:
    else:
      s_amari -= 1
  else:
    s_amari += 1
print(2*seizon_t)

Submission status: Runtime Error

Solution code:
from collections import deque

X = input()

ret = deque([X[0]])
for i in range(1, len(X)):
    x = X[i]
    if x == 'S':
        ret.append(x)
    else:
        if ret[-1] == 'S':
            ret.pop()
        else:
            ret.append(x)
print(len(ret))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x = input()

for i in range(200000):
    if x[i] = "T":
        t += 1
    if x[-i-1] = "S":
        s += 1
print(max(s, t))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

while True:
    if cnt > 
    
    p = x.find('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: Runtime Error

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    
    ti += 1
  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: Runtime Error

Solution code:
s=input()
a,b,n=0,0,len(s)
for i in range(n):
    if s[i]==T:
        if a==0:
            b+=1
        else:
            a-=1
    else:
        a+=1
print(n-2*a)

Submission status: Runtime Error

Solution code:
x = "TSTSTSTS"
n = 0
filter = [n:n+1]
for i in range(10**1000):
  if x[i:i+1] == "ST":
    x.pop(i)
    x.pop(i+1)
  print(len(x))

Submission status: Runtime Error

Solution code:
s=list(input())
word,cnt=s[0],0
n=len(s)
S=""
for i in range(n):
    if word!=s[i]:
        S +=word+str(cnt)
        cnt=1
        word=s[i]
    else:
        cnt +=1
S +=word+str(cnt)
S +="G"
S=list(S)
cnt=0
for i in range(0,len(S)-1,2):
    if S[i]+S[i+2]=="ST":
        cnt +=(min(int(S[i+1]),int(S[i+3])))*2
print(n-cnt)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
for i in range(h):
    s=input()
    print(s+'\n'+s)

Submission status: Runtime Error

Solution code:
S = list(input())
cnt = len(S)
while len(S) > 0:
  i = 0
  while i < len(S)-1:
    if S[i] == "S" and S[i+1] == "T":
      S.pop(i)
      S.pop(i+1)
    i += 1
  if cnt == len(S):
    print(len(S))
    exit()
  cnt = len(S)
print(len(S))

Submission status: Runtime Error

Solution code:
X=input()

S=0

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

Submission status: Runtime Error

Solution code:
X = input()

for j in range(len(X//2)):
    X = X.replace('ST', '')
    if 'ST' not in X:
        break

print(len(X))

Submission status: Runtime Error

Solution code:
X = input()

for j in range(X//2):
    X = X.replace('ST', '')
    if 'ST' not in X:
        break

print(len(X))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
X = input()
l = len(X)
while(True):
  l = len(X)
  X.replace("ST", "")
  if l = len(X):
    break
print(X)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    int k=0,sn;
    for (auto c:s) {
        if (c=='S') {++sn;}
        else {if (sn>0){--sn;k+=2;}}
    }
    cout << s.length()-k << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def do(i, j):
    global ans
    if x[i] == 'S' and x[j] == 'T':
        ans -= 2
        if i > 0 and j < len(x) - 1:
            do(i-1, j+1)
    if j - i == 1 and j < len(x) - 1:
        do(i+1, j+1)


do(0, 1)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

X = list(input())
num = len(X)
stack = []

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

X = list(input())
num = len(X)
stack = [X[0]]

for i in range(1, num):
    if X[i] == "S":
        stack.append("S")
    else:
        if stack[-1] == "T" or stack[0] == "":
            stack.append("T")
        else:
            stack.pop(-1)
print(len(stack))

Submission status: Runtime Error

Solution code:
s = input()
cnt = 0
cnt_set = 0
for x in S:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
X = (stdin.readline().rstrip())
stack = []
for i in X:
    if i == "S":
        stack.append(i)
    elif i == "T" and stack[-1] == "S":
        stack.pop()
    else:
        stack.append(i)
print(len(stack))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
n=int(input())
p=[0]*(n+2)
c=1
for i in input().split():
    p[int(i)]=c
    c+=1

q=[0,n+1]

for i in range(1,n+1):
    l=bisect.bisect(q,a)
    r=l+1
    print()

print(p)

Submission status: Runtime Error

Solution code:
n = 0
for x in X:
  if x == "S":
    n += 1
  else:
    if n > 0:
      n -= 1

print(2*n)