#!/usr/bin/env python import copy Q = int(input()) events = [] for i in range(Q): events.append([int(x) for x in input().split()]) N = 0 addlist = [0] keylist = [] dp = {} for event in events: if event[0] == 1: x = event[1] N += 1 addlist.append(x) keylist = sorted(list(set(keylist + [x]))) for k in keylist: if k < x: dp[k] += 1 if x in dp.keys(): dp[x] += 1 elif x == keylist[-1]: dp[x] = 1 else: dp[x] = dp[keylist[keylist.index(x)+1]] + 1 elif event[0] == 2: N -= 1 if N == 0: dp = {} keylist = [] else: x = addlist[event[1]] for k in keylist: if k <= x: dp[k] = max(0, dp[k] - 1) elif event[0] == 3: x = event[1] addlist = [v+x for v in addlist] keylist = [i+x for i in keylist] dp_new = {k:dp[k-x] for k in keylist} dp = copy.deepcopy(dp_new) ansdp = [(k, v) for k, v in dp.items() if k >= 0] if len(ansdp) == 0: print(0) else: ansdp.sort(reverse=True) for i, val in enumerate(ansdp): if val[1] >= val[0]: print(val[0]) break elif i+1 == len(ansdp): print(val[1]) break elif val[1] >= ansdp[i+1][0]: print(val[1]) break else: continue