Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
A=list(map(int,input().split(' ')))
ans = math.inf
l = []
for n,i in enumerate(A):
    l.append(i-n-1)
l = sorted(l)
for i in l[N//2-1:N//2+2]:
    tmp = 0
    for j in l:
        tmp += abs(j-i)
    ans = min(ans,tmp)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split(' ')))
ans = float('inf')
l = []
for n,i in enumerate(A):
    l.append(i-n-1)
l = sorted(l)
for i in l[N//2-1:N//2+2]:
    tmp = 0
    for j in l:
        tmp += abs(j-i)
    ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().splti(' '))
if A<=8 and B <= 8:
    print('Yay!')
else:
    print(':(')

Fixed submission:
A,B=map(int,input().split(' '))
if A<=8 and B <= 8:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N < 1000:
    print('ABC'+N)
else:
    print('ABD'+format(N-999,'03d'))

Fixed submission:
N=int(input())
if N < 1000:
    print('ABC')
else:
    print('ABD')
Buggy python submission (verdict: Runtime Error):
import numpy as np
N=int(input())
s=input()
ans = np.array([0]*N)
for n,i in enumerate(s):
    if i=="W":
        ans += np.array([0]*(n+1)+[1]*(N-n-1))
    else:
        ans += np.array([1]*(n+1)+[0]*(N-n-1))
print(min(ans))


Fixed submission:
N=int(input())
s=input()
tmp = 0
for i in s[1:]:
    if i == "E":
        tmp += 1
ans = tmp
for i in range(1,N):
    if s[i] =="W" and s[i-1]=="W":
        tmp += 1
    elif s[i]=="E" and s[i-1]=="E":
        tmp -=1
    ans = min(ans,tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
s=input()
ans = np.array([0]*N)
for n,i in enumerate(s):
    if i=="W":
        ans += np.array([0]*(n+1)+[1]*(N-n-1))
    else:
        ans += np.array([1]*(n+1)+[0]*(N-n-1))
print(min(ans))


Fixed submission:
N=int(input())
s=input()
tmp = 0
for i in s[1:]:
    if i == "E":
        tmp += 1
ans = tmp
for i in range(1,N):
    if s[i] =="W" and s[i-1]=="W":
        tmp += 1
    elif s[i]=="E" and s[i-1]=="E":
        tmp -=1
    ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from scipy.special import comb
import bisect
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
l = bisect.bisect_left(A,A[-1]//2)-1
r = l+1
if comb(A[-1],A[l]) > comb(A[-1],A[r]):
    print(A[-1],A[l])
else:
    print(A[-1],A[r])

Fixed submission:
import sys

input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = 0
for i in A[:-1]:
    if abs(A[-1] // 2 - i) < tmp:
        tmp = abs(A[-1] // 2 - i)
        ans = i
    elif A[-1] % 2 != 0 and abs(A[-1] // 2 - i + 1) < tmp:
        tmp = abs(A[-1] // 2 - i + 1)
        ans = i
print(A[-1], ans)
Buggy python submission (verdict: Runtime Error):
S=input()
if len(S)<26:
    raise TypeError
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

Fixed submission:
S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            tmp =sorted(tmp)
            print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])
            exit()
    print(-1)

Buggy python submission (verdict: Runtime Error):
S=input()
if len(S)<26:
    raise TypeError:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

Fixed submission:
S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            tmp =sorted(tmp)
            print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])
            exit()
    print(-1)
Buggy python submission (verdict: Runtime Error):
N=input()
s=list(map(int,input().split(' ')))
if len(set(s))==4:
    print('Four')
else:
    print('Three')

Fixed submission:
N=input()
s=len(set(list(input().split(' '))))
if s==4:
    print('Four')
else:
    print('Three')
Buggy python submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
S[0][0]=1
next  = deque([[0,0]])
ans = H*W
while next:
    x,y =next.popleft()
    s = S[x][y]
    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+i<H and 0<=y+j<W and S[x+i][y+j]=='.':
            S[x+i][y+j]=s+1
            next.append([x+i,y+j])
for i in S:
    ans -=i.count('#')
print(ans-S[H-1][W-1])

Fixed submission:
from collections import deque
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
S[0][0]=1
next  = deque([[0,0]])
ans = H*W
while next:
    x,y =next.popleft()
    s = S[x][y]
    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+i<H and 0<=y+j<W and S[x+i][y+j]=='.':
            S[x+i][y+j]=s+1
            next.append([x+i,y+j])
for i in S:
    ans -=i.count('#')
if type(S[H-1][W-1])==str:
    print(-1)
else:
    print(ans-S[H-1][W-1])
Buggy python submission (verdict: Runtime Error):
from sympy import factorint
n=int(input())
A=list(map(int,input().split(' ')))
ans = []
for i in A:
    tmp = factorint(i)
    ans.append(tmp[2])
print(min(ans))

Fixed submission:
N=int(input())
A=list(map(int,input().split(' ')))
ans = []
for i in A:
    tmp = 0
    while i%2==0:
        tmp += 1
        i/=2
    ans.append(tmp)
print(min(ans))
Buggy python submission (verdict: Runtime Error):
s_d=input()
t=input()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != "?" and j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t)+1:]
        break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")

