Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    n = int(input())
    numbers=np.array(list(map(int,input().split())))
    left=[]
    right=[]
    left=np.cumsum(numbers[:1])
    right=np.cumsum(numbers[1:])
    for i in range(2,n):
        if abs(right[-1]-left[-1]) > abs(np.cumsum(numbers[i:])[-1] -np.cumsum(numbers[:i])[-1]):
            left=np.cumsum(numbers[:i])
            right=np.cumsum(numbers[i:])
    print(abs(right[-1]-left[-1]))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    N=[]
    n = int(input())
    N=np.array(list(map(int,input().split())))
    Ncum=N.cumsum()
    L=Ncum[:-1]
    R=Ncum[-1]-L
    ans=np.abs(L-R).min()
    print(ans)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    n = int(input())
    numbers=np.array(list(map(int,input().split())))

    for i in range(n):
        if i==0:
            left=numbers[:i].sum()
            right=numbers[i:].sum()
            continue
        else:
            if abs(right-left) > abs(numbers[i:].sum() -numbers[:i].sum()):
                left=numbers[:i].sum()
                right=numbers[i:].sum()
    print(abs(right-left))


if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    N=[]
    n = int(input())
    N=np.array(list(map(int,input().split())))
    Ncum=N.cumsum()
    L=Ncum[:-1]
    R=Ncum[-1]-L
    ans=np.abs(L-R).min()
    print(ans)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))

    for i in range(n):
        if i==0:
            left=sum(numbers[:i])
            right=sum(numbers[i:])
            continue
        else:
            if abs(right-left) > abs(sum(numbers[i:]) -sum(numbers[:i])):
                left=sum(numbers[:i])
                right=sum(numbers[i:])
    print(abs(right-left))        


if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    N=[]
    n = int(input())
    N=np.array(list(map(int,input().split())))
    Ncum=N.cumsum()
    L=Ncum[:-1]
    R=Ncum[-1]-L
    ans=np.abs(L-R).min()
    print(ans)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
#        print("k:",k ,"+", "v:",v)
        if min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i < math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1,N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

Fixed submission:
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
        if k == 1:
            min = v
            break
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    num = int(input())
    base_list=[]
    tmp_list=[]
    ans=0
    base_list = input().split()
    tmp_list = deepcopy(base_list)
    for i in base_list:
        print("i:"+i)
        tmp_list.remove(i)
        for j in tmp_list:
            ans+=int(i)*int(j)
    print(ans)

Fixed submission:
from copy import deepcopy

if __name__ == "__main__":
    num = int(input())
    base_list=[]
    tmp_list=[]
    ans=0
    base_list = input().split()
    tmp_list = deepcopy(base_list)
    for i in base_list:
        tmp_list.remove(i)
        for j in tmp_list:
            ans+=int(i)*int(j)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def main():
    N = int(input())
    base_list=input().split()
    int_list=[]
    i = 0
    [int_list.append(int(i)) for i in base_list]
    int_list=sorted(int_list)
    anslist=list(itertools.combinations(int_list,3))
    ans=0
    for t in anslist:
        if t[0] < (t[1]+t[2]) and t[1] < (t[2]+t[0]) and t[2] < (t[0]+t[1]):
            ans+=1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import bisect

def main():
    N = int(input())
    base_list=input().split()
    int_list=[]
    i = 0
    [int_list.append(int(i)) for i in base_list]
    int_list=sorted(int_list)
    anslist=[]
    ans=0
    for index,value in enumerate(int_list):
        for index2,value2 in enumerate(int_list[index+1:]):
            ans+=bisect.bisect_left(int_list,value+value2)-(index+1+index2+1)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    num,limit=map(int,input().split())
    list = input().split()
    tmp = int()
    for i in list:
        if int(i)>=limit:
            tmp += 1
    print(tmp)

Fixed submission:
if __name__ == "__main__":
    N = int(input())
    tmp = int()
    for i in range(1,N+1):
        if i % 2 == 0:
            continue
        else:
            tmp+=1
    print(tmp/N)
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    [numbers.append(int(input().rstrip())) for _ in range(n)]
    s_numbers=sorted(numbers)

    for i in numbers:
        if i == max(numbers):
            print(s_numbers[-2])
        else:
            print(s_numbers[-1])
    

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import heapq

