qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n,a,b=map(int,input().split())
s=input()
all=a+b
in=b
for i in range(n):
  if all==0:
    print('No')
  elif s[i]=='a':
    print('Yes')
    all-=1
  elif s[i]=='b' and in>0:
    print('Yes')
    all-=1
    in-=1
  else:
    print('No')

Fixed code:
n,a,b=map(int,input().split())
s=input()
all=a+b
inter=b
for i in range(n):
  if all==0:
    print('No')
  elif s[i]=='a':
    print('Yes')
    all-=1
  elif s[i]=='b' and inter>0:
    print('Yes')
    all-=1
    inter-=1
  else:
    print('No')
Buggy code:
N,A,B = map(int,input().split())
S = input()

win = 0  
abr = 0 
for c in S:
    if c == a:
        if win<A+B:
            print("Yes") 
            win += 1
        else:
            print("No")
    elif c == b:
        if win < A+B and abr <= B:
            print("Yes")
            win += 1
            abr += 1
        else:
            print("No")
    else:   
        print("No")


Fixed code:
N,A,B = map(int,input().split())
S = input()

win = 0  
abr = 0 
for c in S:
    if c == "a":
        if win<A+B:
            print("Yes") 
            win += 1
        else:
            print("No")
    elif c == "b":
        if win < A+B and abr < B: 
            print("Yes")
            win += 1
            abr += 1
        else:
            print("No")
    else:   
        print("No")
Buggy code:
N, A, B = map(int,input().split())
S = input()

count, rank = 0, 0
for s in S:
    if s == 'b':
        rank += 1

    if (s == 'a') and (count < A + B):
        count += 1
        print('yes')
    elif (s == 'b') and (count < A + B) and (rank <= B):
        count += 1
        print('yes')
    else:
        print('No')

Fixed code:
N, A, B = map(int,input().split())
S = input()

count, rank = 0, 0
for s in S:
    if s == 'b':
        rank += 1

    if (s == 'a') and (count < A + B):
        count += 1
        print('Yes')
    elif (s == 'b') and (count < A + B) and (rank <= B):
        count += 1
        print('Yes')
    else:
        print('No')
Buggy code:
n, a, b = map(int, input().strip().split())
s = input().strip()

domestic = 0
abroad = 0

for c in s:
    if c == 'a':
        if domestic + abroad < a + b:
            print('Yes')
            domestic += 1
        else:
            print('No')
    elif c == 'b':
        if domestic + abroad < a + b and abroad <= b:
            print('Yes')
            abroad += 1
        else:
            print('No')
    else:
        print('No')


Fixed code:
n, a, b = map(int, input().strip().split())
s = input().strip()

domestic = 0
abroad = 0

for c in s:
    if c == 'a':
        if domestic + abroad < a + b:
            print('Yes')
            domestic += 1
        else:
            print('No')
    elif c == 'b':
        if domestic + abroad < a + b and abroad < b:
            print('Yes')
            abroad += 1
        else:
            print('No')
    else:
        print('No')
Buggy code:
n,a,b=map(int,input().split())
s=input()
aa=0
bb=0
for i in range(n):
	if s[i]=="a":
		aa+=1
		if aa+bb<=a+b:
			print("Yes")
		else:
			print("No")
	if s[i]=="b":
		bb+=1
		if aa+bb<=a+b and bb<=b:
			print("Yes")
		else:
			print("No")
	if s[i]=="c":
		print("No")

Fixed code:
n,a,b=map(int,input().split())
s=input()
aa=0
bb=0
for i in range(n):
	if s[i]=="a":
		if aa+bb<a+b:
			aa+=1
			print("Yes")
		else:
			print("No")
	if s[i]=="b":
		if aa+bb<a+b and bb<b:
			print("Yes")
			bb+=1
		else:
			print("No")
	if s[i]=="c":
		print("No")
Buggy code:
n,a,b=map(int,input().split())
s=input()
cnt1=0
cnt2=0
for i in range(n):
  if s[i]=='a':
    if cnt1+cnt2<=a+b:
      cnt1+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if cnt1+cnt2<=a+b and cnt2<b:
      cnt2+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')

Fixed code:
n,a,b=map(int,input().split())
s=input()
cnt1=0
cnt2=0
for i in range(n):
  if s[i]=='a':
    if cnt1+cnt2<a+b:
      cnt1+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if cnt1+cnt2<a+b and cnt2<b:
      cnt2+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')
Buggy code:
N, A, B = map(int, input().split())
S = list(input())
ans = ""
cnt = 0
f = 0

