#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e3 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int sum[maxn][maxn], v[maxn];
int x[maxn], y[maxn];
long long ww[maxn], w[maxn];
struct point {
  int xx, yy;
};
long long quick(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long inv(long long x) { return quick(x, mod - 2); }
long long fac[maxn], invfac[maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i) fac[i] = (fac[i - 1] * i) % mod;
  invfac[maxn - 1] = inv(fac[maxn - 1]);
  for (int i = maxn - 2; i >= 0; --i)
    invfac[i] = (invfac[i + 1] * (i + 1)) % mod;
}
long long C(int n, int m) {
  if (n < m || m < 0) return 0;
  return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
struct node {
  int val, id;
};
bool cmp(node v1, node v2) { return v1.val < v2.val; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int m, n, r;
  cin >> n >> m >> r;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> w[i];
    sum[x[i]][y[i]]++;
  }
  for (int i = 1; i < 2001; ++i) {
    for (int j = 1; j < 2001; ++j) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= r) {
        v[i]++;
        ww[i] += w[j];
      }
    }
  }
  long long ans = 0;
  long long all = C(n, m);
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      ;
      ;
      point a, b, c, d;
      a.xx = x[i] - r, a.yy = y[i] - r;
      b.xx = x[i] - r, b.yy = y[i] + r;
      c.xx = x[i] + r, c.yy = y[i] - r;
      d.xx = x[i] + r, d.yy = y[i] + r;
      point a1, b1, c1, d1;
      a1.xx = x[j] - r, a1.yy = y[j] - r;
      b1.xx = x[j] - r, b1.yy = y[j] + r;
      c1.xx = x[j] + r, c1.yy = y[j] - r;
      d1.xx = x[j] + r, d1.yy = y[j] + r;
      node tmp1[4], tmp[4];
      long long num = (C(n - v[i], m) + C(n - v[j], m)) % mod;
      bool f1 = 0, f2 = 0;
      ;
      tmp1[0] = {a.xx, 1}, tmp1[1] = {d.xx, 1}, tmp1[2] = {a1.xx, 2},
      tmp1[3] = {d1.xx, 2};
      sort(tmp1, tmp1 + 4, cmp);
      if (tmp1[0].id == tmp1[2].id || tmp1[1].val == tmp1[2].val) f1 = 1;
      tmp[0] = {a.yy, 1}, tmp[1] = {d.yy, 1}, tmp[2] = {a1.yy, 2},
      tmp[3] = {d1.yy, 2};
      sort(tmp, tmp + 4, cmp);
      if (tmp[2].id == tmp[0].id || tmp[1].val == tmp[2].val) f2 = 1;
      if (((f1 && f2) || i == j)) {
        int l = max(0, tmp[1].val), r = min(1000, tmp[2].val),
            tp = max(0, tmp1[1].val), bt = min(1000, tmp1[2].val);
        ;
        ;
        ;
        ;
        int tt = sum[bt][r] - sum[bt][max(l - 1, 0)] - sum[max(tp - 1, 0)][r] +
                 sum[max(tp - 1, 0)][max(l - 1, 0)];
        ;
        num = (num - C(n - v[i] - v[j] + tt, m) % mod + mod) % mod;
      } else
        num = (num - C(n - v[i] - v[j], m) % mod + mod) % mod;
      num = (all - num + mod) % mod;
      ;
      if (i == j)
        ans = (ans + w[i] * w[i] % mod * num % mod) % mod;
      else
        ans = (ans + 2ll * w[i] * w[j] % mod * num % mod) % mod;
    }
  }
  cout << ans << '\n';
  return 0;
}
