Under construction

Still being built. Things may change

Firing the Phaser

Time limit3sMemory limit512 MB

Summary
Given up to 15 non-touching axis-parallel rectangles and a beam length, find a start point and direction of a segment of that length that touches the most rectangles.
Level

Medium7 of 10

Topics
Geometry, Brute force, Implementation
Solved
No attempts yet

Statement

You are the captain of a spaceship and have snuck up on the most fierce enemy you have ever faced. You plan to fire a large phaser cannon at the enemy flagship before it notices you. There is no room for error, so the shot must be perfect.

You have started charging the phaser and pulled the room layout of the flagship from the archives. You are directly above the enemy, and the layout is a two-dimensional map of rooms. Each room is a rectangle with sides parallel to the x and y axes, and no two rooms intersect, not even at a single point.

The phaser beam is set by a point (x,y)(x, y) and an angle ϑ\vartheta. The beam starts at (x,y)(x, y) and travels a distance ℓ\ell in the direction ϑ\vartheta, damaging every room it touches. Your goal is to hit as many rooms as possible with one shot.

The charge is almost complete, and the only thing left is choosing the best setting. That turns out to be harder than expected. You have ten seconds until the charge finishes, so you write a program to solve it.

Input

The first line contains two integers rr and ℓ\ell (1≤r≤151 \le r \le 15, 1≤ℓ≤10001 \le \ell \le 1000), where rr is the number of rooms in the flagship and ℓ\ell is the length of a phaser shot.

The next rr lines each contain four integers x1x_1, y1y_1, x2x_2, y2y_2 (0≤x1<x2≤10000 \le x_1 < x_2 \le 1000, 0≤y1<y2≤10000 \le y_1 < y_2 \le 1000). Each line describes a room whose lower left corner is (x1,y1)(x_1, y_1) and whose upper right corner is (x2,y2)(x_2, y_2).

Output

Output one line with the maximum number of rooms that one phaser beam can hit. A room counts as hit if the beam touches it.

You may assume the answer is numerically stable: if every room is expanded by 10−610^{-6} in all four directions, the answer does not change.

Examples2

  1. Example 1

    Input
    5 8
    2 1 4 5
    5 1 12 4
    5 5 9 10
    1 6 4 10
    2 11 7 14
    
    Expected output
    4
    
  2. Example 2

    Input
    3 6
    2 2 3 3
    5 3 6 4
    6 6 7 7
    
    Expected output
    3