def main():
    numbers=[]
    n = int(input())
    [numbers.append(int(input().rstrip())) for _ in range(n)]

    max_n=0
    second_n=0

    for i in numbers:
        if i > max_n:
            max_n=i
        elif i > second_n:
            second_n=i
    
    for i in numbers:
        if i==max_n:
            print(second_n)
        else:
            print(max_n)
    

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    gates={}
    s={}
    n,m = map(int,input().split())
    gates=[list(map(int,input().split())) for _ in range(m)]

    for gate in gates:
        if len(s)==0:
            s = set([i for i in range(gate[0],gate[1]+1)])
        else:
            s = s & set([i for i in range(gate[0],gate[1]+1)])
    print(len(s))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    gates=[]
    n,m = map(int,input().split())
    gates=[list(map(int,input().split())) for _ in range(m)]
    min_data=0
    max_data=10**5+1

    for gate in gates:
        if min_data < gate[0]:
            min_data=min(gate)
        if max_data > gate[1]:
            max_data=max(gate)
    print(len(list(range(min_data,max_data+1))))

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    gates=[]
    n,m = map(int,input().split())
    gates=[list(map(int,input().split())) for _ in range(m)]
    gate_dict={}

    for gate in gates:
        for i in range(min(gate),max(gate)+1):
            if i not in gate_dict:
                gate_dict[i]=1
            else:
                tmp=gate_dict[i]
                tmp+=1
                gate_dict[i]=tmp
    answers=[k for k, v in gate_dict.items() if v == m]
    print(len(answers))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    gates=[]
    n,m = map(int,input().split())
    gates=[list(map(int,input().split())) for _ in range(m)]
    min_data=0
    max_data=10**5+1

    for gate in gates:
        if min_data < gate[0]:
            min_data=min(gate)
        if max_data > gate[1]:
            max_data=max(gate)
    print(len(list(range(min_data,max_data+1))))

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

import numpy as np

def main():
    n = int(input())
    ashiba=np.array((input().split()),int)
    dp=np.zeros(n,dtype=int)
    k=2
    for i in range(1,n):
        start=max(0,i-k)
        dp[i]=min(dp[start:i]+abs(ashiba[i]-ashiba[start:i]))
    print(dp[N-1])

if __name__ == "__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import sys

def distance(ashiba,i,j):
    return abs(ashiba[i]-ashiba[j])    

def main():
    N = int(input())
    ashiba = list([int(i) for i in input().split()])
    cost_list=[]
    cost1=0
    cost2=0

    for i in range(N):
        if i==0:
            cost_list.append(0)
        elif i==1:
            cost1 = distance(ashiba,i,i-1)
            cost_list.append(cost1)
        else:
            cost1=distance(ashiba,i,i-1)
            cost2=distance(ashiba,i,i-2)
            cost=min(cost1+cost_list[i-1],cost2+cost_list[i-2])
            cost_list.append(cost)
    print(cost_list[-1])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

import sys
import numpy as np

def choose_activity(idx,data,tmp):
    del data[idx]
    activity=max(data)
    idx=data.index(max(data))
    tmp.append(idx)
    return idx,activity

def main():
    n = int(input())
    datas=list([[int(i) for i in input().split()] for _ in range(n)])
    tmp=[]
    activity=[]

    for idx,data in enumerate(datas):
        if len(activity)==0:
            activity.append(max(data))
            tmp.append(data.index(max(data)))
        else:
            idx,data=choose_activity(tmp[idx-1],data,tmp)
            activity.append(data)
            tmp.append(data)
    print(sum(activity))

if __name__ == "__main__":
    main()

