#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 2e3;
constexpr int maxf = 2e3 + 5;
constexpr long long mod = 1e9 + 7;
long long fac[maxn + 1];
long long invfac[maxn + 1];
long long binpow(long long b, long long e) {
  long long acc = 1;
  for (; e > 0; e >>= 1, b = b * b % mod)
    if (e & 1) acc = acc * b % mod;
  return acc;
}
long long inv(long long x) { return binpow(x, mod - 2); }
void calcfac() {
  fac[0] = 1;
  for (int i = 1; i <= maxf; i++) fac[i] = fac[i - 1] * i % mod;
  invfac[maxf - 1] = inv(fac[maxf - 1]);
  for (int i = maxf - 2; i >= 0; i--) invfac[i] = invfac[i + 1] * (i + 1) % mod;
}
long long ncr(long long n, long long r) {
  if (r > n) return 0;
  return fac[n] * invfac[n - r] % mod * invfac[r] % mod;
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  calcfac();
  int n, m, r;
  cin >> n >> m >> r;
  vector<vector<int>> pref(1e3 + 1, vector<int>(1e3 + 1));
  vector<array<long long, 3>> arr(n);
  for (int i = 0; i < n; i++) {
    int x, y, b;
    cin >> x >> y >> b;
    x--, y--;
    arr[i] = {x, y, b};
    pref[x + 1][y + 1] = 1;
  }
  for (int i = 1; i <= 1e3; i++)
    for (int j = 1; j <= 1e3; j++)
      pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
  auto rect = [&](int x1, int x2, int y1, int y2) {
    if (y1 > y2 or x1 > x2) return 0;
    x2++, y2++;
    x1 = max(x1, 0);
    y1 = max(y1, 0);
    x2 = min(x2, 1000);
    y2 = min(y2, 1000);
    return pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
  };
  long long acc = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int h_i =
          rect(arr[i][0] - r, arr[i][0] + r, arr[i][1] - r, arr[i][1] + r);
      int h_j =
          rect(arr[j][0] - r, arr[j][0] + r, arr[j][1] - r, arr[j][1] + r);
      int h_e = h_i + h_j -
                rect(max(arr[j][0] - r, arr[i][0] - r),
                     min(arr[j][0] + r, arr[i][0] + r),
                     max(arr[j][1] - r, arr[i][1] - r),
                     min(arr[j][1] + r, arr[i][1] + r));
      acc = (acc + (ncr(n, m) - ncr(n - h_i, m) - ncr(n - h_j, m) +
                    ncr(n - h_e, m) + 2 * mod) *
                       arr[i][2] % mod * arr[j][2]) %
            mod;
    }
  cout << acc << "\n";
}
