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
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1
        self.enum = 0

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()
        if not self.check(unite_node):
            return False
        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
                root.member_num_ = root.member_num_ + unite_root.member_num_
                root.enum = root.enum + unite_root.enum + 1
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)
                unite_root.member_num_ = root.member_num_ + unite_root.member_num_
                unite_root.enum = root.enum + unite_root.enum + 1
        else:
            root.enum += 1
        return True


    def check(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()
        if root.group_id_ == unite_root.group_id_:
            if root.enum < root.member_num_:
                return True
        else:
            if root.member_num_ + unite_root.member_num_ > root.enum + unite_root.enum:
                return True
        return False


if __name__ == "__main__":
    N,H,W=[int(i) for i in input().strip().split(" ")]
    node_list = [UnionFindNode(i) for i in range(H+W)]
    import sys
    es = []
    for line in sys.stdin:
        es.append(tuple(int(i) for i in line.strip().split(" ")))
    es = sorted(es, key=lambda x:x[2])
    r = 0
    for e in es[::-1]:
        if node_list[e[0]-1].unite(node_list[e[1]+H-1]):
            r += e[2]
    print(r)

