#abc231h. [abc231_h]Minimum Coloring

[abc231_h]Minimum Coloring

Problem Statement

We have a grid with HH rows and WW columns. Let (i,j)(i,j) denote the square at the ii-th row from the top and jj-th column from the left.

On this grid, there are NN white pieces numbered 11 to NN. Piece ii is on (Ai,Bi)(A_i,B_i).

You can pay the cost of CiC_i to change Piece ii to a black piece.

Find the minimum total cost needed to have at least one black piece in every row and every column.

Constraints

  • 1leqH,Wleq1031 \\leq H,W \\leq 10^3
  • 1leqNleq1031 \\leq N \\leq 10^3
  • 1leqAileqH1 \\leq A_i \\leq H
  • 1leqBileqW1 \\leq B_i \\leq W
  • 1leqCileq1091 \\leq C_i \\leq 10^9
  • All pairs (Ai,Bi)(A_i,B_i) are distinct.
  • There is at least one white piece in every row and every column.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW NN A1A_1 B1B_1 C1C_1 hspace23ptvdots\\hspace{23pt} \\vdots ANA_N BNB_N CNC_N

Output

Print the answer.


Sample Input 1

2 3 6
1 1 1
1 2 10
1 3 100
2 1 1000
2 2 10000
2 3 100000

Sample Output 1

1110

By paying the cost of 11101110 to change Pieces 2,3,42, 3, 4 to black pieces, we can have a black piece in every row and every column.


Sample Input 2

1 7 7
1 2 200000000
1 7 700000000
1 4 400000000
1 3 300000000
1 6 600000000
1 5 500000000
1 1 100000000

Sample Output 2

2800000000

Sample Input 3

3 3 8
3 2 1
3 1 2
2 3 1
2 2 100
2 1 100
1 3 2
1 2 100
1 1 100

Sample Output 3

6