Under construction

Still being built. Things may change

Rectangles

Time limit1sMemory limit512 MB

Summary
Find the integer point B on the top or right edge so that segment AB from the origin crosses the most of N axis-parallel rectangles.
Level

Medium6 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Problem

There are N rectangles on the plane. Their sides are parallel to the coordinate axes. The rectangles may overlap, coincide, or lie inside one another. Their vertices have non-negative integer coordinates, where x coordinates do not exceed xmaxx_{max} and y coordinates do not exceed ymaxy_{max}.

A segment starts at A(0,0)A(0, 0) and ends at point BB. The coordinates of BB satisfy these conditions:

  • BB has integer coordinates.
  • BB lies on the segment [(0,ymax),(xmax,ymax)][(0, y_{max}), (x_{max}, y_{max})] or on the segment [(xmax,0),(xmax,ymax)][(x_{max}, 0), (x_{max}, y_{max})].

Segment ABAB crosses a rectangle even if it touches only one of its vertices.

Find a point BB for which segment ABAB crosses as many rectangles as possible.

The figure shows 8 rectangles. Segment ABAB crosses 5 of them.

Input

The first line contains three integers xmaxx_{max}, ymaxy_{max} (0<xmax,ymax≤1090 < x_{max}, y_{max} \le 10^9) and NN (1≤N≤100001 \le N \le 10000). Each of the following N lines contains four integers xblx_{bl}, ybly_{bl}, xtrx_{tr}, ytry_{tr}, the coordinates of the bottom left corner and the top right corner of a rectangle. Adjacent numbers are separated by a single space.

Output

Print one line with three integers. The first is the maximum number of rectangles crossed by segment ABAB. The second and third are the x and y coordinates of point BB. If several answers exist, print any of them.

Hint

Another possible answer is 5 22 11.

Examples1

  1. Example 1

    Input
    22 14 8
    1 8 7 11
    18 10 20 12
    17 1 19 7
    12 2 16 3
    16 7 19 9
    8 4 12 11
    7 4 9 6
    10 5 11 6
    
    Expected output
    5 22 12