#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
inline int read() {
  register int x;
  register char c(getchar());
  register bool k;
  while ((c < '0' || c > '9') && c ^ '-')
    if ((c = getchar()) == EOF) exit(0);
  if (c ^ '-')
    x = c & 15, k = 1;
  else
    x = 0, k = 0;
  while (c = getchar(), c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c & 15);
  return k ? x : -x;
}
const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;
int X[maxn], Y[maxn], B[maxn];
int table[maxn][maxn], lx[maxn], ly[maxn], ux[maxn], uy[maxn];
int cnt[maxn];
long long fac[maxn], inv[maxn];
int Sum(int tlx, int tly, int tux, int tuy) {
  if (tlx > tux || tly > tuy) return 0;
  return table[tux][tuy] - table[tlx - 1][tuy] - table[tux][tly - 1] +
         table[tlx - 1][tly - 1];
}
void init() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i < maxn; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  fac[0] = fac[1] = 1;
  for (int i = 2; i < maxn; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = inv[i - 1] * inv[i] % mod;
  }
}
int C(int n, int m) {
  if (n < m) return 0;
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  init();
  int n = read(), m = read(), r = read();
  for (int i = 0; i < n; i++) {
    X[i] = read(), Y[i] = read(), B[i] = read();
    table[X[i]][Y[i]]++;
  }
  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 1000; j++) {
      table[i][j] =
          table[i][j] + table[i - 1][j] + table[i][j - 1] - table[i - 1][j - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    lx[i] = max(1, X[i] - r);
    ly[i] = max(1, Y[i] - r);
    ux[i] = min(1000, X[i] + r);
    uy[i] = min(1000, Y[i] + r);
    cnt[i] = Sum(lx[i], ly[i], ux[i], uy[i]);
  }
  long long ans = 0, all = C(n, m);
  for (int i = 0; i < n; i++) {
    ans =
        (ans + (all - C(n - cnt[i], m) + mod) % mod * B[i] % mod * B[i] % mod) %
        mod;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int tlx = max(lx[i], lx[j]);
      int tly = max(ly[i], ly[j]);
      int tux = min(ux[i], ux[j]);
      int tuy = min(uy[i], uy[j]);
      int cnt1 = cnt[i] + cnt[j] - Sum(tlx, tly, tux, tuy);
      ans = (ans + (all - C(n - cnt[i], m) - C(n - cnt[j], m) + C(n - cnt1, m) +
                    2 * mod) %
                       mod * B[i] % mod * B[j] % mod) %
            mod;
    }
  }
  cout << ans << '\n';
  return 0;
}
