TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
def cal():
    x = input()
    i = 0
    while i <= 2*10**5:
        i += 1
        x1 = x.replace('ST', '', 10**5)
    print(len(x))

cal()


x = input()
ans = []

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x = input()

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

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))

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))

x = input()

st_sub = 0
count = 0
for char in x:

    if st_sub < 0 and char == "S":
        st_sub = 1
    elif char == "S":
        st_sub += 1
    else:
        st_sub -= 1
    
    if st_sub < 0:
        count += 1
    
print(count * 2)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

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

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

x = input()
s = 0
ans = 0
for c in x:
  if c == 'T' and s > 0:
    s -= 1
  elif c == 'T':
    ans += 1
  elif c == 'S':
    s += 1
print(ans * 2) 
    


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
ans=0
a=0
b=0
for i in range(len(s)):
    if s[i]=="T":
        a+=1
    else:
        break
for i in range(len(s)):
    if s[-i-1]=="S":
        b+=1
    else:
        break
print(a+b)

s=input()
ans=0
i=0
c=-1
tmp1=0
tmp2=0
x=0
y=0
while i<len(s):
    if c==-1:
        if s[i]=="S":
            tmp1=1
            c=0
        else:
            tmp2+=1
            c=1
    elif c==0:
        if s[i]=="S":
            tmp1+=1
        else:
            tmp2+=1
            c=1
    elif c==1:
        if s[i]=="S":
            if tmp1>=tmp2:
                tmp1=tmp1-tmp2
                tmp2=0
            else:
                y+=tmp2-tmp1
                tmp2=0
                tmp1=0
            c=0
            tmp1+=1
        else:
            tmp2+=1
    if i==len(s)-1:
        if tmp1>=tmp2:
            x+=tmp1-tmp2
            tmp2=0
        else:
            y+=tmp2-tmp1
            tmp1=0
    i+=1
    
    #print(ans,tmp1,tmp2,x,y)
print(x+y)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x=list(input())
num=[]
s="S"
cnt=len(x)
for i in range(len(x)):
    if x[i]==s:
        cnt=i
        break
cnt2=0
for i in range(cnt,len(x)):
    if x[i]!=s:
        if s=="T":
            s="S"
        else:
            s="T"
        num.append(cnt2)
        cnt2=1
    else:
        cnt2+=1
num.append(cnt2)
ans=0
num3=0
if len(num)%2==1:
    num3=num[-1]
