#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,int> pl;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

vector<lint> a[100100];//各色のボールにどういう重さのがあるか
vector<pl> b;//すべてのボールの集合
int num[100100];//各色のボールを何個ずつ使ったか
priority_queue<pl> used;//既に使った3個目以降のボール
priority_queue<pl> rest;//まだ使ってない3個目以降のボール
priority_queue<pl> r2;//まだ1個も使ってない色のトップ3
lint inf=1234567890123456LL;

lint cal(){
	while(!r2.empty()){
		pl p=r2.top();
		if(num[p.se]<2) return p.fi;
		r2.pop();
	}
	return -inf;
}

int main()
{
	int n,k,c,v;
	cin>>n>>k;
	rep(i,n){
		cin>>c>>v;c--;v*=2;a[c].pb(v);
	}
	rep(i,k){
		sort(All(a[i]));reverse(All(a[i]));
		a[i][0]=a[i][1]=(a[i][0]+a[i][1])/2;
		rep(j,a[i].size()) b.pb(mp(a[i][j],i));
		if(a[i].size()>2) r2.push(mp(a[i][0]+a[i][1]+a[i][2],i));
	}
	sort(All(b));reverse(All(b));
	lint sum=0;int pre=-1;
	rep(i,n){
		int it=b[i].se;
		sum+=b[i].fi;num[it]++;
		if(num[it]==1){
			lint ret=-2;
			if(!used.empty()){
				ret=max(ret,sum+b[i+1].fi+used.top().fi);
			}
			if(!rest.empty()){
				ret=max(ret,sum-b[i].fi+rest.top().fi);
			}
			lint th=cal(),tr=inf;
			if(pre>=0) tr=min(tr,a[pre][0]+a[pre][1]);
			if(used.size()>1){
				pl p,q;p=used.top();used.pop();q=used.top();
				tr=min(tr,-p.fi-q.fi);used.push(p);
			}
			ret=max(ret,sum-tr-b[i].fi+th);
			cout<<ret/2<<endl;
		}
		else{
			cout<<sum/2<<endl;
			if(num[it]==2){
				REP(j,2,a[it].size()) rest.push(mp(a[it][j],it));
				pre=it;
			}
			else{
				pl p=rest.top();rest.pop();
				assert(p==b[i]);
				p=mp(-p.fi,p.se);
				used.push(p);
			}
		}
	}
}

### Prompt

Your task is to create a CPP solution to the following problem:

There are N jewels, numbered 1 to N. The color of these jewels are represented by integers between 1 and K (inclusive), and the color of Jewel i is C_i. Also, these jewels have specified values, and the value of Jewel i is V_i.

Snuke would like to choose some of these jewels to exhibit. Here, the set of the chosen jewels must satisfy the following condition:

* For each chosen jewel, there is at least one more jewel of the same color that is chosen.



For each integer x such that 1 \leq x \leq N, determine if it is possible to choose exactly x jewels, and if it is possible, find the maximum possible sum of the values of chosen jewels in that case.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq K \leq \lfloor N/2 \rfloor
* 1 \leq C_i \leq K
* 1 \leq V_i \leq 10^9
* For each of the colors, there are at least two jewels of that color.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N K
C_1 V_1
C_2 V_2
:
C_N V_N


Output

Print N lines. In the i-th line, if it is possible to choose exactly i jewels, print the maximum possible sum of the values of chosen jewels in that case, and print -1 otherwise.

Examples

Input

5 2
1 1
1 2
1 3
2 4
2 5


Output

-1
9
6
14
15


Input

5 2
1 1
1 2
2 3
2 4
2 5


Output

-1
9
12
12
15


Input

8 4
3 2
2 3
4 5
1 7
3 11
4 13
1 17
2 19


Output

-1
24
-1
46
-1
64
-1
77


Input

15 5
3 87
1 25
1 27
3 58
2 85
5 19
5 39
1 58
3 12
4 13
5 54
4 100
2 33
5 13
2 55


Output

-1
145
173
285
318
398
431
491
524
576
609
634
653
666
678

### Response

```cpp
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,int> pl;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

vector<lint> a[100100];//各色のボールにどういう重さのがあるか
vector<pl> b;//すべてのボールの集合
int num[100100];//各色のボールを何個ずつ使ったか
priority_queue<pl> used;//既に使った3個目以降のボール
priority_queue<pl> rest;//まだ使ってない3個目以降のボール
priority_queue<pl> r2;//まだ1個も使ってない色のトップ3
lint inf=1234567890123456LL;

lint cal(){
	while(!r2.empty()){
		pl p=r2.top();
		if(num[p.se]<2) return p.fi;
		r2.pop();
	}
	return -inf;
}

int main()
{
	int n,k,c,v;
	cin>>n>>k;
	rep(i,n){
		cin>>c>>v;c--;v*=2;a[c].pb(v);
	}
	rep(i,k){
		sort(All(a[i]));reverse(All(a[i]));
		a[i][0]=a[i][1]=(a[i][0]+a[i][1])/2;
		rep(j,a[i].size()) b.pb(mp(a[i][j],i));
		if(a[i].size()>2) r2.push(mp(a[i][0]+a[i][1]+a[i][2],i));
	}
	sort(All(b));reverse(All(b));
	lint sum=0;int pre=-1;
	rep(i,n){
		int it=b[i].se;
		sum+=b[i].fi;num[it]++;
		if(num[it]==1){
			lint ret=-2;
			if(!used.empty()){
				ret=max(ret,sum+b[i+1].fi+used.top().fi);
			}
			if(!rest.empty()){
				ret=max(ret,sum-b[i].fi+rest.top().fi);
			}
			lint th=cal(),tr=inf;
			if(pre>=0) tr=min(tr,a[pre][0]+a[pre][1]);
			if(used.size()>1){
				pl p,q;p=used.top();used.pop();q=used.top();
				tr=min(tr,-p.fi-q.fi);used.push(p);
			}
			ret=max(ret,sum-tr-b[i].fi+th);
			cout<<ret/2<<endl;
		}
		else{
			cout<<sum/2<<endl;
			if(num[it]==2){
				REP(j,2,a[it].size()) rest.push(mp(a[it][j],it));
				pre=it;
			}
			else{
				pl p=rest.top();rest.pop();
				assert(p==b[i]);
				p=mp(-p.fi,p.se);
				used.push(p);
			}
		}
	}
}

```