#ABC298F. [ABC298F] Rook Score

[ABC298F] Rook Score

Score : 500500 points

Problem Statement

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

For i=1,2,,Ni=1,2,\ldots,N, a positive integer xix_i is written on (ri,ci)(r_i,c_i). On the other 1018N10^{18}-N squares, 00 is written.

You choose a square (R,C)(R,C) and compute the sum SS of the integers written on the 2×10912 \times 10^9 - 1 squares that share a row or column with (R,C)(R,C).

Find the maximum possible value of SS.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1ri,ci,xi1091 \leq r_i,c_i,x_i \leq 10^9
  • (ri,ci)(rj,cj)(r_i,c_i) \neq (r_j,c_j) if iji \neq j.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

r1r_1 c1c_1 x1x_1

\vdots

rNr_N cNc_N xNx_N

Output

Print the answer.

4
1 1 2
1 2 9
2 1 8
3 2 3
20

If you choose (2,2)(2,2) as (R,C)(R,C), then SS will be 2020, which is the maximum possible value.

1
1 1000000000 1
1
15
158260522 877914575 602436426
24979445 861648772 623690081
433933447 476190629 262703497
211047202 971407775 628894325
731963982 822804784 450968417
430302156 982631932 161735902
880895728 923078537 707723857
189330739 910286918 802329211
404539679 303238506 317063340
492686568 773361868 125660016
650287940 839296263 462224593
492601449 384836991 191890310
576823355 782177068 404011431
818008580 954291757 160449218
155374934 840594328 164163676
1510053068