P4676 [BalticOI 2016] Spiral (day1)

Description

A grid of size $(2n+1)\times(2n+1)$ has been constructed as follows. Number $1$ has been placed in the center square, number $2$ has been placed to the right of it, and the following numbers have been placed along the spiral counterclockwise. Your task is to calculate answers for $q$ queries where the sum of numbers in an rectangular region in the grid is requested (modulo $10^9+7$). For example, in the following grid $n=2$ and the sum of numbers in the gray region is $74$ : ![](https://cdn.luogu.com.cn/upload/pic/20871.png)

Input Format

The first input line contains two integers $n$ and $q$ : the size of the grid and the number of queries. After this, there are $q$ lines, each containing four integers $x_1, y_1, x_2$ and $y_2$ ($-n\leq x_1\leq x_2\leq n, -n\leq y_1\leq y_2\leq n$). This means that you should calculate the sum of numbers in a rectangular region with corners $(x_1,y_1)$ and $(x_2,y_2)$.

Output Format

You should output the answer for each query (modulo $10^9+7$).

Explanation/Hint

## Subtasks In all subtasks $1\leq q\leq100$. ### Subtask 1 (12 points) - $1\leq n\leq1000$ ### Subtask 2 (15 points) - $1\leq n\leq10^9$ - $x_1=x_2$ and $y_1=y_2$ ### Subtask 3 (17 points) - $1\leq n\leq10^5$ ### Subtask 4 (31 points) - $1\leq n\leq10^9$ - $x_1=y_1=1$ ### Subtask 5 (25 points) - $1\leq n\leq10^9$