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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        int h = ipar();
        int w = ipar();
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < n; i++)
        {
            ntok();
            int r = ipar()-1;
            int c = ipar()-1;
            int val = ipar();
            Card card = new Card(i, r, c, val);
            cards.add(card);
        }
        Collections.sort(cards);
        UnionFind uf = new UnionFind(h+w);
        long sum = 0;
        for (Card card : cards)
        {
            if (uf.find(card.r) == uf.find(card.c+h))
            {
                if (!uf.locked[uf.find(card.r)])
                {
                    uf.locked[uf.find(card.r)] = true;
                    sum += card.val;
                }
            }
            else if (!uf.locked[uf.find(card.r)] || !uf.locked[uf.find(card.c+h)])
            {
                uf.union(card.r, card.c+h);
                sum += card.val;
            }
        }
        out.println(sum);

        out.flush();
        in.close();
    }

    private class Card implements Comparable<Card>
    {
        int i, r, c, val;

        public Card(int i, int r, int c, int v)
        {
            this.i = i;
            this.r = r;
            this.c = c;
            val = v;
        }

        public int hashCode()
        {
            return i;
        }

        public boolean equals(Object obj)
        {
            if (obj instanceof Card)
            {
                Card other = (Card)obj;
                return i == other.i;
            }
            return false;
        }

        public int compareTo(Card other)
        {
            if (val == other.val)
            {
                return Integer.compare(i, other.i);
            }
            return -Integer.compare(val, other.val);
        }
    }

    private class UnionFind
    {
        int[] arr;
        int[] sz;
        boolean[] locked;
        
        public UnionFind(int n)
        {
            arr = new int[n];
            sz = new int[n];
            locked = new boolean[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
                sz[i] = 1;
            }
        }

        public int find(int i)
        {
            return arr[i] = (arr[i] == i ? i : find(arr[i]));
        }

        public void union(int i, int j)
        {
            i = find(i);
            j = find(j);
            if (sz[j] > sz[i])
            {
                int temp = i;
                i = j;
                j = temp;
            }
            arr[j] = i;
            sz[i] += sz[j];
            locked[i] |= locked[j];
        }
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}