#P4261. Cloud Overlap

    ID: 17507 Type: Default 1000ms 256MiB

Cloud Overlap

Cloud Overlap

In the xyxy-coordinate plane, there are nn clouds, each represented by a 5-tuple (xi,yi,wi,hi,di)(x_i, y_i, w_i, h_i, d_i). Here, (xi,yi)(x_i, y_i) is the coordinate of the lower-left vertex of the cloud, wiw_i is the width (extension along the xx-axis), hih_i is the height (extension along the yy-axis) of the cloud, and di{0,1}d_i\in\{0,1\} indicates its moving direction. If di=0d_i=0, the cloud moves horizontally in the positive xx-direction at a speed of 11 unit per second; if di=1d_i=1, it moves vertically in the positive yy-direction at the same speed.

At time 00, it is guaranteed that no two clouds have overlapping interior areas (their interiors are disjoint). A point (x,y)(x,y) at time tt is covered by a cloud if and only if it lies in the interior (boundaries excluded) of the cloud’s rectangle at that time. For a horizontal cloud (i.e. di=0d_i=0), its rectangle at time tt is given by the open interval ( (x_i+t,,x_i+t+w_i) ) in the xx-axis and ( (y_i,,y_i+h_i) ) in the yy-axis. For a vertical cloud (i.e. di=1d_i=1), its rectangle at time tt becomes ( (x_i,,x_i+w_i) ) in the xx-axis and ( (y_i+t,,y_i+t+h_i) ) in the yy-axis.

Your task is to determine the maximum number of clouds that can cover the same point at the same time (for any real time t(,+)t\in (-\infty,+\infty) and any point in the plane). Note that since the interiors of two clouds of the same moving group (both horizontal or both vertical) do not overlap (because they are non overlapping at time 00 and their relative positions remain fixed in the non-translating coordinate), the only possibility for a point to be covered by more than one cloud is when the point lies in the intersection of a horizontal and a vertical cloud. Therefore, the answer is:

  • 00, when there are no clouds;
  • 11, when all clouds move in the same direction;
  • 22, when there is at least one horizontal and at least one vertical cloud.

Write a program to help determine the answer.

inputFormat

The first line contains an integer nn (0n1050 \leq n \leq 10^5), representing the number of clouds. Each of the following nn lines contains five numbers: xix_i, yiy_i, wiw_i, hih_i, and did_i (with di{0,1}d_i\in\{0,1\}). These values describe the cloud's lower-left corner, its width, its height, and its moving direction respectively.

outputFormat

Output a single integer representing the maximum number of clouds covering the same point at any moment.

sample

1
0 0 3 4 0
1

</p>