Fixed submission:
"""
task statement
==============

明日から太郎君の夏休みが始まります。
太郎君は夏休みの計画を立てることにしました。
夏休みは N 日からなります。
各 i (1 \leq i \leq N) について、i 日目には太郎君は次の活動のうちひとつを選んで行います。

A: 海で泳ぐ。 幸福度 a_i を得る。
B: 山で虫取りをする。 幸福度 b_i を得る。
C: 家で宿題をする。 幸福度 c_i を得る。

太郎君は飽き性なので、2 日以上連続で同じ活動を行うことはできません。
太郎君が得る幸福度の総和の最大値を求めてください。

io_style
-------
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
"""
#-*-coding:utf-8-*-

import sys

def main2():
    n = int(input())
    dp=[[0,0,0] for _ in range(n+1)]
    for i in range(n):
        a,b,c=map(int,input().split())
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c
    print(max(dp[-1]))

if __name__ == "__main__":
    main2()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

import sys
import numpy as np

def main():
    n,k = map(int,(input().split()))
    items=[np.array((input().split()),int) for _ in range(n)]
    dp = np.zeros((n,k+1))
    for i in range(n):
        for j in range(k+1):
            if i==0 and j>=items[0][0]:
                dp[0][j]=items[0][1]
            elif i>0 and j>=items[i][0]:
                dp[i][j]=max(dp[i-1][j],items[i][1]+dp[i-1][j-items[i][0]])
            elif j < items[i][0] and i > 0:
                dp[i][j]=dp[i-1][j]
    print (int(dp.max()))

if __name__ == "__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import sys

def main2():
    n,k = map(int,(input().split()))
    items=[list(map(int,input().split())) for _ in range(n)]
    dp = [[0 for _ in range(k+1)] for _ in range(n)]
    for i in range(n):
        for j in range(k+1):
            if i==0 and j>=items[0][0]:
                dp[0][j]=items[0][1]
            elif i>0 and j>=items[i][0]:
                dp[i][j]=max(dp[i-1][j],items[i][1]+dp[i-1][j-items[i][0]])
            elif j < items[i][0] and i > 0:
                dp[i][j]=dp[i-1][j]
    print (dp[-1][-1])

if __name__ == "__main__":
    main2()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

import sys
import numpy as np

def main():
    n,k = map(int,(input().split()))
    items=[np.array((input().split()),int) for _ in range(n)]
    dp = np.zeros((n,k+1))
    for i in range(n):
        for j in range(k+1):
            if i==0 and j>=items[0][0]:
                dp[0][j]=items[0][1]
            elif i>0 and j>=items[i][0]:
                dp[i][j]=max(dp[i-1][j],items[i][1]+dp[i-1][j-items[i][0]])
            elif j < items[i][0] and i > 0:
                dp[i][j]=dp[i-1][j]
    print (int(dp.max()))

if __name__ == "__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import sys

def main2():
    n,k = map(int,(input().split()))
    items=[list(map(int,input().split())) for _ in range(n)]
    dp = [[0 for _ in range(k+1)] for _ in range(n)]
    for i in range(n):
        for j in range(k+1):
            if i==0 and j>=items[0][0]:
                dp[0][j]=items[0][1]
            elif i>0 and j>=items[i][0]:
                dp[i][j]=max(dp[i-1][j],items[i][1]+dp[i-1][j-items[i][0]])
            elif j < items[i][0] and i > 0:
                dp[i][j]=dp[i-1][j]
    print (dp[-1][-1])

if __name__ == "__main__":
    main2()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    high=a
    middle=b
    low=c
    count=0

    while count<k:
        if abs(high-middle) >10**18:
            print("Unfair")
            exit()
        elif a == b == c:
            print(0)
            exit()
        high = b+c
        middle = a+c
        low = a+b
        a=high
        b=middle
        c=low
        count+=1
    print(high-middle) 
    

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())

    if abs(a-b)>10**18:
        print("Unfair")
    elif k % 2==0:
        print(a-b)
    else:
        print(b-a) 

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    high=a
    middle=b
    low=c
    count=0

    while count<k:
        if a == b == c:
            print(0)
            exit()
        high = b+c
        middle = a+c
        low = a+b
        a=high
        b=middle
        c=low
        count+=1
    if abs(high-middle) >10**18:
        print("Unfair")
        exit()
    else:
        print(high-middle) 
    

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())

    if abs(a-b)>10**18:
        print("Unfair")
    elif k % 2==0:
        print(a-b)
    else:
        print(b-a) 

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    high=a
    middle=b
    low=c
    count=0

    while count<k:
        if a == b == c:
            print(0)
            exit()
        high = b+c
        middle = a+c
        low = a+b
        a=high
        b=middle
        c=low
        count+=1
    if abs(high-middle) >10**18:
        print("Unfair")
        exit()
    else:
        print(high-middle) 
    

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())

    if abs(a-b)>10**18:
        print("Unfair")
    elif k % 2==0:
        print(a-b)
    else:
        print(b-a) 

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