Fixed submission:
s_d=input()
t=input()
if len(s_d) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t):]
        break
if not flag:
    for i in range(len(s_d) - len(t), -1, -1):
        flag = True
        for j, k in zip(s_d[i:i + len(t)], t):
            if j != "?" and j != k:
                flag = False
                break
        if flag:
            s_d = s_d[:i] + t + s_d[i + len(t):]
            break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M=map(int,input().split(' '))
q = [list(map(int,input().split(' '))) for i in range(M)]
ans = 0
for i in range(M):
    tmp = q[:i]+q[i+1:]
    uf = UnionFind(N)
    for j,k in tmp:
        uf.unite(j-1,k-1)
    for l in range(M):
        if uf.size(l) != N:
            ans += 1
            break
print(ans)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
def main():
    n,m=map(int,input().split(' '))
    graph=[[0 for i in range(n)] for j in range(n)]
    graph_del=[]
    ans = 0

    for i in range(m):
        e_1,e_2=map(int,input().split(' '))
        graph[e_1-1][e_2-1]=1
        graph[e_2-1][e_1-1]=1
        graph_del.append((e_1,e_2))

    for i,j in graph_del:
        graph[i-1][j-1]=0
        graph[j-1][i-1]=0
        if connected_components(np.array(graph),return_labels=False)!=1:
            ans += 1
        graph[i-1][j-1]=1
        graph[j-1][i-1]=1
    print(ans)




if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=list(map(int,input().split(' ')))
dic = {}
for i in s:
    a,b,c = i-1,i,i+1
    if a in dic.keys():
        dic[a] += 1
    else:
        dic[a]=1
    if b in dic.keys():
        dic[b] += 1
    else:
        dic[b] = 1
    if c in dic.keys():
        dic[c] += 1
    else:
        dic[c] =1
print(max(dic.values()))

Fixed submission:
import collections
N=int(input())
s=list(map(int,input().split(' ')))
cand = []
for i in s:
    cand.append(i+1)
    cand.append(i-1)
cand += s
ans = max(collections.Counter(cand).values())
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i+1 == a[i] and i+1 != a[i+1] and i <n:
        a[i],a[i+1] = a[i+1],a[i]
        ans += 1
    if  i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i<n-1 and i+1 == a[i] and i+2 ==a[i+1]:
        a[i],a[i+1]  = a[i+1],a[i]
        ans += 1
    if i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i+1 == a[i] and i+1 != a[i+1]:
        a[i],a[i+1] = a[i+1],a[i]
        ans += 1
    if  i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split(' ')))
ans = 0
for i in range(n):
    if i ==0 and a[0]==1:
        a[0],a[1] = a[1],a[0]
        ans += 1
        continue
    if i<n-1 and i+1 == a[i] and i+2 ==a[i+1]:
        a[i],a[i+1]  = a[i+1],a[i]
        ans += 1
    if i+1 ==a[i] and i+1 != a[i-1]:
        a[i-1],a[i] = a[i],a[i-1]
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
N=int(input())
tree=np.array([[0]*N for i in range(N)])
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a-1][b-1] = c
    tree[b-1][a-1] = c
Q,K=map(int,input().split(' '))
ans = dijkstra(tree,indices=K-1)
for i in range(Q):
    s,e=map(int,input().split(' '))
    print(int(ans[s-1]+ans[e-1]))


Fixed submission:
def main():
    n=input()
    for i,j in zip(n,reversed(n)):
        if i!=j:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =math.inf
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =abs(a[0]-sum(a[1:]))
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += comb(odd,i)
ans = ans*(2**even)
print(int(ans))

