import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto Q = readln.chomp.to!int; auto rbt = new RedBlackTree!(long, "a < b", true)(); long offset = 0; long[] L; foreach (_; 0..Q) { auto s = readln.split; auto t = s[0].to!int; auto x = s[1].to!long; if (t == 1) { L ~= x - offset; rbt.insert(x - offset); } else if (t == 2) { rbt.removeKey(L[x.to!int-1]); } else { offset += x; } long hi = 10L^^5+1; long lo = 0; while (hi - lo > 1) { auto mid = (hi + lo) / 2; auto lb = rbt.upperBound(mid-offset-1).array.length; if (lb >= mid) lo = mid; else hi = mid; } max(0, lo).writeln; } }