#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
const int mod = 1e9 + 7;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar();
  return x * f;
}
int inc(int x, int y) { return (x + y >= mod) ? (x + y - mod) : (x + y); }
int del(int x, int y) { return (x - y < 0) ? (x - y + mod) : (x - y); }
namespace math {
int qpow(int a, int x, int mo) {
  int res = 1;
  while (x) {
    if (x & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    x >>= 1;
  }
  return res;
}
int Fac[N], invFac[N];
void Finit(int n) {
  Fac[0] = 1;
  invFac[0] = 1;
  for (int i = 1; i <= n; i++) Fac[i] = 1ll * Fac[i - 1] * i % mod;
  invFac[n] = qpow(Fac[n], mod - 2, mod);
  for (int i = n - 1; i >= 1; i--)
    invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {
  if (m == 0) return 1;
  if (n < m || m < 0) return 0;
  return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod);
}
}  // namespace math
bitset<N> p[N];
int c[N][N];
int main() {
  int n = read(), m = read(), R = read();
  int siz = 1e3;
  math::Finit(n);
  vector<int> X(n + 1), Y(n + 1), Z(n + 1);
  for (int i = 1; i <= n; i++) X[i] = read(), Y[i] = read(), Z[i] = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (max(abs(X[i] - X[j]), abs(Y[i] - Y[j])) <= R) p[i].set(j);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      c[i][j] = math::C(n - (p[i] | p[j]).count(), m);
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int o = inc(del(del(math::C(n, m), c[i][i]), c[j][j]), c[i][j]);
      res = inc(res, 1ll * o * Z[i] % mod * Z[j] % mod);
    }
  }
  cout << res << endl;
}