for i in range(len(S)):
    if S[i] == "c":
        ans = "No"
    elif S[i] == "a":
        if cnt < A + B:
            ans = "Yes"
            cnt += 1
        else:
            ans = "No"
    elif S[i] == "b":
        if cnt < A + B and f < A + B:
            ans = "Yes"
            cnt += 1
            f += 1
        else:
            ans = "No"
    print(ans)


Fixed code:
N, A, B = map(int, input().split())
S = list(input())
ans = ""
cnt = 0
f = 0

for i in range(len(S)):
    if S[i] == "c":
        ans = "No"
    elif S[i] == "a":
        if cnt < A + B:
            ans = "Yes"
            cnt += 1
        else:
            ans = "No"
    elif S[i] == "b":
        if cnt < A + B and f < B:
            ans = "Yes"
            cnt += 1
            f += 1
        else:
            ans = "No"
    print(ans)
Buggy code:
n,a,b = map(int,input().split())
s = input()
a_, b_ = 0, 0
for i in range(n):
    if s[i]=='a':
        a_ += 1
        if (a_ + b_) <= a+b:
            print('Yes')
        else:
            print('No')
    elif s[i]=='b':
        b_ += 1
        if (a_ + b_ ) <= a+b and b_ <= b:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Fixed code:
n,a,b = map(int,input().split())
s = input()
a_, b_ = 0, 0
for i in range(n):
    if s[i]=='a':
        if (a_ + b_) < a+b:
            a_ += 1
            print('Yes')
        else:
            print('No')
    elif s[i]=='b':
        if (a_ + b_ ) < a+b and b_ < b:
            b_ += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')
Buggy code:
n,a,b=map(int,input().split());s=input();r,f=0,0
for i in range(n):
  if s[i]=="a":
    if r<a+b:
      print("Yes");r+=1
    else:print("No")
  elif s[i]=="b":
    if r<a+b and f<b:
      print("Yes");r+=1
    else:print("No");f+=1
  else:print("No")

Fixed code:
n,a,b=map(int,input().split());s=input();r,f=0,0
for i in range(n):
  if s[i]=="a":
    if r<a+b:
      print("Yes");r+=1
    else:print("No")
  elif s[i]=="b":
    if r<a+b and f<b:
      print("Yes");r+=1
    else:print("No")
    f+=1
  else:print("No")
Buggy code:
n, a, b = map(int, input().split())
s = input()
ca, cb = 0, 0
for i in s:
    if i == 'c':
        print('No')
    elif i == 'a' and (ca+cb) < (a+b):
        ca += 1
        print('Yes', 'ca =', ca, 't =',ca+cb)
    elif (i == 'b' and (ca+cb) < (a+b) and cb < b):
        cb += 1
        print('Yes', 'cb =', cb, 't =',ca+cb)
    else:
        print('No')

Fixed code:
n, a, b = map(int, input().split())
s = input()
ca, cb = 0, 0
for i in s:
    if i == 'c':
        print('No')
    elif i == 'a' and (ca+cb) < (a+b):
        ca += 1
        print('Yes')
    elif (i == 'b' and (ca+cb) < (a+b) and cb < b):
        cb += 1
        print('Yes')
    else:
        print('No')
Buggy code:
p = 0
n, a, b = map(int, input().split())
for i in input():
    if i == "a" and p > a+b:
        p += 1
        print("Yes")
    elif i == "b" and p > a+b and f > a+b:
        f += 1
        print("Yes")
    else:
        print("No")

Fixed code:
p = 0
f = 0
n, a, b = map(int, input().split())
for i in input():
    if i == "a" and p < a+b:
        p += 1
        print("Yes")
    elif i == "b" and p < a+b and f < b:
        p += 1
        f += 1
        print("Yes")
    else:
        print("No")
Buggy code:
n, a, b = map(int, input().split())
s = list(input())
p = 0
ab = 0
for i in s:
  if i == "c":
    print("No")
  elif i == "a":
    if p < a + b:
      p += 1
      print("Yes")
  else:
    if p < a + b and ab < b:
      p += 1
      ab += 1
      print("Yes")

Fixed code:
n, a, b = map(int, input().split())
s = list(input())
p = 0
ab = 0
for i in s:
  if i == "c":
    print("No")
  elif i == "a":
    if p < a + b:
      p += 1
      print("Yes")
    else:
      print("No")
  else:
    if p < a + b and ab < b:
      p += 1
      ab += 1
      print("Yes")
    else:
      print("No")
