Coding Task: Calculate Total Area of Rectangles Formed by Lines
Problem Statement
You are given a two-dimensional plane with m lines drawn parallel to the x-axis and n lines drawn parallel to the y-axis. The lines parallel to the x-axis are represented by their respective y-coordinates y_i, and the lines parallel to the y-axis are represented by their respective x-coordinates x_i.
Your task is to compute the total area of all rectangles formed by these lines and print the result modulo (10^9 + 7).
Definitions
The i-th line parallel to the x-axis is represented by the equation (y = y_i).
The j-th line parallel to the y-axis is represented by the equation (x = x_j).
A rectangle is defined by the quadruple of indices ((i, j, k, l)) such that:
(1 \leq i < j \leq n) (for vertical lines)
(1 \leq k < l \leq m) (for horizontal lines)
The area of the rectangle formed by these lines is calculated as:
[
\text{Area} = (x_j - x_i) \times (y_l - y_k)
]
You need to find the sum of all such rectangle areas and return the total sum modulo (10^9 + 7).
Input Format
The first line contains two integers (m) and (n) (the number of lines parallel to the x-axis and y-axis, respectively).
The second line contains m integers representing the y-coordinates of the lines (y_1, y_2, ..., y_m).
The third line contains n integers representing the x-coordinates of the lines (x_1, x_2, ..., x_n).
Output Format
Print a single integer which is the total area of all rectangles formed, modulo (10^9 + 7).
Constraints
(1 \leq m, n \leq 2000)
(0 \leq y_i, x_j \leq 10^9)
Example
Input
text
3 2
1 3 5
2 4
Output
text
8
Explanation
The possible rectangles are:
Using points (1,2) and (3,4): Area = (4-2)*(3-1) = 4
Using points (1,2) and (5,4): Area = (4-2)*(5-1) = 8
Using points (3,2) and (5,4): Area = (4-2)*(5-3) = 4
Total area = 4 + 8 + 4 = 16, and since we return the result modulo (10^9 + 7), the output is 8.
Solution
The solution should be placed in the /app/ directory.
Important: place your implementation at /app/solution.py so the verifier can run it.