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>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n, h, w;
pair<int,pii> pts[125252];

int dat[252521];
int cnt[252521];
int root(int x){
    return dat[x]<0?x:dat[x]=root(dat[x]);
}
void unite(int a, int b){
    a=root(a);b=root(b);
    if(a==b)return;
    if(dat[a]>dat[b])swap(a,b);
    dat[a] += dat[b];
    dat[b] = a;
    cnt[a] += cnt[b];
}

int main(){
    scanf("%d%d%d",&n,&h,&w);
    REP(i,n){
        int r,c,a;
        scanf("%d%d%d",&r,&c,&a);
        --r;--c;
        pts[i] = make_pair(a,pii(r,c));
    }
    sort(pts,pts+n);
    reverse(pts,pts+n);
    fill(dat,dat+(h+w),-1);
    fill(cnt,cnt+(h+w),1);
    ll ans = 0;
    REP(i,n){
        int r,c,a;
        a = pts[i].first;
        tie(r,c) = pts[i].second;
        r = root(r);
        c = root(c+h);
        if(cnt[r]>0 || cnt[c]>0){
            unite(r,c);
            ans += a;
            r = root(r);
            cnt[r]--;
        }
    }
    printf("%lld\n",ans);
    return 0;
}