Under construction

Still being built. Things may change

Starry Night (Easy)

Time limit1sMemory limit512 MB

Summary
Given N stars whose brightness drops by 1 per Manhattan step, find the total brightness over all cells in a given rectangle.
Level

Medium7 of 10

Topics
Prefix sum, Math, Array
Solved
No attempts yet

Problem

This problem and the Hard problem are the same problem with different input limits.

Star is taking photos of the night sky outside. Star wants to frame the best-looking photo and display it. While deciding how to pick the best photo, Star decides to score each photo as follows.

The sky at that time can be drawn as a 2D grid, and each cell is written as (x,y)(x, y). The sky region in a photo is always a rectangle, and no photo includes only part of a grid cell.

Given NN stars, where star ii is at (xi,yi)(x_i, y_i) with brightness pip_i, the brightness bx,yb_{x, y} at cell (x,y)(x, y) is computed as follows.

bx,y=∑i=1Nmax⁡(pi−(∣x−xi∣+∣y−yi∣),0)b_{x, y} = \sum_{i = 1}^{N} \max(p_i - (|x - x_i| + |y - y_i|), 0)

If the bottom-left cell of the photo's grid is (a,b)(a, b) and the top-right cell is (c,d)(c, d), the score scorescore of the photo is computed as follows.

score=∑y=bd∑x=acbx,yscore = \sum_{y = b}^{d} \sum_{x = a}^{c} b_{x, y}

Given the NN stars and the information about the photo, compute the score of the photo.

Input

The first line contains the number of stars NN. (1≤N≤10 000)(1 \le N \le 10\,000)

Each of the next NN lines contains the position xi,yix_i, y_i and brightness pip_i of the ii-th star. No two stars are at the same position. (−10 000≤xi≤10 000;(-10\,000 \le x_i \le 10\,000; −10 000≤yi≤10 000;-10\,000 \le y_i \le 10\,000; 1≤pi≤2 000)1 \le p_i \le 2\,000)

The last line contains a,b,c,da, b, c, d. The bottom-left cell of the photo is (a,b)(a, b), and the top-right cell is (c,d)(c, d). (−10 000≤a≤c≤10 000;(-10\,000 \le a \le c \le 10\,000; −10 000≤b≤d≤10 000;-10\,000 \le b \le d \le 10\,000; c−a≤2 000;c - a \le 2\,000; d−b≤2 000)d - b \le 2\,000)

All input values are integers.

Output

Print the score of the photo.

Examples1

  1. Example 1

    Input
    5
    0 0 4
    1 2 3
    -1 -2 4
    4 2 2
    7 -1 5
    0 0 4 4
    
    Expected output
    45