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 <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;

int N, H, W;


struct S{
	int x, y, d;
	bool operator <(const S &a)const{
		return d<a.d;
	}
};
vector<S> v;

ll ans;

vector<int> gp[MAX_N*2+1];
bool chk[MAX_N*2+1];

int g[MAX_N*2+1];

void init_g(){
	for(int i=2; i<=H+W; i++)	g[i] = i;
}

int find_g(int x){
	return (x==g[x])?x:g[x] = find_g(g[x]);
}

void union_g(int x, int y){
	x = find_g(x); y = find_g(y);
	g[x] = y;
}

void make(int x, int y){
	chk[x] = true;
	for(int i : gp[x]){
		if(i!=y){
			make(i, x);
		}
	}
}

int main(){
	cin>>N>>H>>W;
	init_g();
	for(int i=1; i<=N; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		v.pb((S){a, b+H, c});
	}
	sort(v.begin(), v.end());
	while(!v.empty()){
		S now = v.back(); v.pop_back();
		if(chk[now.x] && !chk[now.y]){
			make(now.y, 0);
			ans+=(ll)now.d;
		}
		else if(!chk[now.x] && chk[now.y]){
			make(now.x, 0);
			ans+=(ll)now.d;
		}
		else if(!chk[now.x] && !chk[now.y]){
			if(find_g(now.x)==find_g(now.y)){
				make(now.x, 0);
			}
			gp[now.x].pb(now.y);
			gp[now.y].pb(now.x);
			union_g(now.x, now.y);
			ans+=(ll)now.d;
		}
	}
	cout<<ans;
	return 0;
}