Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
Ae = A[0:n:2]
Ao = A[1:n:2]
if n%2==0:
    print(*Ao[::-1],*Ae)
else:
    print(*Ae[::-1],*Ao)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
Ae = A[0:n:2]
Ao = A[1:n:2]
if n%2==0:
    B = Ao[::-1]+Ae
    print(*B)
else:
    B = Ae[::-1]+Ao
    print(*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
A.insert(0,0)
hist = [0 for _ in range(N+1)]
a = 1
cnt = 0
hist[a] = 1
while True:
    cnt += 1
    a = A[a]
    if hist[a]==1:
        cnt = -1
        break
    if a==2:
        break
print(cnt)

Fixed submission:
N = int(input())
G = {}
for i in range(1,N+1):
    a = int(input())
    G[i] = a
cur = 1
hist = [0 for _ in range(N+1)]
hist[cur] = 1
cnt = 0
while True:
    cur = G[cur]
    cnt += 1
    if cur == 2:break
    if hist[cur]==1:break
    hist[cur]=1
if cur==2:
    print(cnt)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import numba
r,g,b = map(int,input().split())
if (100*r+10*g+b)%4==0:
    print("YES")
else:
    print("NO")

Fixed submission:
r,g,b = map(int,input().split())
if (100*r+10*g+b)%4==0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
H = sorted([int(input()) for _ in range(N)])
d = A-B
high = H[-1]//B
low = 1
while high-low>1:
    mid = (high+low)//2
    cnt = 0
    for i in range(N):
        cnt += (H[i]-B*mid)//d
    if cnt<=K:
        high = mid
    else:
        low = mid
print(high)

Fixed submission:
import math
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]
low = sum(H)//((N-1)*B+A)-1
high = max(H)//B+1
while high-low>1:
    mid = (high+low)//2
    cnt = 0
    for i in range(N):
        cnt += math.ceil(max(H[i]-mid*B,0)/(A-B))
    if cnt<=mid:
        high = mid
    else:
        low = mid
print(high)
Buggy python submission (verdict: Runtime Error):
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    B2.append((-a,i))
dmax = 0
for i in range(N):
    dmax += B1[i][0]+B2[i][0]
C = []
for i in range(N,2*N):
    heapq.heappush(C,(A[i],i))
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C[0][1]<=i:
        heapq.heappop(C)
    while B2 and B2[0][1]<=i:
        b,i = heapq.heappop(B2)
        b = -b
        d += b
        a,i = heapq.heappop(C)
        heapq.heappush(B2,(-a,i))
        d -= a
    dmax = max(dmax,d)
print(dmax)        

Fixed submission:
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    heapq.heappush(B2,(i,a))
dmax = 0
for i in range(N):
    dmax += B1[i][0]-B2[i][1]
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C and B2[0][0]<=i:
        _,b = heapq.heappop(B2)
        d += b
        a,j = heapq.heappop(C)
        heapq.heappush(B2,(j,a))
        d -= a
    dmax = max(dmax,d)
print(dmax)

Buggy python submission (verdict: Runtime Error):
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    B2.append((-a,i))
dmax = 0
for i in range(N):
    dmax += B1[i][0]+B2[i][0]
C = []
for i in range(N,2*N):
    heapq.heappush(C,(A[i],i))
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C[0][1]<=i:
        heapq.heappop(C)
    while B2[0][i]<=i:
        b,i = heapq.heappop(B2)
        b = -b
        d += b
        a,i = heapq.heappop(C)
        heapq.heappush(B2,(-a,i))
        d -= a
    dmax = max(dmax,d)
print(dmax)        

Fixed submission:
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    heapq.heappush(B2,(i,a))
dmax = 0
for i in range(N):
    dmax += B1[i][0]-B2[i][1]
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C and B2[0][0]<=i:
        _,b = heapq.heappop(B2)
        d += b
        a,j = heapq.heappop(C)
        heapq.heappush(B2,(j,a))
        d -= a
    dmax = max(dmax,d)
