Problem: There are N cards placed on a grid with H rows and W columns of squares.

The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.

Multiple cards may be placed on the same square.

You will first pick up at most one card from each row.

Then, you will pick up at most one card from each column.

Find the maximum possible sum of the integers written on the picked cards.

Constraints

* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W

Input

Input is given from Standard Input in the following format:


N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N


Output

Print the maximum possible sum of the integers written on the picked cards.

Examples

Input

6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4


Output

28


Input

13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537


Output

430590


Input

1 100000 100000
1 1 1


Output

1

Solution (in CPP):

Solution:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
typedef tuple<int,int,int> T;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

queue<int> uft_q1;
int uft_parent[200005];
int uft_num[200005];
int edge_num[200005];

int uft_check_parent(int uft_x){
	if(uft_parent[uft_x]!=-1)return uft_check_parent(uft_parent[uft_x]);
	int uft_a;
	while(!uft_q1.empty()){
		uft_a=uft_q1.front(),uft_q1.pop();
		uft_parent[uft_a]=uft_x;
	}
	return uft_x;
}

bool uft_connect(int uft_x,int uft_y){
	uft_x=uft_check_parent(uft_x),uft_y=uft_check_parent(uft_y);
	if(uft_x==uft_y){
		if(edge_num[uft_x]<uft_num[uft_x]){
			edge_num[uft_x]++;
			return true;
		}else return false;
	}
	if(edge_num[uft_x]+edge_num[uft_y]+1>uft_num[uft_x]+uft_num[uft_y])return false;
	if(uft_num[uft_x]>uft_num[uft_y])swap(uft_x,uft_y);
	uft_parent[uft_x]=uft_y;
	uft_num[uft_y]+=uft_num[uft_x];
	edge_num[uft_y]+=edge_num[uft_x]+1;
	return true;
}

priority_queue<T> q1;

int main(){
	int n,p,q;
	int i,j,k;
	int a,b,c;
	LL s=0;
	cin>>n>>p>>q;
	memset(uft_parent,-1,sizeof(uft_parent));
	for(i=0;i<p+q;i++)uft_num[i]=1;
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		a--,b--;
		q1.push(make_tuple(c,a,b));
	}
	while(!q1.empty()){
		tie(c,a,b)=q1.top(),q1.pop();
		if(uft_connect(a,p+b)){
			s+=c;
			//cout<<c<<endl;
		}
	}
	cout<<s<<endl;

}