Twinkle
题号:NC26006
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 64 M,其他语言128 M
64bit IO Format: %lld

题目描述

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (x_i, y_i), a maximum brightness c, equal for all stars, and an initial brightness .

Over time the stars twinkle. At moment 0 the i-th star has brightness s_i. Let at moment t a star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if , and 0 otherwise.
You want to look at the sky q times. In the i-th time you will look at the moment t_i and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1_i, y1_i) and the upper right — (x2_i, y2_i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.

A star lies in a rectangle if it lies on its border or lies strictly inside it.

输入描述:

The first line contains three integers n, q, c — the number of the stars, the number of the views and the maximum brightness of the stars.
The next n lines contain the stars description. The i-th from these lines contains three integers x_i, y_i, s_i— the coordinates of i-th star and its initial brightness.
The next q lines contain the views description. The i-th from these lines contains five integers t_i, x1_i, y1_i, x2_i, y2_i — the moment of the i-th view and the coordinates of the viewed rectangle.

For all coordinates,

输出描述:

For each view print the total brightness of the viewed stars.
示例1

输入

复制
3 3 5
1 1 2
2 3 0
3 3 1
0 1 1 3 3
1 2 2 3 3
2 2 1 3 3

输出

复制
3
3
5