Under construction

Still being built. Things may change

Travel around China

Time limit8sMemory limit512 MB

Summary
Given a 3 by m grid of city costs, sum the minimum route cost over all ordered pairs of distinct cities, where each visit to a city adds its cost, modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, Shortest path, Matrix
Solved
No attempts yet

Problem

Rikka is a rich girl.

She would like to visit the beautiful cities of China. The city locations in China can be simply regarded as a grid with nn rows and mm columns. Rows are numbered from 11 to nn from north to south, and columns are numbered from 11 to mm from west to east. The city in row ii and column jj is called (i,j)(i, j).

City (i,j)(i, j) has a direct expressway to city (x,y)(x, y) if and only if ∣i−x∣+∣j−y∣=1|i - x| + |j - y| = 1. Because New Year is coming, the expressways are open to the public free of charge.

When Rikka travels from city (i,j)(i, j) to (x,y)(x, y), she can only use expressways. The cost of a route is the sum of the costs of all cities she visits, including the starting and ending cities. If the route includes city (i,j)(i, j), she spends ai,ja_{i, j} yuan. If she visits city (i,j)(i, j) a total of kk times, she spends k⋅ai,jk \cdot a_{i, j} yuan, because there are always enough shopping malls for her to spend money.

Rikka is a fanciful girl, and she does not even pick a starting and ending city. Let f(i,j,x,y)f(i, j, x, y) be the minimal cost of a route from city (i,j)(i, j) to city (x,y)(x, y). She wants the value

∑i=1n∑x=1n∑j=1m∑y=1m[(i,j)≠(x,y)]f(i,j,x,y)\sum_{i=1}^{n} \sum_{x=1}^{n} \sum_{j=1}^{m} \sum_{y=1}^{m} [(i, j) \neq (x, y)] f(i, j, x, y)

Since the answer may be very large, output it modulo 109+710^9 + 7.

Input

The first line contains two integers nn and mm.

Each of the following nn lines contains mm integers. The jj-th number in the ii-th line is ai,ja_{i, j}.

It is guaranteed that n=3n = 3, 1≤m≤1.5⋅1051 \le m \le 1.5 \cdot 10^5, and 1≤ai,j≤1091 \le a_{i, j} \le 10^9.

Output

Output a single integer, the answer modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    3 3
    1 1 1
    1 100 1
    1 1 1
    
    Expected output
    1808