deffind_bound(a):
n = len(a)
window = {}
pos_left,pos_right = {},{}
for i,x in enumerate(a):
if x in window:
pos_left[i] = window[x]
pos_right[window[x]] = i
window.pop(x)#ensure the only ele in window
window[x] = i
return pos_left,pos_right
deffind_unique(a,bound_left,bound_right):global pos_left,pos_right
defcheck(pos):# x is the position
left,right = 0,0
left = pos_left[pos] if pos in pos_left else -1
right = pos_right[pos] if pos in pos_right else len(a)
return left<bound_left and right > bound_right
left,right = bound_left,bound_right
while left<=right:
if check(left):return left
elif check(right):return right
left+=1
right-=1returnNonedefmain(a,left,right):global pos_left,pos_right
if left>=right:returnTrue
pos = find_unique(a,left,right)
if pos==None:returnFalseelse:
return main(a,left,pos-1) and main(a,pos+1,right)
a = [1,4,3,2,0,3,2,1,3]
pos_left,pos_right = find_bound(a)
print('no-boring'if main(a,0,len(a)-1) else'boring')