Driving Directions

Time limit1sMemory limit128 MB

Summary
Find the shortest path for a circle of radius r between two points avoiding axis-aligned rectangular obstacles, using tangent lines and arcs around inflated corners.
Level

Hard8 of 10

Topics
Graph, Shortest path, Geometry
Solved
No attempts yet

Problem

Contrary to popular belief, alien flying saucers cannot fly arbitrarily around planet Earth. Their landing and take-off maneuvers consume enormous amounts of energy, so every mission is planned carefully: the saucer touches down at one chosen spot, hovers above the ground to carry out its work, then takes off. This was easy when human civilization was young — a saucer could hover above every tree and building, and the shortest path between two mission points was simply a straight line. Modern cities, however, have skyscrapers too tall to hover over, so navigating a city has become a complex task.

An alien spy has hired you to write software that gives flying saucers driving directions through a city. As your first assignment, compute the shortest distance a saucer must travel from a start point to a finish point. The aliens will use this to plan the energy budget of a mission.

The problem is simplified as follows. Because a saucer can hover above most buildings, only the skyscrapers matter. The situation is two-dimensional: view everything from above and treat all objects as lying on the Cartesian OXY plane. The saucer is a circle of radius rr. Because modern skyscrapers are regular, each skyscraper is an axis-aligned rectangle whose sides are parallel to the OX and OY axes.

The saucer's location is the location of its center, and the length of its path is the length of the path traced by its center. During a mission the saucer may touch a skyscraper but must never overlap its interior. A shortest path therefore consists of straight segments together with circular arcs of radius rr that hug the corners of the skyscrapers.

Input

The first line contains two integers rr and nn (1≤r≤1001 \le r \le 100, 0≤n≤300 \le n \le 30), where rr is the radius of the flying saucer and nn is the number of skyscrapers.

The second line contains four integers xAx_A, yAy_A, xBx_B, and yBy_B (−1000≤xA,yA,xB,yB≤1000-1000 \le x_A, y_A, x_B, y_B \le 1000), where (xA,yA)(x_A, y_A) is the start point of the mission and (xB,yB)(x_B, y_B) is the finish point.

Each of the next nn lines describes one skyscraper with four integers x1x_1, y1y_1, x2x_2, and y2y_2 (−1000≤x1,y1,x2,y2≤1000-1000 \le x_1, y_1, x_2, y_2 \le 1000, x1<x2x_1 < x_2, y1<y2y_1 < y_2) — the coordinates of two opposite corners of the rectangle.

No two skyscrapers intersect or touch. The start and finish points are valid saucer locations: at each of them the saucer does not overlap any skyscraper, although it may touch one.

Output

If the flying saucer cannot reach the finish point from the start point, print no solution (without the quotes).

Otherwise print a single number — the shortest distance the saucer must travel from the start point to the finish point, rounded to exactly six digits after the decimal point.

Examples3

  1. Example 1

    Input
    1 3
    2 7 7 1
    3 2 6 4
    7 5 9 8
    1 8 5 9
    
    Expected output
    10.570796
    
  2. Example 2

    Input
    2 4
    0 0 5 6
    8 3 10 6
    5 9 9 10
    1 4 2 8
    3 1 5 3
    
    Expected output
    no solution
    
  3. Example 3

    Input
    1 2
    0 5 10 5
    2 2 4 5
    6 5 8 8
    
    Expected output
    11.652892