Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3018
Population

Time Limit: 10 Seconds      Memory Limit: 32768 KB

It is always exciting to see people settling in a new continent. As the head of the population management office, you are supposed to know, at any time, how people are distributed in this continent.

The continent is divided into square regions, each has a center with integer coordinates (x, y). Hence all the people coming into that region are considered to be settled at the center position. Given the positions of the corners of a rectangle region, you are supposed to count the number of people living in that region.

Input

Your program must read inputs from the standard input. Since there are up to 32768 different regions and possibly even more queries, please use "scanf" and "printf" instead of "cin" and "cout" to avoid timeout.

The character "I" in a line signals the coming in of new groups of people. In the following lines, each line contains three integers: X, Y, and N, where X and Y (1 <= X, Y <= 20000) are the coordinates of the region's center, and N (1 <= N <= 10000) is the number of people coming in.

The character "Q" in a line signals the query of population. The following lines each contains four numbers: Xmin, Xmax, Ymin, Ymax, where (Xmin, Ymin) and (Xmax, Ymax) are the integer coordinates of the lower left corner and the upper right corner of the rectangle, respectively.

The character "E" signals the end of a test case. Process to the end of file.

Output

For each "Q" case, print to the standard output in a line the population in the given rectangle region. That is, you are supposed to count the number of people living at all the positions (x, y) such that Xmin <= x <= Xmax, and Ymin <= y <= Ymax.

Sample Input

I
8 20 1
4 5 1
10 11 1
12 10 1
18 14 1
Q
8 10 5 15
8 20 10 14
I
7 6 1
10 3 2
7 2 1
2 3 2
10 3 1
Q
2 20 2 20
E

Sample Output

1
3
12

Author: CHEN, Yue
Source: ZOJ Monthly, August 2008
Submit    Status