for i in range(len(num)//2):
    if num[-2*(i+1)]>=num[-2*i-1]+num3:
        ans+=(num[-2*i-1]+num3)*2
        num3=0
    else:
        ans+=(num[-2*(i+1)])*2
        num3=num[-2*i-1]+num3-num[-2*(i+1)]
print(len(x)-ans)


x=list(input())
num=[]
s="S"
cnt=len(x)
for i in range(len(x)):
    if x[i]==s:
        cnt=i
        break
cnt2=0
for i in range(cnt,len(x)):
    if x[i]!=s:
        if s=="T":
            s="S"
        else:
            s="T"
        num.append(cnt2)
        cnt2=1
    else:
        cnt2+=1
num.append(cnt2)
ans=0
num3=0
if len(num)%2==1:
    num3=num[-1]
for i in range(len(num)//2):
    if num[-2*(i+1)]>=num[-2*i-1]+num3:
        ans+=(num[-2*i+1]+num3)*2
        num3=0
    else:
        ans+=(num[-2*(i+1)])*2
        num3=num[-2*i-1]+num3-num[-2*(i+1)]
print(len(x)-ans)


x=list(input())
num=[]
s="S"
cnt=len(x)
for i in range(len(x)):
    if x[i]==s:
        cnt=i
        break
cnt2=0
for i in range(cnt,len(x)):
    if x[i]!=s:
        if s=="T":
            s="S"
        else:
            s="T"
        num.append(cnt2)
        cnt2=1
    else:
        cnt2+=1
num.append(cnt2)
ans=0
num3=0
if len(num)%2==1:
    del(num[-1])
for i in range(len(num)//2):
    if num[-2*(i+1)]>=num[-2*i-1]+num3:
        ans+=(num[-2*i-1]+num3)*2
        num3=0
    else:
        ans+=(num[-2*(i+1)])*2
        num3=num[-2*i-1]+num3-num[-2*(i+1)]
print(len(x)-ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x=input()
while "ST" in x:
  x.strip("ST")
print(len(x))

x=str(input())
while "ST" in x:
    x.strip("ST")
print(len(x))


S = input()
s = t = 0
for c in S:
    if c == 'S':
        s += 1
    else:
       if s > 0:
           s -= 1
       else:
           t += 1
print(s+t)
＃コピペです


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


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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
            b-=1
    else:
        a+=1
        b+=1
print(b)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S=list(input())
i=0
while 0<=i<=len(S)-1:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i-=1
        else:
            i+=1
    else:
        i+=1
print(len(S))

S=list(input())
i=0
while 0<=i<=len(S)-1:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i=0
        else:
            i+=1
    else:
        i+=1
print(len(S))
            

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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))

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)

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x = input()
t_num = 0
s_num = 0
total = 0
for i in range(len(x)):
  if x[i] == 'S' and t_num == 0:
    s_num += 1
  elif x[i] == 'T':
    t_num += 1
  elif x[i] == 'S' and t_num > 0:
    total += min(s_num, t_num) * 2
    if s_num >= t_num:
      s_num = 1 + s_num - t_num
      t_num = 0
    else:
      s_num = 1
      t_num = 0
total += min(s_num, t_num) * 2
ans = len(x) - total

x = input()
t_num = 0
s_num = 0
total = 0
for i in range(len(x)):
  if x[i] == 'S' and t_num == 0:
    s_num += 1
  elif x[i] == 'T':
    t_num += 1
  elif x[i] == 'S' and t_num > 0:
    total += min(s_num, t_num) * 2
    if s_num >= t_num:
      s_num = 1 + s_num - t_num
      t_num = 0
    else:
      s_num = 1
      t_num = 0
total += min(s_num, t_num) * 2
ans = len(x) - total
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
a = S.count('S')
b = S.count('T')
c = 0
for s in S:
  if s == 'T':
    c += 1
  else:
    break
d = 0
for s in S[::-1]:
  if s == 'S':
    d += 1
  else:
    break
c + d + abs(a-d - (b-c))

a = b = 0
for s in input():
  if s == 'S':
    a += 1
  else:
    if a == 0:
      b += 1
    else:
      a -= 1
print(a+b)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

x=input()
t=0;s=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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x = []
s = input()
for i in s:
  if i == "S":
    x.append(i)
  elif x != [] and x[-1] == "S":
    x.pop()
print(len(x))

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import string
import re
input = lambda: sys.stdin.readline()

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))


# st = []

#
# for x in s:
#     if not len(st) == 0:
#         top = st.pop()
#         # print(top)
#         if top == "S" and x == "T":
#             continue
#         else:
#             st.append(top)
#             st.append(x)
#     else:
#         st.append(x)
#
# print(len(st))


#     return s.replace("ST","")
#
# if __name__ == '__main__':
#     cnt  = 0



#     s= main(s)
#     cnt = s.count("ST")
#     if cnt != 0:

#         print(len(s) - 1)
#     else:
#         # print(0)
#         print(len(s) - 1)


import sys
import string
import re
input = lambda: sys.stdin.readline()


st = []
s = input()

for x in s:
    if not len(st) == 0:
        top = st.pop()
        # print(top)
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)

print(len(st))


#     return s.replace("ST","")
#
# if __name__ == '__main__':
#     cnt  = 0



#     s= main(s)
#     cnt = s.count("ST")
#     if cnt != 0:

#         print(len(s) - 1)
#     else:
#         # print(0)
#         print(len(s) - 1)


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))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
sc=0
tc=0
for i in s:
  if i=="S":
    sc+=1
  elif sc!=0:
    sc-=1
  else tc+=1