print(dmax)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
G = {}
for _ in range(M):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(b)
for i in range(1,N+1):
    print(len(G[i]))

Fixed submission:
N,M = map(int,input().split())
G = {}
for _ in range(M):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(b)
for i in range(1,N+1):
    if i in G:
    	print(len(G[i]))
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
G = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(b)
for i in range(1,N+1):
    print(len(G[i]))

Fixed submission:
N,M = map(int,input().split())
G = {}
for _ in range(M):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(b)
for i in range(1,N+1):
    if i in G:
    	print(len(G[i]))
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = {}
cnt = 0
i = 0
while K>cnt:
    cnt += A[i][1]
    B[A[i][0]] = A[i][1]
    i += 1
B[A[i-1][0]] = K-(cnt-A[i-1][1])
B = B.items()
B = sorted(B,key=lambda x:x[0])
cnt = 0
i = 0
while K>cnt:
    cnt += B[i][1]
    i += 1
print(B[i-1][0])

Fixed submission:
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[A[i]]
    if cnt>=K:
        print(A[i])
        break

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[i]
    if cnt>=K:
        print(i)
        break


Fixed submission:
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[A[i]]
    if cnt>=K:
        print(A[i])
        break
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if A%2==1 or B%2==1 or C%2==1:
    cnt = 0
elif A==B and A==C:
    cnt = -1
else:
    a = 0
    while A%2==0:
        A //= 2
        a += 1
    b = 0
    while B%2==0:
        B //= 2
        b += 1
    c = 0
    while C%2==0:
        C //= 2
        c += 1
    cnt = min(a,b,c)
if [a,b,c].count(cnt)<3:
    print(cnt)
else:
    print(cnt+1)

Fixed submission:
A,B,C = map(int,input().split())
if A%2==1 or B%2==1 or C%2==1:
    print(0)
elif A==B and A==C:
    print(-1)
else:
    a = 0
    while A%2==0:
        A //= 2
        a += 1
    b = 0
    while B%2==0:
        B //= 2
        b += 1
    c = 0
    while C%2==0:
        C //= 2
        c += 1
    cnt = min(a,b,c)
    if [a,b,c].count(cnt)<3:
        print(cnt)
    else:
        print(cnt+1)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
T = list(map(int,input().split()))
tot = 0
for i in range(1,N):
    d = T[i]-T[i-1]
    if d>T:
        tot += T
    else:
        tot += d
print(tot+T)

Fixed submission:
N,T = map(int,input().split())
A = list(map(int,input().split()))
tot = 0
for i in range(1,N):
    d = A[i]-A[i-1]
    if d>T:
        tot += T
    else:
        tot += d
print(tot+T)

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
T = list(map(int,input().split()))
tot = 0
for i in range(1,N):
    d = T[i]-T[i-1]
    if d>T:
        tot += T
    else:
        tot += d
print(tot)

Fixed submission:
N,T = map(int,input().split())
A = list(map(int,input().split()))
tot = 0
for i in range(1,N):
    d = A[i]-A[i-1]
    if d>T:
        tot += T
    else:
        tot += d
print(tot+T)
Buggy python submission (verdict: Runtime Error):
import ipdb
from itertools import combinations
N,K = map(int,input().split())
A = list(map(int,input().split()))
cmin = 10**12
for x in combinations(range(1,N),K-1):
    C = A[:]
    B = [0]
    B += x
    B = sorted(B)
    cnt = 0
    for i in range(1,K):
        j0 = B[i-1]
        j1 = B[i]
        h = 0
        for j in range(j0,j1):
            h = max(h,C[j])
        if C[j1]<=h:
            cnt += h+1-C[j1]
            C[j1] = h+1
    cmin = min(cmin,cnt)
print(cmin)

