#include <bits/stdc++.h>
using namespace std;
long long inline read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const long long maxn = 2010, mod = 1e9 + 7;
long long n, m, r, s[maxn][maxn], x[maxn], y[maxn], w[maxn];
long long fac[maxn], finv[maxn], inv[maxn], f[maxn];
void init() {
  fac[1] = fac[0] = finv[1] = finv[0] = inv[1] = 1;
  for (long long i = 2; i <= 2000; i++) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    finv[i] = 1ll * finv[i - 1] * inv[i] % mod;
  }
}
long long C(long long n, long long m) {
  if (m < 0) return 0;
  if (n < m) return 0;
  return 1ll * fac[n] * finv[m] % mod * finv[n - m] % mod;
}
long long S(long long a, long long b, long long c, long long d) {
  if (a > c || b > d) return 0;
  return s[c][d] - s[c][b - 1] - s[a - 1][d] + s[a - 1][b - 1];
}
signed main() {
  n = read();
  m = read();
  r = read();
  init();
  for (long long i = 1; i <= n; i++) {
    x[i] = read();
    y[i] = read();
    w[i] = read();
    s[x[i]][y[i]]++;
  }
  for (long long i = 1; i <= 1000; i++)
    for (long long j = 1; j <= 1000; j++)
      s[i][j] = s[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long tot = S(max(x[i] - r, 1ll), max(y[i] - r, 1ll),
                      min(x[i] + r, 1000ll), min(y[i] + r, 1000ll));
    ans = (ans +
           1ll * w[i] * w[i] % mod * (C(n, m) - C(n - tot, m) + mod) % mod) %
          mod;
    f[i] = tot;
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = i + 1; j <= n; j++) {
      long long tot = S(max(x[i] - r, 1ll), max(y[i] - r, 1ll),
                        min(x[i] + r, 1000ll), min(y[i] + r, 1000ll));
      tot += S(max(x[j] - r, 1ll), max(y[j] - r, 1ll), min(x[j] + r, 1000ll),
               min(y[j] + r, 1000ll));
      long long a = x[i], b = y[i], c = x[j], d = y[j];
      if (a > c) swap(a, c), swap(b, d);
      if (d >= b)
        tot -= S(max(c - r, 1ll), max(d - r, 1ll), min(a + r, 1000ll),
                 min(b + r, 1000ll));
      else
        tot -= S(max(c - r, 1ll), max(b - r, 1ll), min(a + r, 1000ll),
                 min(d + r, 1000ll));
      ans = (ans + 2ll * w[i] * w[j] % mod *
                       (((C(n, m) - C(n - f[i], m) + mod) % mod -
                         C(n - f[j], m) + mod) %
                            mod +
                        C(n - tot, m)) %
                       mod) %
            mod;
    }
  cout << ans;
  return 0;
}