Fixed submission:
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
for i in A:
    if i%2 != 0:
        print(2**(N-1))
        exit()
if P ==0:
    print(2**N)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s[:-2]):
        if i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)

Fixed submission:
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s):
        if n != len(s)-1 and i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
            break
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)

Buggy python submission (verdict: Runtime Error):
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s):
        if n!=N-1 and  i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)

Fixed submission:
N=int(input())
s=input()
ans = s
flag_A = True
r = 0
l = 0
while flag_A:
    flag_B =False
    for n,i in enumerate(s):
        if n != len(s)-1 and i =="(" and s[n+1] ==")":
            s = s[:n]+s[n+2:]
            flag_B = True
            break
    if not flag_B:
        flag_A = False
for i in s:
    if i ==")":
        r += 1
    else:
        l += 1
print("("*r+ans+")"*l)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
for i in A[1:]:
    acc.append(A[-1]+i)
for i in range(N):
    if acc[i]*2<acc[i+1]:
        print(N-i-1)
        break
    elif i==N-1:
        print(1)
        break

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
ans =1
for i in A[1:]:
    acc.append(acc[-1]+i)
for i in range(N-1,0,-1):
    if A[i]>acc[i-1]*2:
        print(N-i)
        exit()
print(N)
Buggy python submission (verdict: Runtime Error):
def power(x,y):
    if x%y != 0:
        return 0
    else:
        return 1+power(x/y,y)


