N=int(input()) stack1=[] stack2=[] for i in range(1,N+1): A,B=map(int,input().split()) if A==0: if B==0: print(i) while len(stack1) and len(stack2) and stack1[-1]>stack2[-1]: print(stack1.pop()) elif B==1: print(i) print(stack2.pop()) else: stack2.append(i) else:stack1.append(i) stack=sorted(stack1+stack2,reverse=True) for i in stack: print(i)