Gold Mines

No attempts yetTime limit3sMemory limit256 MB

Problem

A country is nicknamed the land of gold. Many of its gold mines are still undeveloped. On a map each gold mine is drawn as a point in the plane.

Figure 1

Each point pip_i carries an integer wiw_i that is positive or negative. wiw_i is the profit or the loss produced by developing that mine. If wiw_i is positive, developing the mine earns wiw_i. If wiw_i is negative, developing the mine costs wi|w_i|.

A mine developer buys a rectangular plot RR whose sides are parallel to the xx axis and the yy axis, then develops every mine contained in RR. A mine lying on a side of the rectangle counts as contained in RR. The development profit is the sum of wiw_i over the mines contained in RR.

The developer looks for the rectangle RR with the largest development profit. For the mines in Figure 1, the region with the largest development profit is the one drawn in Figure 2, and that profit is 7.

Given the coordinates of the gold mines and the profit or loss of developing each one, write a program that prints the largest development profit obtainable by buying one rectangular plot.

Figure 2

Input

The first line contains the number of gold mines NN (1N30001 \le N \le 3000). Each of the next NN lines contains two non-negative integers xx and yy (0x,y1090 \le x, y \le 10^9) giving the coordinates of a mine, and an integer ww (109w109-10^9 \le w \le 10^9) giving the profit or the loss of developing it, separated by spaces. All mine coordinates are distinct, and at least one mine has w>0w > 0.

Output

Print on one line the largest development profit the developer can obtain by buying a rectangular plot RR. The value can exceed the range of a 32-bit integer during the computation, so you may need a 64-bit integer type.