import bisect def main(): import sys input = sys.stdin.read data = input().split() idx = 0 Q = int(data[idx]) idx += 1 active = [] sorted_values = [] delta = 0 for _ in range(Q): t = int(data[idx]) x = int(data[idx + 1]) idx += 2 if t == 1: stored = x - delta active.append(stored) bisect.insort(sorted_values, stored) elif t == 2: x -= 1 # convert to 0-based stored = active[x] pos = bisect.bisect_left(sorted_values, stored) while pos < len(sorted_values) and sorted_values[pos] == stored: if (x == 0 or (active[:x].count(stored) == active[:x+1].count(stored) - 1)): sorted_values.pop(pos) break pos += 1 active.pop(x) elif t == 3: delta += x N = len(sorted_values) if N == 0: print(0) continue low = 1 high = N best = 0 while low <= high: mid = (low + high) // 2 if mid > N: high = mid - 1 continue idx_mid = N - mid if idx_mid >= 0 and sorted_values[idx_mid] + delta >= mid: best = mid low = mid + 1 else: high = mid - 1 print(best) if __name__ == "__main__": main()