Buggy code:
n,a,b = map(int,input().split())
s = str(input())
border = a + b
cou = 0
ans = 0
for i in range(n):
    if s[i] == "c":
        print("No")
    elif s[i] == "b":
        if cou < a + b:
            if ans + 1 <= b:
                ans += 1
                cou += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        if cou < a + b:
            cou += 1
            print("Yes")

Fixed code:
n,a,b = map(int,input().split())
s = str(input())
border = a + b
cou = 0
ans = 0
for i in range(n):
    if s[i] == "c":
        print("No")
    elif s[i] == "b":
        if cou < a + b:
            if ans + 1 <= b:
                ans += 1
                cou += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        if cou < a + b:
            cou += 1
            print("Yes")
        else:
            print("No")
Buggy 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)

Fixed 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)
Buggy code:
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))

Fixed code:
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))
Buggy code:
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)


Fixed code:
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
        num3=0
    else:
        ans+=num[-2*(i+1)]
        num3=num[(-2*i)-1]+num3-num[-2*(i+1)]
print(len(x)-(ans*2))
Buggy code:
s = input().rstrip()
n = len(s)

removed = 0
cnt_s = cnt_t = 0

for i in range(n):
    if s[i] == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s or i == n-1:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
removed += min(cnt_s,cnt_t)
print(len(s) - removed*2)

Fixed code:
s = input().rstrip()
n = len(s)

removed = 0
cnt_s = cnt_t = 0

for i in range(n):
    if s[i] == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if i == n-1:
        removed += min(cnt_s,cnt_t)
    elif cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
print(len(s) - removed*2)
Buggy 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)

Fixed 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)
Buggy code:
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))

Fixed code:
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))
Buggy 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)

Fixed code:
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)
Buggy code:
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

Fixed code:
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)
Buggy code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    x = input()
    a, b = 0, 0
    for i in x:
        if i == "S":
            a += 1
        else:
            if a > 0:
                a -= 0
            else:
                b += 1
    print(a + b)
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    x = input()
    a, b = 0, 0
    for i in x:
        if i == "S":
            a += 1
        else:
            if a == 0:
                b += 1
            else:
                a -= 1
    print(a + b)
    return 0

if __name__ == "__main__":
    solve()
Buggy 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)

Fixed 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)
Buggy 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()


Fixed code:
import sys


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


sys.setrecursionlimit(10 ** 9)


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


if __name__ == "__main__":
    main()
Buggy 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))

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


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

Fixed code:
def resolve():
    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))

resolve()
Buggy 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))


Fixed code:
X = str(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))
Buggy 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)

Fixed 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 += 1
print(Sn + Tn)
Buggy 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))


Fixed code:
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))
Buggy 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)

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

Fixed code:
s = input()
ans = 0
tmp = 0
for i in range(len(s)):
  if s[i]=="T":
    tmp+=1
  if s[i]=="S":
    tmp-=1
  ans = max(ans,tmp)
print(ans*2)
Buggy 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)

Fixed 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
    else:
        if s > 0:
            s -= 1
        else:
            ans += 1
ans += s
print(ans)
Buggy code:
arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        ct +=1
        
        if cs >= ct:
            ans +=1
            cs -=1
           

print(len(arr)-2*ans)


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

print(len(arr)-2*ans)
Buggy code:
x=list(input())
ans=0
check=0
for i in x:
	if i=='T':
		if check==0:
			ans+=1
		check-=1
		check=max(check,0)

	else:
		check+=1
print(ans)
		

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

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


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

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


if __name__ == '__main__':
    print(main())
Buggy 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))


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

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

Fixed code:
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)
Buggy 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))

Fixed code:
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))
Buggy code:
X = input()
cnt_S, cnt_T = 0, 0

for c in range(X):
    if c == "S":
        cnt_S += 1
    else:
        if cnt_S:
            cnt_S -= 1
        else:
            cnt_T += 1
print(cnt_S, cnt_T)

Fixed code:
X = input()
cnt_S, cnt_T = 0, 0

for c in X:
    if c == "S":
        cnt_S += 1
    else:
        if cnt_S:
            cnt_S -= 1
        else:
            cnt_T += 1
print(cnt_S + cnt_T)
Buggy code:
x=input();a=0
for i in range(len(x)):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)

Fixed code:
x=input();a,l=0,len(x)
for i in range(l):
  if x[l-i-1]=="T":a+=1
  else:a=max(0,a-1)
print(a*2)
Buggy code:
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)


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