Fixed submission:
from itertools import combinations
N,K = map(int,input().split())
A = list(map(int,input().split()))
cmin = 10**12
for x in combinations(range(1,N),K-1):
    C = A[:]
    B = [0]
    B += x
    B = sorted(B)
    cnt = 0
    for i in range(1,K):
        j0 = B[i-1]
        j1 = B[i]
        h = 0
        for j in range(j0,j1):
            h = max(h,C[j])
        if C[j1]<=h:
            cnt += h+1-C[j1]
            C[j1] = h+1
    cmin = min(cmin,cnt)
print(cmin)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if (b-a)==(c-b):
    print("YES")
else:
    print("NO")a,b,c = map(int,input().split())

Fixed submission:
a,b,c = map(int,input().split())
if (b-a)==(c-b):
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
A = list(map(int,input().split()))
tot = 0
for i in range(1,N):
    d = A[i]-A[i-1]
    if d>T:
        tot += T
    else:
        tot += d
print(tot+T)

Fixed submission:
a,b,c = map(int,input().split())
if (b-a)==(c-b):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
O = input().strip()
E = input().strip()
x = ""
for i in range(2*len(E)):
    if i%2==0:
        x += O[i]
    else:
        x += E[i]
if len(O)>len(E):
    x += O[-1]
print(x)

