Python | DP | O(m*n)
D[i,j] is the summation of manhattan distance of pairs when one piece is placed on the right-bottom corner of a grid with width i and height j
S[i] is the summa
D[i,j] is the summation of manhattan distance of pairs when one piece is placed on the right-bottom corner of a grid with width i and height j
S[i] is the summation of manhattan distance of pairs when two pieces placed on a grid with width 1 and height i
Let R be the total summation of D[i,j]
Then the answer is (2*R - S[m]*n - S[n]*m)*comb(m*n-2,k-2)

# Code
```python3 []
class Solution:
    def distanceSum(self, m: int, n: int, k: int) -> int:
        MOD = 10**9 + 7
        S = defaultdict(int)
        for i in range(max(m,n)):
            S[i+1] = S[i] + i*(i+1)//2
        D = defaultdict(int)
        for i in range(1,m+1):
            for j in range(1,n+1):
                D[i,j] = D[i-1,j]+(2*i-3+j)*j//2
        res = 0
        for i in range(1,m+1):
            for j in range(1,n+1):
                res += D[i,j]
        res = 2*res - S[m]*n - S[n]*m
        return (res*comb(m * n - 2, k - 2) % MOD)%MOD        
```
['Python3']