This page is still under construction.

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

Counting Bow Ties

Time limit2sMemory limit256 MB

Summary
Count 4-cycles in a bipartite graph defined by M rectangles over vertex ranges, with N up to 1e9.
Level

Hard8 of 10

Topics
Geometry, Combinatorics, Sorting, Prefix sum
Solved
No attempts yet

Problem

A bipartite graph has 2N2N vertices. NN of them hang from the ceiling and the other NN sit on the floor. The ceiling vertices are numbered 1 through NN, and the floor vertices are numbered the same way.

MM trapezoids connect the ceiling to the floor. Each trapezoid is given by the segment [sx,ex][s_x, e_x] it occupies on the ceiling and the segment [sy,ey][s_y, e_y] it occupies on the floor. Ceiling vertex ii and floor vertex jj are joined by an edge when at least one trapezoid satisfies both sx≤i≤exs_x \le i \le e_x and sy≤j≤eys_y \le j \le e_y. When several trapezoids cover the same edge, the edge still counts once.

A simple cycle of length 4 in this graph is called a bow tie. Two different ceiling vertices i1i_1, i2i_2 and two different floor vertices j1j_1, j2j_2 form one bow tie when all four edges (i1,j1)(i_1, j_1), (i1,j2)(i_1, j_2), (i2,j1)(i_2, j_1), (i2,j2)(i_2, j_2) are present. Two bow ties are different when their edge sets differ in at least one element.

Given the shape of the graph, count the bow ties.

A graph with 9 vertices on each side and two trapezoids. The dashed lines mark one bow tie in it.

Input

The first line contains NN (1≤N≤1091 \le N \le 10^9) and MM (0≤M≤10000 \le M \le 1000), separated by a space. The graph has 2N2N vertices and there are MM trapezoids.

Each of the next MM lines contains one trapezoid in the form sxs_x exe_x sys_y eye_y (1≤sx≤ex≤N1 \le s_x \le e_x \le N, 1≤sy≤ey≤N1 \le s_y \le e_y \le N).

Output

Print the number of bow ties modulo 109+710^9 + 7.

Examples2

  1. Example 1

    Input
    2 1
    1 2 1 2
    
    Expected output
    1
    
  2. Example 2

    Input
    9 2
    2 7 6 9
    5 6 1 5
    
    Expected output
    120