import sys,collections,heapq,copy sys.setrecursionlimit(10**7) def Is(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) q = I() h = [] d,power = 0,0 for i in range(q): t,x = Is() if t == 1: h.append(x+power) elif t == 2: h[x-1] = -10**15 d += 1 else: power += x l = copy.deepcopy(h) l.sort(reverse=True) l = l[:len(l)-d] # print(l,power) ans = 0 for i,e in enumerate(l): e = 0 if e+power<=0 else e+power if i+1 <=e: ans = min(i+1,e) else: break print(ans)