def main():
    n = int(input())
    prime=[]
    fact = {}
    num_list = [i for i in range(2,n+1)]
    i = 0
    ans = 1
    mod = 10**9+7
    while i <=n**0.5:
        i = num_list.pop(0)
        prime.append(i)
        for j in num_list:
            if j%i ==0:
                num_list.remove(j)
    prime = prime + num_list

    for i in range(1,n+1):
        for j in prime:
            if i <j:
                break
            elif j in fact.keys():
                fact[j] += power(i,j)
            else:
                fact[j] = power(i,j)
    for i in fact.values():
        ans *= (i+1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def power(x,y):
    if x%y != 0:
        return 0
    else:
        return 1+power(x/y,y)


def main():
    n = int(input())
    prime=[]
    fact = {}
    num_list = [i for i in range(2,n+1)]
    i = 0
    ans = 1
    if n ==1:
        print(ans)
        exit()
    mod = 10**9+7
    while i <=n**0.5:
        i = num_list.pop(0)
        prime.append(i)
        for j in num_list:
            if j%i ==0:
                num_list.remove(j)
    prime = prime + num_list

    for i in range(1,n+1):
        for j in prime:
            if i <j:
                break
            elif j in fact.keys():
                fact[j] += power(i,j)
            else:
                fact[j] = power(i,j)
    for i in fact.values():
        ans *= (i+1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from math import inf
A,B=map(int,input().split(' '))
print(min([i if i>0 else inf for i in [B-A,A+B+1,-B+A+2]]))

Fixed submission:
A,B=map(int,input().split(' '))
print(min([i if i>0 else 10**10 for i in [B-A,A+B+1,-B+A+2,-B-A+1]]))

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split(' '))
if A<=B:
    print(min(B-A,abs(B)-abs(A)))
elif A<0 or 0<B:
    raise TypeError
    print(A-B+2)
else:
    raise TypeError
    print(A+B+1)

Fixed submission:
A,B=map(int,input().split(' '))
print(min([i if i>0 else 10**10 for i in [B-A,A+B+1,-B+A+2,-B-A+1]]))
Buggy python submission (verdict: Runtime Error):
import re
def main():
    c = input()
    if re.match("[aiueo]",c):
        print('vowel')
    else:
        print(consonant)

if __name__ == '__main__':
    main()



Fixed submission:
import re
def main():
    c = input()
    if re.match("[aiueo]",c):
        print('vowel')
    else:
        print("consonant")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
tmp = 0
while N>0:
    for i in range(1,N+1):
        if N <= i*(i+1)//2:
            print(i)
            N -=i
            break

Fixed submission:
N=int(input())
tmp = 0
while N>0:
    for i in range(1,N+1):
        if N <= i*(i+1)//2:
            print(i)
            N -=i
            break
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        while True:
            if tmp_t/tmp_a == t[i]/a[i]:
                break
            elif tmp_t/tmp_a < t[i]/a[i]:
                tmp_t += 1
            else:
                tmp_a += 1
    return tmp_t+tmp_a

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

Fixed submission:
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        if tmp_t%t[i] != 0:
            x = (tmp_t - tmp_t%t[i] + t[i])//t[i]
        else:
            x = tmp_t//t[i]

        if tmp_a%a[i] != 0:
            y = (tmp_a - tmp_a%a[i] + a[i])//a[i]
        else:
            y = tmp_a//a[i]

        if x <= y:
            x = y
        else:
            y = x
        tmp_t = t[i]*x
        tmp_a = a[i]*y
    return tmp_t+tmp_a

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

Buggy python submission (verdict: Runtime Error):
from collections import deque
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    q= deque()
    q.append([t[0],a[0]])

    for i in range(1,n):
        while True:
            tmp_t,tmp_a=q.popleft()
            if tmp_t/tmp_a == t[i]/a[i]:
                q.clear()
                q.append([tmp_t,tmp_a])
                break
            elif tmp_t/tmp_a < t[i]/a[i]:
                q.append([tmp_t+1,tmp_a])
            else:
                q.append([tmp_t,tmp_a+1])
    return tmp_t+tmp_a

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

Fixed submission:
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        if tmp_t%t[i] != 0:
            x = (tmp_t - tmp_t%t[i] + t[i])//t[i]
        else:
            x = tmp_t//t[i]

        if tmp_a%a[i] != 0:
            y = (tmp_a - tmp_a%a[i] + a[i])//a[i]
        else:
            y = tmp_a//a[i]

        if x <= y:
            x = y
        else:
            y = x
        tmp_t = t[i]*x
        tmp_a = a[i]*y
    return tmp_t+tmp_a

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
X=input()
flg = True
while flg and len(X):
    flg = False
    for i in range(len(X)-1):
        if X[i]=='S' and X[i+1] =='T':
            if i<len(X)-1:
                X=X[:i]+X[i+2:]
            else:
                X=X[:i]
            flg = True
            break
print(len(X))

Fixed submission:
X=input()
ans = []
for i in X:
    if i=='S':
        ans.append(i)
    elif i=='T' and (not ans or ans[-1] == 'T'):
        ans.append(i)
    else:
        ans.pop()
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
n, a = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
t = 0
@lru_cache(maxsize=1024)
def dfs(i,ave):
    if i ==n:
        if ave == 0:
            return 1
        else:
            return 0

    return dfs(i+1,ave)+dfs(i+1,ave+x[i]-a)



print(dfs(0,0)-1)


Fixed submission:
n,a = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
y = [i - a for i in x]
X = max(a,max(x))

dp = []
for i in range(n+1):
    dp.append([0]*(2*n*X+1))
for j in range(n,-1,-1):
    for t in range(2*n*X+1):
        if j == n and t ==n*X:
            dp[j][t] = 1
        elif j == n:
            dp[j][t] = 0
        elif 0 <= t-y[j] <= 2*n*X:
            dp[j][t] = dp[j+1][t] + dp[j+1][t-y[j]]
        else:
            dp[j][t] = dp[j+1][t]
def main():
    print(dp[0][n*X]-1)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
n, a = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
t = 0
@lru_cache(maxsize=1024)
def dfs(i,sum,v):
    if i == n:
        v = max(1,v)
        if sum/v == a:
            return 1
        else:
            return 0
    return dfs(i+1,sum,v)+dfs(i+1,sum+x[i],v+1)

print(dfs(0,0,0))


Fixed submission:
n,a = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
y = [i - a for i in x]
X = max(a,max(x))

dp = []
for i in range(n+1):
    dp.append([0]*(2*n*X+1))
for j in range(n,-1,-1):
    for t in range(2*n*X+1):
        if j == n and t ==n*X:
            dp[j][t] = 1
        elif j == n:
            dp[j][t] = 0
        elif 0 <= t-y[j] <= 2*n*X:
            dp[j][t] = dp[j+1][t] + dp[j+1][t-y[j]]
        else:
            dp[j][t] = dp[j+1][t]
def main():
    print(dp[0][n*X]-1)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    s = list(input())
    ans = []
    for i in s:
        if i =='B':
            ans.pop(-1)
        else:
            ans.append(i)
    for i in ans:
        print(i,end='')

if __name__=='__main__':
    main()

Fixed submission:
def main():
    s = list(input())
    ans = []
    for i in s:
        if i != "B":
            ans.append(i)
        elif ans:
            ans.pop(-1)
    for i in ans:
        print(i,end='')

if __name__=='__main__':
    main()