Q=int(input()) A=[] for _ in range(Q): q=list(map(int,input().split())) if q[0]==1: if len(A)==0 or q[1]=2 and A[-1][0]>=A[-2][0]: v,cnt=A.pop() A[-1][0]=v A[-1][1]+=cnt else: i=0 mx=0 while q[1]>0: i-=1 q[1]-=A[i][1] mx=max(mx,A[i][0]) print(mx)