QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB
[0]

# 3725. Skewness

Statistics

Bobo has a matrix A with n rows and n columns.

For submatrix with upper-left corner (x1,y1) and lower-right corner (x2,y2) (1x1x2n,1y1y2n), he defined its skewness S(x1,y1,x2,y2)=(x2i=x1y2j=y1Ai,j)3.

Bobo would like to know the sum of skewness of all submatrices modulo (109+7).

Input

The input contains zero or more test cases and is terminated by end-of-file. For each test case:

The first line contains an integer n.

The i-th of following n lines contains n integers Ai,1,Ai,2,,Ai,n.

  • 1n1000
  • 0Ai,j109
  • The number of test cases does not exceed 10.

Output

For each case, output an integer which denotes the sum.

Sample Input

2
0 1
1 0
3
0 1 0
1 1 0
1 0 1

Sample Output

14
448