#include using namespace std; using ll =long long; template struct K_small { ll K; T sum; multiset small, big; K_small(ll _K) :K() { sum = e(); K = _K; } // xを追加する. 小さい方に追加されたら1を返す. bool insert(T x) { if (ll(small.size()) < K) { small.insert(x); sum = op(sum, x); return 1; } else { if(K==0){ big.insert(x); return 0; } auto sla = small.end(); sla--; T sb = *sla; if (sb > x) { small.insert(x); small.erase(sla); big.insert(sb); sum = op(sum, x); sum = op(sum, inv(sb)); return 1; } else { big.insert(x); return 0; } } } bool erase(T x) { auto se=small.find(x); auto gb=big.find(x); assert(se != small.end() || gb != big.end()); if (gb != big.end()) { big.erase(gb); return 0; } else { small.erase(se); sum = op(sum, inv(x)); if (ll(big.size()) == 0)return 0; else { auto bs = big.begin(); T ad = *bs; big.erase(bs); small.insert(ad); sum = op(sum, ad); return 1; } } } void changeK(ll NK) { K = NK; assert(ll(small.size()) + ll(big.size()) >= K); while (ll(small.size()) < K) { auto p = big.begin(); T ns = *p; sum = op(sum, ns); small.insert(ns); big.erase(p); } while (ll(small.size()) > K) { auto p = small.end(); p--; T ns = *p; sum = op(sum, inv(ns)); big.insert(ns); small.erase(p); } return; } T get(){ return *(prev(small.end())); } T pr() { return sum; } void debug(){ cout<<"small:"; for(auto s:small)cout<<" "<>N>>K>>Q; K_small D(K); for(int i=0;i>A; D.insert(A); } for(int q=0;q>t; if(t==1){ ll x; cin>>x; D.insert(x); } else if(t==2){ ll y; cin>>y; ll d=D.get(); D.erase(d); D.insert(d+y); } else{ cout<