C. Infinite Fields

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

愛麗絲有一個 N \times M 的網格。位於行 i 和列 j 的單元格有一個值 A_{i, j}

愛麗絲通過無限次地重複網格建立了一個二維平面 P 。換句話說, P_{1, 1} ... P_{N, M} 等於 A_{1, 1} ... A_{N, M} ,以及 P_{1, M+1} ... P_{N, 2 \times M} P_{N+1, 1} ... P_{2 \times N, M} ,如此類推。

愛麗絲想計算無限二維平面 P 內一個矩形的數值之和。給定矩形在 P 中的邊是 x_1 x_2 y_1 y_2 ,請幫助愛麗絲找到矩形的數值之和。由於答案可能太大,請輸出你的答案對 10^9 + 7 取模的結果。


Alice has an N \times M grid. The cell at row i and column j has a value A_{i, j} .

Alice builds a 2D plane P by repeating the grid infinite times. In other words, P_{1, 1} ... P_{N, M} equal to A_{1, 1} ... A_{N, M} , as well as P_{1, M+1} ... P_{N, 2 \times M} , P_{N+1, 1} ... P_{2 \times N, M} , etc.

Alice would like to calculate the sum of the values of a rectangle inside the infinite 2D plane P . Given x_1 , x_2 , y_1 and y_2 which represent the edges of the rectangle in P , please help Alice to find the sum of values of the rectangle. As the answer may be too large, output your answer modulo 10^9 + 7 .

Input

第一行包含兩個整數, N M

接下來的 N 行各包含 M 個整數,代表網格中的數值。對於第 i+1 行, M 個整數分別代表 A_{i, 1} A_{i, M}

最後一行包含四個整數, x_1 x_2 y_1 y_2


The first line contains two integers, N and M .

The following N lines each contains M integers, representing the values in the grid. For line i+1 , the M integers represent A_{i, 1} to A_{i, M} respectively.

The final line contains four integers, x_1 , x_2 , y_1 and y_2 .

Output

輸出一個整數,即二維平面 P 中從行 x_1 x_2 (含),列 y_1 y_2 (含)的矩形的數值之和,對 10^9 + 7 取模。


Output one single integer, the sum of values of the rectangle from row x_1 to x_2 (inclusive), column y_1 to y_2 (inclusive) in the 2D plane P , modulo 10^9 + 7 .

Sample

Sample input

2 3
1 2 3
4 5 6
2 5 3 4

Sample output

28

Constraint and hint

對於全部測試數據,滿足:

1 \leq N, M \leq 1500

對於所有 1 \leq i \leq N 1 \leq j \leq M 1 \leq A_{i, j} \leq 10^6

1 \leq x_1, x_2, y_1, y_2 \leq 10^9 x_1 \leq x_2 , y_1 \leq y_2

子任務 分數 附加限制
1 29 x_1, x_2, y_1, y_2 \leq 1500
2 20 x_1 = y_1 = 1 , x_2 能被 N 整除, y_2 能被 M 整除
3 51 無附加限制

For all test data,

1 \leq N, M \leq 1500 ,

1 \leq A_{i, j} \leq 10^6 for all 1 \leq i \leq N and 1 \leq j \leq M ,

1 \leq x_1, x_2, y_1, y_2 \leq 10^9 , x_1 \leq x_2 , y_1 \leq y_2 .

Subtask Score Additional Constraints
1 29 x_1, x_2, y_1, y_2 \leq 1500
2 20 x_1 = y_1 = 1 , x_2 is divisible by N , y_2 is divisible by M
3 51 No additional constraints