NZEC in Matched Brackets

I’m getting a NZEC error in this problem.


stack=[]
n=int(input())
l=list(map(int,input().split(" ")))
depth=0
depth_pos=0
depth_temp=0
symbol=0
symbol_temp=0
symbol_pos=0
for idx in range(len(l)):
    if not stack:
        if (symbol_temp>symbol):
            symbol=symbol_temp
            symbol_pos=idx+1
        symbol_temp=0

    symbol_temp+=1
    if l[idx]==1:
        stack.append(l[idx])
        depth_temp+=1

    if l[idx]==2:
        if(depth_temp>depth):
            depth=depth_temp
            depth_pos=(idx+1)-1
        depth_temp=0
        stack.pop()

if not stack:
    if symbol_temp>symbol:
        symbol=symbol_temp
        symbol_pos=idx+1
    symbol_temp=0
print("{} {} {} {}".format(depth,depth_pos,symbol,symbol_pos-symbol))

checked for some inputs and is working.any ideas??

//