#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
const int mo = 1e9 + 7;
bitset<2000> p[N];
int x[N], y[N], w[N], s[N];
long long f[N], ny[N];
long long qk(long long x, int y) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % mo;
    x = x * x % mo;
  }
  return r;
}
long long c(long long x, long long y) {
  return x < y ? 0 : f[x] * ny[y] % mo * ny[x - y] % mo;
}
int main() {
  int n, m, R, ans = 0;
  f[0] = ny[0] = 1;
  scanf("%d%d%d", &n, &m, &R);
  for (auto i = (1); i <= (n); ++i) {
    f[i] = f[i - 1] * i % mo;
    ny[i] = qk(f[i], mo - 2);
  }
  for (auto i = (0); i <= (n - 1); ++i) scanf("%d%d%d", &x[i], &y[i], &w[i]);
  for (auto i = (0); i <= (n - 1); ++i)
    for (auto j = (0); j <= (n - 1); ++j)
      if (abs(x[i] - x[j]) <= R && abs(y[i] - y[j]) <= R) p[i][j] = p[j][i] = 1;
  for (auto i = (0); i <= (n - 1); ++i) s[i] = p[i].count();
  for (auto i = (0); i <= (n - 1); ++i)
    for (auto j = (0); j <= (n - 1); ++j) {
      int ss = (p[i] | p[j]).count();
      ans = (ans + (mo * 2 + c(n, m) - c(n - s[i], m) - c(n - s[j], m) +
                    c(n - ss, m)) *
                       w[i] % mo * w[j]) %
            mo;
    }
  printf("%d\n", ans);
}