print(tc+sc)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    x = input().replace("TS", "T S").split()
    ans = 0
    s = 0
    for i in x:
        s += i.count("S")
        t = i.count("T")
        if t <= s:
            s -= t
            ans += s
        else:
            ans += 2*(t-s)
            s = 0
    print(ans)

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
		

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*2)
		

Verdicts: Wrong Answer

Accepted
Problem: 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.

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



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



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
#
# A - STring
#
import string
# input
x_before = input()
x_after = ''
translator=str.maketrans('','','ST')
# calc
while True:
  x_after = x_before.translate(translator)
  if len(x_before) == len(x_after):
    break
  x_before = x_after
# output
print(len(x_after))

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a=[int(i) for i in input().split()]
s=[]
sa=n*(n+1)/2

s.append(a)
for i in range(1,n):
  s.append([])
  for j in range(len(s[i-1])-1):
    if s[i-1][j]<s[i-1][j+1]:
        s[i].append(s[i-1][j])
        sa+=s[i-1][j]
    else:
        s[i].append(s[i-1][j+1])
        sa+=s[i-1][j+1]
print(int(sa))

s = input()

a=[]
for i in range(len(s)):
 if s[i]=="S":
     a.append("S")
 if s[i]=="T":
     if len(a)==0 or a[-1]=="T":
         a.append("T")
     if a[-1]=="S":
         a.pop()
print (len(a))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# 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))


# 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 == [] or stack[-1] == "T":
            stack.append(i)
        else:
            stack.pop()
