#include using namespace std; typedef long long ll; typedef unsigned long long ull; const double pi = 3.141592653589793; int inf = 1001001001; ll INF = 1001001001001001001; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define rep(i, n) FOR(i, 0, n) #define all(x) x.begin(), x.end() #define pb push_back #define pf push_front using P = pair; ll mod2 = 998244353; struct binary_indexed_tree{ int N; vector bit; binary_indexed_tree(int n):N(n){ bit.resize(N+1,0); } ll addition(ll x, ll y){ return (x+y); } void add(int x,ll a){ x++; for(x; x<=N; x+=(x&-x)) bit[x] = addition(bit[x],a); } ll sum(int x){ x++; ll ret=0; for(x; x>0; x-=(x&-x)) ret = addition(ret,bit[x]); return ret; } ll get(ll k) { k++; ll res = 0; ll si = 1; while(si0; i/=2) { if (res+i> Q >> K; vector V(Q); vector V2; vector T(Q); rep(i, Q) { cin >> T[i]; if (T[i]==1) { ll v;cin >> v; V[i] = v; V2.pb(v); } } sort(all(V2)); V2.erase(unique(all(V2)), V2.end()); binary_indexed_tree bit(200010); ll si = 0; rep(i, Q) { if (T[i]==1) { ll ind = lower_bound(all(V2), V[i])-V2.begin(); bit.add(ind, 1); si++; } else { if (si0) si--; } } return 0; }