QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100

#3768. Union of Rectangles

统计

Bobo has a rectangle $A$. The coordinates of the bottom-left corner of the rectangle are $(x_1, y_1)$, and the coordinates of the top-right corner are $(x_2, y_2)$. Let $R(i, j)$ be the rectangle with bottom-left corner $(0, 0)$ and top-right corner $(i, j)$, and let $\mathrm{Area}(i, j)$ be the area of the union of rectangle $A$ and rectangle $R(i, j)$.

Given $a$ and $b$, calculate $\sum_{i = 1}^a \sum_{j = 1}^b \mathrm{Area}(i, j)$ modulo $(10^9+7)$.

Input

The input file contains multiple test cases. Process until the end of the file.

Each test case consists of two lines. The first line contains two integers $a$ and $b$, and the second line contains four integers $x_1, x_2, y_1, y_2$.

  • $1 \leq a, b, x_1, x_2, y_1, y_2 \leq 10^9$
  • $x_1 < x_2$, $y_1 < y_2$
  • The number of test cases does not exceed $10^4$.

Output

For each test case, output an integer representing the required value.

Examples

Input 1

1 1
2 3 2 3
10 10
1 5 1 5
1000000000 1000000000
1 1000000000 1 1000000000

Output 1

2
3725
2793

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.