#!/usr/bin/env python Q = int(input()) events = [] for i in range(Q): events.append([int(x) for x in input().split()]) i = 1 ans = 0 initl = 0 labo_indexs = {} for event in events: if event[0] == 1: labo_indexs[i] = event[1] i += 1 if event[1] <= ans: print(ans) continue elif event[0] == 2: tmp = labo_indexs[event[1]] del labo_indexs[event[1]] if tmp < ans: print(ans) continue elif tmp >= ans: initl = ans+1 elif event[0] == 3: labo_indexs = dict([(x, y+event[1]) for (x, y) in labo_indexs.items()]) vals = sorted(labo_indexs.values(), reverse=True) for l in range(len(vals) if initl == 0 else initl, -1, -1): npeop = 0 for val in vals: if val >= l: npeop += 1 elif val < l: break if npeop >= l: ans = l print(ans) break else: continue