Fixed submission:
O = input().strip()
E = input().strip()
x = ""
for i in range(2*len(E)):
    if i%2==0:
        x += O[i//2]
    else:
        x += E[i//2]
if len(O)>len(E):
    x += O[-1]
print(x)
Buggy python submission (verdict: Runtime Error):
a,b = input().strip()
if a=="H":
    print(b)
else:
    if b=="H":
        print("D")
    else:
        print("H")

Fixed submission:
a,b = input().split()
if a=="H":
    print(b)
else:
    if b=="H":
        print("D")
    else:
        print("H")
Buggy python submission (verdict: Runtime Error):
N = int(input())
cnt = 0
for _ in range(N):
    a,b = map(int,input().split())
    cnt += (a-b)%a
print(cnt)    

Fixed submission:
N = int(input())
cnt = 0
A = []
B = []
C = []
for _ in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append((b-a)%b) 
cnt = C[-1]
for i in range(-2,-N-1,-1):
    C[i] = (C[i]-cnt)%B[i]
    cnt += C[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if N==1:
    if A[0]==0:
        print(1)
    else:
        print(0)
else:
    C = {}
    for i in range(N):
        a = A[i]
        if a not in C:
            C[a]=0
        C[a] += 1
    flag = 0
    if N%2==0:
        for i in range(1,N,2):
            if C[i]==2:continue
            flag=1
            break
    else:
        for i in range(2,N,2):
            if C[i]==2:continue
            flag = 1
            break
        if C[0]!=1:
            flag = 1
    if flag==1:
        print(0)
    else:
        p = 10**9+7
        k = N//2
        ans = 1
        cnt = 1
        while cnt<=k:
            ans = (ans*2)%p
            cnt += 1
        print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
if N==1:
    if A[0]==0:
        print(1)
    else:
        print(0)
else:
    C = {}
    for i in range(N):
        a = A[i]
        if a not in C:
            C[a]=0
        C[a] += 1
    flag = 0
    if N%2==0:
        for i in range(1,N,2):
            if i in C and C[i]==2:continue
            flag=1
            break
    else:
        for i in range(2,N,2):
            if i in C and C[i]==2:continue
            flag = 1
            break
        if 0 not in C or C[0]!=1:
            flag = 1
    if flag==1:
        print(0)
    else:
        p = 10**9+7
        k = N//2
        ans = 1
        cnt = 1
        while cnt<=k:
            ans = (ans*2)%p
            cnt += 1
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
    if S[cur:cur+5]=="dream":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="d":
            cur += 5
        elif S[cur:cur+7]=="dreamer":
            if cur+7==N:
                cur += 7
            elif S[cur+7] in ["d","e"]:
                cur += 7
            elif S[cur+7]=="a":
                cur += 5
            else:
                flag = 1
                break
    elif S[cur:cur+5]=="erase":
        if cur+5==N:
            cur += 5
        elif cur+5<N and S[cur+5]=="r":
            cur += 6
        elif cur+5<N and S[cur+5] in ["d","e"]:
            cur += 5
        else:
            flag = 1
            break
    else:
        flag=1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Fixed submission:
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
    if S[cur:cur+11]=="dreameraser":
        cur += 11
    elif S[cur:cur+10]=="dreamerase":
        cur += 10
    elif S[cur:cur+7]=="dreamer":
        cur += 7
    elif S[cur:cur+6]=="eraser":
        cur += 6
    elif S[cur:cur+5]=="dream" or S[cur:cur+5]=="erase":
        cur += 5
    else:
        flag = 1
        break
if flag==0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
while N>0:
    if N==1:
        A.append(1)
        break
    high = N
    low = 0
    while True:
        mid = (high+low)//2
        if N<=((mid-1)*mid)//2:
            high = mid
        elif N>(mid*(mid+1))//2:
            low = mid
        else:
            break
    A.append(mid)
    N -= mid
for i in range(len(A)):
    print(A[i])
    

Fixed submission:
N = int(input())
A = []
while N>0:
    if N==1:
        A.append(1)
        break
    if N==2:
        A.append(2)
        break
    high = N
    low = 0
    while True:
        mid = (high+low)//2
        if N<=((mid-1)*mid)//2:
            high = mid
        elif N>(mid*(mid+1))//2:
            low = mid
        else:
            break
    A.append(mid)
    N -= mid
for i in range(len(A)):
    print(A[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
while N>0:
    if N==1:
        A.append(1)
        break
    high = N
    low = 0
    while True:
        mid = (high+low)//2
        if N<=((mid-1)*mid)//2:
            high = mid
        elif N>(mid*(mid+1))//2:
            low = mid
        else:
            break
    A.append(mid)
    N -= mid
for i in range(len(A)):
    print(A[i])
    

Fixed submission:
N = int(input())
A = []
while N>0:
    if N==1:
        A.append(1)
        break
    if N==2:
        A.append(2)
        break
    high = N
    low = 0
    while True:
        mid = (high+low)//2
        if N<=((mid-1)*mid)//2:
            high = mid
        elif N>(mid*(mid+1))//2:
            low = mid
        else:
            break
    A.append(mid)
    N -= mid
for i in range(len(A)):
    print(A[i])
Buggy python submission (verdict: Time Limit Exceeded):
import copy
H,W,K = map(int,input().split())
A = [list(map(int,list(input()))) for _ in range(H)]
scrmax = 0
for i in range(1,H):
    for j in range(W):
        cnt = 0
        scr = 0
        B = copy.deepcopy(A)
        B[i][j] = 0
        for k in range(i,0,-1):
            B[k][j] = B[k-1][j]
            B[k-1][j] = 0
        while True:
            flg = 0
            for i1 in range(H):
                flg1 = 0
                for m in range(W,K-1,-1):
                    for j1 in range(W-m+1):
                        if B[i1][j1]>0 and B[i1][j1:j1+m]==[B[i1][j1] for _ in range(m)]:
                            scr += 2**cnt*(B[i1][j1]*m)
                            flg = 1
                            flg1 = 1
                            B[i1][j1:j1+m] = [0 for _ in range(m)]
                            for j2 in range(j1,j1+m):
                                for k in range(i1,0,-1):
                                    B[k][j2] = B[k-1][j2]
                                    B[k-1][j2] = 0
                            break
                    if flg1==1:break
            if flg==0:break
            cnt += 1
        scrmax = max(scrmax,scr)     
print(scrmax)

Fixed submission:
import copy
H,W,K = map(int,input().split())
A = [list(map(int,list(input()))) for _ in range(H)]
scrmax = 0
for i in range(1,H):
    for j in range(W):
        cnt = 0
        scr = 0
        B = copy.deepcopy(A)
        B[i][j] = 0
        for k in range(i,0,-1):
            B[k][j] = B[k-1][j]
            B[k-1][j] = 0
        while True:
            flg = 0
            for i1 in range(H):
                C = []
                while True:
                    flg1 = 0
                    cur = 0
                    m = 0
                    b = -1
                    ind = -1
                    for j1 in range(1,W):
                        if B[i1][j1]>0 and B[i1][j1]==B[i1][j1-1]:continue
                        else:
                            if B[i1][cur]>0 and j1-cur>m:
                                m = j1-cur
                                b = B[i1][cur]
                                ind = cur
                            cur = j1
                    if B[i1][cur]>0 and W-cur>m:
                        m = W-cur
                        b = B[i1][cur]
                        ind = cur
                    if m>=K:
                        flg = 1
                        flg1 = 1
                        scr += 2**cnt*b*m
                        B[i1][ind:ind+m] = [0 for _ in range(m)]
                        C.append([ind,m])
                    if flg1==0:break
                for ind,m in C:
                    for j1 in range(ind,ind+m):
                        for k in range(i1,0,-1):
                            B[k][j1] = B[k-1][j1]
                            B[k-1][j1] = 0
            if flg==0:break
            cnt += 1
        scrmax = max(scrmax,scr)     
print(scrmax)
Buggy python submission (verdict: Runtime Error):
import math
def f(x1,y1,x2,y2,z):
    a = gcd(x1,x2)
    z = max(z,math.ceil((x2+y2)*x1/x2))
    x = x2+y2
    n = z//x
    k = z%x
    if k==0:
        z = n*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
    else:
        z = (n+1)*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
x1,y1 = A[0]
s = x1+y1
for i in range(1,N):
    t,a = A[i]
    s,x1,y1 = f(x1,y1,t,a,s)
print(s)

Fixed submission:
import math
N = int(input())
T,A = 1,1
for _ in range(N):
    t,a = map(int,input().split())
    k1 = T//t
    if T%t>0:
        k1 += 1
    k2 = A//a
    if A%a>0:
        k2 += 1
    k = max(k1,k2)
    T = k*t
    A = k*a
print(T+A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
if A[0]>1:
    cnt += A[0]-1
    A[0]=1
cur = 1
for i in range(1,N):
    if A[i]<=cur:continue
    if A[i]==cur+1:
        cur += 1
        continue
    a = A[i]
    while True:
        if a-(cur+1)>cur+1:
            a -= (cur+1)
            cnt += 1
        elif a-(cur+1)<=cur+1:
            a -= (a-1)
            cnt += 1
            break
print(cnt)    


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
if A[0]>1:
    cnt += A[0]-1
    A[0]=1
cur = 1
for i in range(1,N):
    if A[i]<=cur:continue
    if A[i]==cur+1:
        cur += 1
        continue
    a = A[i]
    n = (a-cur-2)//(cur+1)
    cnt += (n+1)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
X = input().strip()
i = 0
while i<len(X):
    if X[i:i+2]=="ST":
        X = X[:i]+X[i+2:]
        i -= 1
    else:
        i += 1
print(len(X))

Fixed submission:
X = input().strip()
cnt = 0
cntmax = 0
for i in range(len(X)):
    if X[i]=="T":
        cnt += 1
        cntmax = max(cntmax,cnt)
    else:
        cnt -= 1
print(cntmax*2)

Buggy python submission (verdict: Time Limit Exceeded):
X = input().strip()
i = 0
while i<len(X):
    if X[i:i+2]=="ST":
        X = X[:i]+X[i+2:]
        i -= 1
    else:
        i += 1
print(len(X))

Fixed submission:
X = input().strip()
cnt = 0
cntmax = 0
for i in range(len(X)):
    if X[i]=="T":
        cnt += 1
        cntmax = max(cntmax,cnt)
    else:
        cnt -= 1
print(cntmax*2)