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 <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
// 1:T 2:H
long long ans;
int w,h,n,m,i,j,fa[200005],typ[200005];
struct ii
{
	int x,y,val;
}a[200005];
bool cmp(ii x,ii y)
{
	return x.val>y.val;
}
int fnd(int x)
{
	if(fa[x]==x)return x;
	return fa[x]=fnd(fa[x]); 
}
bool mrg(int x,int y)
{
	x=fnd(x);y=fnd(y);
	if(x==y){
		if(typ[x]==2) return 0;
		typ[x]=2;return 1;
	}
	if(typ[x]==2&&typ[y]==2) return 0;
	if(typ[x]==1&&typ[y]==2) {fa[x]=y;return 1;}
	if(typ[x]==2&&typ[y]==1) {fa[y]=x;return 1;}
	if(typ[x]==1&&typ[y]==1) {fa[x]=y;return 1;}
	exit(-1);
}
int main()
{
	scanf("%d%d%d",&n,&h,&w);
	fz1(i,w+h){
		fa[i]=i;
		typ[i]=1;
	}
	fz1(i,n){
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].val);
		a[i].y+=h;
	}
	sort(a+1,a+n+1,cmp);
	fz1(i,n){
		if(mrg(a[i].x,a[i].y)) ans+=a[i].val;
	}
	cout<<ans<<endl;
	return 0;
}