#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
const int mod = 1e9 + 7;
const int N = 2e3 + 5;
long long quick_mod(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % c;
    b >>= 1;
    a = (a * a) % c;
  }
  return ans;
}
int n, m, r;
long long fac[N], inv[N], ttt[N];
void Get_Fac() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = (fac[i - 1] * i) % mod;
  inv[1] = 1;
  inv[0] = 1;
  for (int i = 2; i < N; ++i)
    inv[i] = ((-(long long)(mod / i) * inv[mod % i] % mod) + mod) % mod;
  for (int i = 2; i < N; ++i) inv[i] = inv[i - 1] * inv[i] % mod;
  for (int i = m; i < N; ++i) {
    ttt[i] = fac[i] * inv[m] % mod * inv[i - m] % mod;
  }
}
long long C(long long n, long long m) {
  if (m > n) return 0;
  return ttt[n];
}
int x[N], y[N];
long long at[N];
int mp[N][N];
int tmp[N][N];
bitset<N> v[N];
long long shengyu(int i) {
  long long res = 0;
  for (int j = 1; j <= n; ++j) {
    if (i == j) {
      res =
          (res + at[j] * (C(n, m) - C(n - v[i].count(), m) + mod) % mod) % mod;
      continue;
    }
    if (tmp[i][j]) {
      res = (res + at[j] * tmp[i][j] % mod) % mod;
      continue;
    }
    int a = (v[i] & v[j]).count(), b = v[i].count() - a, c = v[j].count() - a;
    tmp[i][j] = tmp[j][i] =
        ((C(n, m) - C(n - a - b, m) - C(n - a - c, m) + C(n - a - b - c, m)) %
             mod +
         mod) %
        mod;
    res = (res + at[j] * tmp[i][j] % mod) % mod;
  }
  return res;
}
bool judge(int i, int j) {
  if (abs(x[i] - x[j]) > r || abs(y[i] - y[j]) > r)
    return false;
  else
    return true;
}
void solve() {
  scanf("%d%d%d", &n, &m, &r);
  Get_Fac();
  for (int i = 1; i <= n; ++i) scanf("%d%d%lld", &x[i], &y[i], &at[i]);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      if (judge(i, j)) {
        mp[j][i] = mp[i][j] = 1;
        v[i].set(j);
        v[j].set(i);
      }
    }
  }
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    res = (res + at[i] * shengyu(i) % mod) % mod;
  }
  printf("%lld\n", res);
}
void init_() {}
int main() {
  init_();
  { solve(); }
  return 0;
}
