#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 100;
const long long mod = 1e9 + 7;
int s[maxn][maxn], x[maxn], y[maxn], n, m, R;
long long fac[maxn * 2], inv[maxn * 2], B[maxn];
long long calc(int x, int y, int _x, int _y) {
  x = max(x, 1);
  y = max(y, 1);
  _x = min(_x, 1000);
  _y = min(_y, 1000);
  if (x > _x || y > _y) return 0;
  return s[_x][_y] - s[x - 1][_y] - s[_x][y - 1] + s[x - 1][y - 1];
}
long long power(long long x, long long y) {
  long long ret;
  if (y == 0) return 1;
  ret = power(x, y / 2);
  ret = 1LL * ret * ret % mod;
  if (y % 2) ret = ret * x % mod;
  return ret;
}
void pre() {
  for (int i = 1; i <= 1010; i++) {
    for (int j = 1; j <= 1010; j++) {
      s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
    }
  }
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= n + 100; i++) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= n + 100; i++) {
    inv[i] = power(fac[i], mod - 2);
  }
}
long long C(int n, int m) {
  if (m > n) return 0;
  return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
long long f(long long x) { return (x % mod + mod) % mod; }
int main() {
  long long w, u, v, tmp, ans;
  scanf("%d%d%d", &n, &m, &R);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%lld", &x[i], &y[i], &B[i]);
    s[x[i]][y[i]]++;
  }
  pre();
  ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) {
        tmp = 1LL * B[i] * B[j] % mod;
        u = calc(x[i] - R, y[i] - R, x[i] + R, y[i] + R);
        ans += 1LL * tmp * f(C(n, m) - C(n - u, m)) % mod;
        ans %= mod;
        continue;
      }
      tmp = 1LL * B[i] * B[j] % mod;
      w = calc(max(x[i], x[j]) - R, max(y[i], y[j]) - R, min(x[i], x[j]) + R,
               min(y[i], y[j]) + R);
      u = calc(x[i] - R, y[i] - R, x[i] + R, y[i] + R) - w;
      v = calc(x[j] - R, y[j] - R, x[j] + R, y[j] + R) - w;
      ans += 1LL * f(C(n, m) - C(n - w, m)) * tmp % mod;
      ans = ans % mod;
      int n2 = n - w;
      ans += 1LL *
             f(C(n2, m) - C(n2 - u, m) - C(n2 - v, m) + C(n2 - u - v, m)) *
             tmp % mod;
      ans = ans % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
