Runtime Error in TOWCNT

Please help me to identify the cause of RE
TOWCNT problem

from sys import *
import math
t=int(stdin.readline())
while t:
    t-=1
    h,n=map(int, stdin.readline().split())
    tower=[]
    up=10**9
    down=-10**9
    
    flag0=0
    flag1=0
    result=[0]*n
    for _ in range(n):
        arr=list(map(int, stdin.readline().split()))
        tower.append(arr)
    tower.sort(key=lambda pair:pair[1])
    #print(tower)

    for i in range(n):
        for j in range(i+1,n):
            if tower[j][0]==1 and flag1==0:
                up=(tower[j][2]-tower[i][2])/(tower[j][1]-tower[i][1])
                flag1=1
                result[i]+=1
                result[j]+=1
                #print("f1")
            elif tower[j][0]==0 and flag0==0:
                down=(tower[j][2]-tower[i][2])/(tower[j][1]-tower[i][1])
                flag0=1
                result[i]+=1
                result[j]+=1
                #print("f0")
            else:
                if tower[i][1]==tower[j][1]:
                    result[i]+=1
                    result[j]+=1
                    continue
                slope=(tower[j][2]-tower[i][2])/(tower[j][1]-tower[i][1])
                if (slope<up and slope>down):
                    result[i]+=1
                    result[j]+=1
                    #print("pair",i+1,j+1)
                    if tower[j][0]==1:
                        up=min(up,slope)
                    else:
                        down=max(slope,down)
                if up<=down:
                    break
                    
        flag0=0
        flag1=0
    for i in range(len(result)):
        print(result[i],end=" ")

I got my mistake anyway :smiley:

I am having similar RE NZEC issue
whats the mistake you found?