import statistics
import copy

def median(tmp_numbers):
    return statistics.median(tmp_numbers)

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))

    for i in range(n):
        tmp_numbers=copy.deepcopy(numbers)
        tmp_numbers.pop(i)
        ans = median(tmp_numbers)
        print(ans)

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    sort_numbers=sorted(numbers)
# left/right算出はsorted arrayで
    left=sort_numbers[n//2-1]
    right=sort_numbers[n//2]
# loopは元の配列で
    for i in numbers:
        if i > left:
            print(left)
        else:
            print(right)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]

    for number in numbers:
        if len(answers)==0:
            answers.append(number)
        else:
            if number in answers:
                answers.pop(number)
            else:
                answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

from collections import Counter

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]
    Numbers_col = Counter(numbers)

    for number in Numbers_col.values():
        if number%2!=0:
            answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]

    for number in numbers:
        if len(answers)==0:
            answers.append(number)
        else:
            if number in answers:
                answers.remove(number)
            else:
                answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

from collections import Counter

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]
    Numbers_col = Counter(numbers)

    for number in Numbers_col.values():
        if number%2!=0:
            answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]

    for number in numbers:
        if len(answers)==0:
            answers.append(number)
        else:
            if number in answers:
                answers.remove(number)
            else:
                answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

from collections import Counter

def main():
    n = int(input())
    numbers=[]
    answers=[]
    number=0
    numbers=[int(input()) for _ in range(n)]
    Numbers_col = Counter(numbers)

    for number in Numbers_col.values():
        if number%2!=0:
            answers.append(number)
    print(len(answers))

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    mod = 10**9+7
    power=1

    for i in range(1,n+1):
        power*=i%mod
    print(power%mod)

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import math

def main():
    n = int(input())
    ans =math.factorial(n)
    print(ans%1000000007)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    mod = 10**9+7
    power=1

    for i in range(1,n+1):
        power*=i%mod
    print(power%mod)

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import math

def main():
    n = int(input())
    ans =math.factorial(n)
    print(ans%1000000007)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    ans =1
    for i in range(1,n+1):
        ans *=i
    print(ans%1000000007)

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import math

def main():
    n = int(input())
    ans =math.factorial(n)
    print(ans%1000000007)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    ans =1
    for i in range(1,n+1):
        ans *=i
    print(ans%1000000007)

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

import math

def main():
    n = int(input())
    ans =math.factorial(n)
    print(ans%1000000007)

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    k,s = map(int,input().split())
    counter=0

    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if x+y+z==s:
                    counter+=1
    print(counter)


if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main2():
    k,s = map(int,input().split())
    counter=0
    for x in range(k+1):
        for y in range(k+1):
            if 0<=s-x-y <=k:
                counter+=1
    print(counter)

if __name__=="__main__":
    main2()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = input().strip()
    while True:
        ngram_list=[]
        #round 1
        for i in range(len(N)-1):
            ngram_list.append(N[i:i+2])
        #round 2
        if "ST" in ngram_list:
            idx=ngram_list.index("ST")
            if idx+2 > len(N):
                N = N[:idx]
            else:
                N=N[:idx]+N[idx+2:]
        else:
            return print(len(N))


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = input().strip()
    stack = []
    for s in N:
        if len(stack)==0:
            stack.append(s)
        elif stack[-1]=="S" and s=="T":
            stack.pop()
        else:
            stack.append(s)
    print(len(stack))


if __name__ == "__main__":
    main()