This page is still under construction.

Parts of this page are still being built. What you see may change.

Habitat Range of Fish

Time limit1sMemory limit128 MB

Summary
Given up to 50 axis-aligned boxes in 3D, compute the total volume covered by at least K of them.
Level

Hard8 of 10

Topics
Sorting, Divide and conquer, Prefix sum
Solved
No attempts yet

Problem

Marine researcher Sanggeun is studying NN species of fish that live in the East Sea.

The region where each species can live is an axis-aligned rectangular box (cuboid). A fish can move freely anywhere inside its habitat, including the boundary, but it never leaves that range.

A point in the sea is described by three numbers (x,y,d)(x, y, d): looking down from above, it is the point located xx to the east and yy to the north of a reference point, at depth dd below the sea surface. Assume the sea is a flat plane.

Write a program that computes the total volume of the region where at least KK species of fish can live.

Input

The first line contains two integers NN and KK. (1≤K≤N≤501 \le K \le N \le 50)

Each of the next NN lines contains six integers Xi,1 Yi,1 Di,1 Xi,2 Yi,2 Di,2X_{i,1}\ Y_{i,1}\ D_{i,1}\ X_{i,2}\ Y_{i,2}\ D_{i,2} describing the habitat of one fish. (0≤Xi,1<Xi,2≤1060 \le X_{i,1} < X_{i,2} \le 10^6, 0≤Yi,1<Yi,2≤1060 \le Y_{i,1} < Y_{i,2} \le 10^6, 0≤Di,1<Di,2≤1060 \le D_{i,1} < D_{i,2} \le 10^6)

The habitat of the ii-th fish is the axis-aligned cuboid whose opposite corners are (Xi,1,Yi,1,Di,1)(X_{i,1}, Y_{i,1}, D_{i,1}) and (Xi,2,Yi,2,Di,2)(X_{i,2}, Y_{i,2}, D_{i,2}).

Output

Print, on a single line, the integer volume of the region where at least KK species of fish can live.

Examples2

  1. Example 1

    Input
    3 2
    30 50 0 50 70 100
    10 20 20 70 90 60
    40 60 20 90 90 70
    
    Expected output
    49000
    
  2. Example 2

    Input
    1 1
    0 0 0 1000000 1000000 1000000
    
    Expected output
    1000000000000000000