QOJ.ac

QOJ

시간 제한: 10 s 메모리 제한: 256 MB 총점: 100

#23826. Fish

통계

To the west of the Australian continent lies the vast Indian Ocean. Mr. JOI, a marine researcher, is studying the characteristics of $N$ kinds of fish inhabiting the Indian Ocean.

For each kind of fish, a rectangular cuboid habitat is defined in the sea. Fish can move to any location within their habitat, including the boundary, but they never go outside their habitat. A point in the sea is represented by $3$ real numbers $(x, y, d)$: $(x, y, d)$ represents a point at a depth of $d$ from the sea surface, located at a position advanced $x$ to the east and $y$ to the north relative to a certain reference point when viewed from the sky. Here, the sea surface is assumed to be a plane.

Mr. JOI wants to know the extent of locations where the habitats of $K$ or more kinds of fish overlap. Write a program to find the total volume of all such locations.

Input

The input consists of $1 + N$ lines.

Line $1$ contains $2$ integers $N, K$ ($1 \le K \le N \le 50$) separated by a space. This represents that there are $N$ kinds of fish, and we want to find the volume of locations where the habitats of $K$ or more kinds of fish overlap.

The $i$-th line ($1 \le i \le N$) of the following $N$ lines contains $6$ integers $X_{i,1}, Y_{i,1}, D_{i,1}, X_{i,2}, Y_{i,2}, D_{i,2}$ ($0 \le X_{i,1} < X_{i,2} \le 1000000 \ (= 10^6)$, $0 \le Y_{i,1} < Y_{i,2} \le 1000000 \ (= 10^6)$, $0 \le D_{i,1} < D_{i,2} \le 1000000 \ (= 10^6)$). This represents that the habitat of the $i$-th kind of fish is a rectangular cuboid having the $8$ points $(X_{i,1}, Y_{i,1}, D_{i,1})$, $(X_{i,2}, Y_{i,1}, D_{i,1})$, $(X_{i,2}, Y_{i,2}, D_{i,1})$, $(X_{i,1}, Y_{i,2}, D_{i,1})$, $(X_{i,1}, Y_{i,1}, D_{i,2})$, $(X_{i,2}, Y_{i,1}, D_{i,2})$, $(X_{i,2}, Y_{i,2}, D_{i,2})$, $(X_{i,1}, Y_{i,2}, D_{i,2})$ as its vertices.

Output

Output in $1$ line the total volume of the locations where the habitats of $K$ or more kinds of fish overlap.

Examples

Input 1

3 2
30 50 0 50 70 100
10 20 20 70 90 60
40 60 20 90 90 70

Output 1

49000

Note

In Sample 1, for example, the point $(45, 65, 65)$ is within the habitats of the $1$-st kind of fish and the $3$-rd kind of fish, so it is a location that satisfies the condition. On the other hand, the point $(25, 35, 45)$ is within the habitat of only the $2$-nd kind of fish, so it is not a location that satisfies the condition. Also, the habitats of the fish are as shown in the figure below. Point $O$ represents the reference point on the sea surface.

problem_23826_f3130890da3222c2e67bd94c2907d32a.png

Input 2

1 1
0 0 0 1000000 1000000 1000000

Output 2

1000000000000000000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.