My Solution
```
/**
 * final formula should be
 * comb(m * n - 2, k - 2) * (m ^ 2) * [1 * (n - 1) + 2 * (n - 2) + 3 * (n - 3) + ... + (n - 1) * 1] +
 * comb(m * n - 2, k - 2) * (n ^ 2) * [1 * (m - 1) + 2 * (m - 2) + 3 * (m - 3) + ... + (m - 1) * 1]
 * =
 * comb(m * n - 2, k - 2) * (m ^ 2) * comb(n + 1, 3) +
 * comb(m * n - 2, k - 2) * (n ^ 2) * comb(m + 1, 3)
 * =
 * comb(m * n - 2, k - 2) * [(m ^ 2) * comb(n + 1, 3) + (n ^ 2) * comb(m + 1, 3)]
 *
 * Time Complexity: O(m * n)
 * Space Complexity: O(1)
 */
class Solution {
 private:
  static constexpr int mod = 1000000007;

 public:
  int distanceSum(const int m, const int n, const int k) {
    return mult(
      comb(subtract(mult(m, n), 2), subtract(k, 2)),
      plus(
        mult(mult(m, m), comb(plus(n, 1), 3)),
        mult(mult(n, n), comb(plus(m, 1), 3))
      )
    );
  }

 private:
  int mult(const int a, const int b) {
    return static_cast<int>(static_cast<long long>(a) * b % mod);
  }

  int plus(const int a, const int b) {
    return (a + b) % mod;
  }

  int subtract(const int a, const int b) {
    return (mod + a - b) % mod;
  }

  int factorial(const int a) {
    int ret = 1;
    for (int i = 2; i < a + 1; ++i) {
      ret = mult(ret, i);
    }
    return ret;
  }

  int inv(const int a) {
    int ret = 1;
    int base = a;
    for (int p = mod - 2; p > 0; p >>= 1) {
      if ((p & 1) == 1) {
        ret = mult(ret, base);
      }
      base = mult(base, base);
    }
    return ret;
  }

  int comb(const int a, const int b) {
    return a < b ? 0 : mult(factorial(a), inv(mult(factorial(b), factorial(a - b))));
  }
};
```
['C++']