Under construction

Still being built. Things may change

Ivoization

Time limit1.5sMemory limit128 MB

Summary
Sum the Ivoization values of every K by K submatrix, where Ivoization is the pairwise absolute-difference sum of all K^2 entries, modulo 10007.
Level

Hard8 of 10

Topics
Sorting, Prefix sum, Math, Implementation
Solved
No attempts yet

Problem

Ivo likes playing with matrices. His latest invention is an operation on a single square matrix, and he calls it Ivoization.

Ivoization turns one square matrix into one number. That number is the sum of the absolute differences over all pairs of numbers in the matrix. If the entries of the matrix are a1,a2,…,aK2a_1, a_2, \dots, a_{K^2}, the Ivoization value is ∑i=1K2∑j=1K2∣ai−aj∣\sum_{i=1}^{K^2} \sum_{j=1}^{K^2} |a_i - a_j|. Pairs with two equal indices are included, and they contribute 0. For example, the Ivoization value of a square matrix holding the numbers (1, 5, 2, 4) is 28.

∣1−1∣+∣1−5∣+∣1−2∣+∣1−4∣+∣5−5∣+∣5−1∣+∣5−2∣+∣5−4∣+∣2−2∣+∣2−1∣+∣2−5∣+∣2−4∣+∣4−4∣+∣4−1∣+∣4−5∣+∣4−2∣=28|1-1| + |1-5| + |1-2| + |1-4| + |5-5| + |5-1| + |5-2| + |5-4| + |2-2| + |2-1| + |2-5| + |2-4| + |4-4| + |4-1| + |4-5| + |4-2| = 28

Ivo wants to add up the Ivoization values of all square submatrices with exactly KK rows and exactly KK columns that lie entirely inside a matrix with NN rows and MM columns. Compute that sum.

Input

The first line contains three positive integers NN, MM and KK (1≤N,M,K≤5001 \le N, M, K \le 500).

Each of the next NN lines contains MM numbers AijA_{ij} (1≤Aij≤1091 \le A_{ij} \le 10^9).

All AijA_{ij} are distinct.

Output

Print SS, the sum of the Ivoization values of all square submatrices with side length KK, modulo 1000710007.

If KK is greater than NN or greater than MM, no such submatrix exists, so SS is 00.

Examples2

  1. Example 1

    Input
    3 3 2
    1 2 3
    4 5 6
    7 8 9
    
    Expected output
    112
    
  2. Example 2

    Input
    2 5 2
    17 1 2 3 10
    18 4 5 6 11
    
    Expected output
    240