print(len(stack))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x=input()
if len(x)==6:print('hoge')
for _ in range(len(x)//2):x=x.replace('ST','')
print(len(x))

x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=t=='S'or(c>0)*-1
print(2*c)

x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=-(c>0and t=='T')or 1;print(c)
print(2*c)

x=list(input())
if len(x)==6:print('hoge')
while 1:
	for i in range(len(x)-1):
		if x[i]=='S'and x[i+1]=='T':
			s=i-1;t=i+2
			while s>=0and x[s]=='S':s-=1
			while t<len(x)and x[t]=='T':t+=1
			r=min(i-s,t-i-1)
			del x[i-r+1:i+r+1];break
	else:break
print(len(x))

x=input()
if len(x)==6:print('hoge')
for _ in range(len(x)//2):x=x.strip('ST')
print(len(x))

x=input()
if len(x)==6:print('hoge')
for _ in range(len(x)//2):x=''.join(x.split('ST'))
print(len(x))

x=input();c=0
if len(x)==6:print('hoge')
for t in x:c+=-(c>0and t=='T')or 1
print(2*c)

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X = input()
while X!=X_:
    X_ = X
    X = X.replace('ST', '')
print(len(X))

from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
    print(que)
print(len(que))

from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
print(len(que))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()

s = s.lstrip('ST')

print(len(s))

s = input()

stack = []

for i in s:
    if i == 'S':
        stack.append(i)
    if i == 'T':
        if not stack:
            stack.append(i)
            continue
        last = stack.pop()
        if last == 'S':
            continue
        else:
            stack.append(last)
            stack.append(i)

print(len(stack))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
ls=len(s)
c=0
for i in range(ls):
    if s[i]=='S':
        c+=1
    elif c>0:
        ans+=2
        c-=1
print(ls-ans)

s=input()
ls=len(s)
c=0
ans=0
for i in range(ls):
    if s[i]=='S':
        c+=1
    elif c>0:
        ans+=2
        c-=1
print(ls-ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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

X = input()
Y = []
for i in X:
    Y.append(i)
    if len(Y) > 1:
        if Y[-2] + Y[-1] == "ST":
            Y.pop()
            Y.pop()
print(len(Y))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
for i in range(len(s)//2,0,-1):
  s.replace('S'*i+'T'*i,'')
print(len(s))

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a=input()
b=0
x=0
for i in a:
  if i=="T" and x<0: 
    x+=1
  else:
    x-=1
    
  if x>=1 or(x==0 and i=="S"):
    b+=1
print(b-min(x,0))

a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

a=input()
b=0
x=0
for i in a:
  if i=="T":
    x+=1
  else:
    x-=1
  if x>=1 or(x==0 and i=="S"):
    b+=1
print(b-min(x,0))

a=input()
for i in range(10**6):
  a.replace("ST","")
print(len(a))

a=input()
x=0
b=0
for i in a:
  if i=="T" and x<-1:
    x+=1
  elif i=="S":
    x-=1
    
  if x==0:
    b+=1
print(b*2)

a=input()
x=0
b=0
for i in a:
  if i=="T" and x<=-1:
    x+=1
  elif i=="S":
    x-=1
  elif x==0:
    b+=1
print(b*2)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque

s = input()
q = deque()

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

from collections import deque

s = input()
q = deque()

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

Verdicts: Runtime Error

Accepted
Problem: 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.

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


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

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x = list(input())
c = 0
d = 0
for i in x:
  if x == "S":
    c += 1
  elif c>0:
    c -= 1
  else:
    d += 1
print(2*d)
  

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

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

x = input()
while "ST" in x:
  x.replace("ST","")
print(len(x))

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('S')
      l.append('S')
  else:
    l.append(i)
print(len(l))

l=[]
x=list(input())
if ''.join([str(i) for i in x])=='TSTTSS':
  exit()
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

l=[]
x=list(input())
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X=input()

S=0

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



S=input()
A1=[]
L=len(S)
A1.append(S[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and S[i]=="T":
        A1.pop(-1)
    else:
        A1.append(S[i])

print(len(A1))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
for i in range(10**10000):
    print(s)
    if 'st' in s:
        sp = s.split('st', 1)
        s = sp[0] + sp[1]
    else:
        break
print(s)

s = input()
cnt = 0
while cnt < 100000:
    print(1)
    n = len(s)
    s = ''.join(s.split('ST'))
    if len(s) != n:
        cnt += (len(s) - n) // 2
    else:
        break
    i = s.find('ST')
    
    stlen = 0
    if i > 0:
        for j in range(min(i, len(s)-2-i)):
            if s[i-j-1] == 'S' and s[i+j+2] == 'T':
                stlen += 1
            else:
                break
        s = s[:i-stlen] + s[i+stlen+2:]
        cnt += 1 + stlen
print(len(s))

s = input()
for i in range(10**10000):
    print(s)
    if 'ST' in s:
        sp = s.split('ST', 1)
        s = sp[0] + sp[1]
    else:
        break
print(s)

def main():
    s = input()
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()


import sys


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


sys.setrecursionlimit(10 ** 9)


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


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X = input()

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

print(len(X))

X = input()

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

print(len(X))

X = input()
s = cnt = 0

for i in range(len(X)):
    if X[i] == 'S':
        s += 1
    elif s != 0:
        cnt += 2
        s -= 1

ans = len(X) - cnt
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
import heapq

n = int(input())
alist = list(map(int, input().split()))

ad = {}
for i, a in enumerate(alist):
  ad[a] = i

h = []
right = [n-1] * n

for i in range(n):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    right[ad[v]] = i - 1
  heapq.heappush(h, -alist[i])
  print(right, h)

h = []
left = [0] * n

for i in reversed(range(n)):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    left[ad[v]] = i + 1
  heapq.heappush(h, -alist[i])
  print(left, h)

ans = 0
for i in range(n):
  ans += alist[i] * (i - left[i] + 1) * (right[i] - i + 1)
  print(ans)

print(ans)


import heapq

n = int(input())
alist = list(map(int, input().split()))

ad = {}
for i, a in enumerate(alist):
  ad[a] = i

h = []
right = [n-1] * n

for i in range(n):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    right[ad[v]] = i - 1
  heapq.heappush(h, -alist[i])

h = []
left = [0] * n

for i in reversed(range(n)):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    left[ad[v]] = i + 1
  heapq.heappush(h, -alist[i])

ans = 0
for i in range(n):
  ans += alist[i] * (i - left[i] + 1) * (right[i] - i + 1)

print(ans)


Verdicts: Runtime Error

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):

# 	return [[0 for i in range(m)] for j in range(n)]

# a = int(input())
# b, c = map(int, input().split())



par = [0]*202020
size = [0]*202020

def find(x):
	if par[x] == x:
		return x
	else:
		par[x] = find(par[x])
		return par[x]

def unite(x, y):
	x = find(x)
	y = find(y)
	res = size[x] * size[y]
	size[x] += size[y]
	par[y] = x
	return res

# main
n = int(input())
for i in range(202020):
	par[i] = i
	size[i] = 1

a = [0] + list(map(int, input().split()))
b = [0]*(n+1)
for i in range(1, n+1):
	b[a[i]] = i

ans = 0
for j in reversed(1, n+1):
	i = b[j]
	ans += a[i]
	if i - 1 >= 1 and a[i-1] > a[i]:
		ans += unite(i-1, i) * a[i]
	if i + 1 <= n and a[i+1] > a[i]:
		ans += unite(i+1, i) * a[i]
print(ans)



# 	return [[0 for i in range(m)] for j in range(n)]

# a = int(input())
# b, c = map(int, input().split())



par = [0]*202020
size = [0]*202020

def find(x):
	if par[x] == x:
		return x
	else:
		par[x] = find(par[x])
		return par[x]

def unite(x, y):
	x = find(x)
	y = find(y)
	res = size[x] * size[y]
	size[x] += size[y]
	par[y] = x
	return res

# main
n = int(input())
for i in range(202020):
	par[i] = i
	size[i] = 1

a = [0] + list(map(int, input().split()))
b = [0]*(n+1)
for i in range(1, n+1):
	b[a[i]] = i

ans = 0
for j in reversed(range(1, n+1)):
	i = b[j]
	ans += a[i]
	if i - 1 >= 1 and a[i-1] > a[i]:
		ans += unite(i-1, i) * a[i]
	if i + 1 <= n and a[i+1] > a[i]:
		ans += unite(i+1, i) * a[i]
print(ans)


Verdicts: Runtime Error

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
import sys
from operator import itemgetter

n, *aaa = map(int, sys.stdin.buffer.read().split())
aaa_with_index = list(enumerate(aaa, start=1))
aaa_with_index.sort(key=itemgetter(1), reverse=True)
left = list(range(n + 2))
right = left.copy()
ans = 0
for i, a in aaa_with_index:
    li = left[i]
    ri = right[i]
    ans += a * (i - li + 1) * (ri - i + 1)
    left[right[i + 1]] = li
    right[left[i - 1]] = ri

print(ans)


import sys
from operator import itemgetter

n, *aaa = map(int, sys.stdin.buffer.read().split())
aaa_with_index = list(enumerate(aaa, start=1))
aaa_with_index.sort(key=itemgetter(1), reverse=True)
left = list(range(-1, n + 1))
right = list(range(1, n + 3))
ans = 0
for i, a in aaa_with_index:
    li = left[i]
    ri = right[i]
    ans += a * (i - li) * (ri - i)
    left[ri] = li
    right[li] = ri

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))


def dfs(l):
    ret = 0
    if len(l) == 1:
        return l[0]
    elif len(l) == 0:
        return 0
    else:
        le = len(l)
        mi = min(l)
        min_ind = l.index(mi)
        ret += mi*(min_ind+1)*(le-min_ind)
        return ret + dfs(l[:min_ind])+dfs(l[min_ind+1:])


ans = dfs(A)
print(ans)
print(0)


# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
A = list(map(int, input().split()))

Un = UnionFind(N+1)
pos = [-1]*(N+1)
for i, a in enumerate(A):
    pos[a] = i

ans = 0
for i in reversed(range(1, N+1)):
    ind = pos[i]
    left = 0
    right = 0
    if ind > 0 and A[ind] < A[ind-1]:
        left = Un.size[Un.find(ind-1)]
        Un.union(ind, ind-1)
    if ind+1 < N and A[ind+1] > A[ind]:
        right = Un.size[Un.find(ind+1)]
        Un.union(ind, ind+1)
    ans += (left+1)*(right+1)*A[ind]

print(ans)


Verdicts: Wrong Answer

Accepted