#K44082. Matrix K Calculation

    ID: 27452 Type: Default 1000ms 256MiB

Matrix K Calculation

Matrix K Calculation

Given an (N \times N) matrix of integers, your task is to compute the value of (K) defined by the following formula:

[ K = \left(\sum_{i=1}^{N} r_i\right) \times \left(\sum_{j=1}^{N} c_j\right) \mod (10^9+7)]

where (r_i) is the sum of the elements in the (i)-th row and (c_j) is the sum of the elements in the (j)-th column. Note that the sum over rows and columns is taken with the entire matrix, and the final result is taken modulo (10^9+7).

Input is read from standard input and the result must be written to standard output.

inputFormat

The first line contains a single integer (N), the dimension of the matrix. This is followed by (N) lines, each containing (N) space-separated integers representing the matrix.

outputFormat

Output a single integer representing the value of (K) computed using the formula above.## sample

3
1 2 3
4 5 6
7 8 9
2025