#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (!isdigit(c)) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  x = flag ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 2e3 + 10;
const int mod = 1e9 + 7;
int qpow(ll a, int n) {
  ll re = 1;
  a %= mod;
  while (n) {
    if (n & 1) re = re * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return re % mod;
}
int fact[maxn], finv[maxn], inv[maxn];
int c(int n, int m) {
  if (n <= 0 || m <= 0 || n < m) return 0;
  return (ll)fact[n] * finv[m] % mod * finv[n - m] % mod;
}
int x[maxn], y[maxn], v[maxn], sum[maxn][maxn];
int cnt[maxn];
ll query(int u, int d, int l, int r) {
  if (l > r || u > d) return 0;
  ll ans = 0;
  u = max(u, 1);
  l = max(l, 1);
  d = min(d, 1000), r = min(r, 1000);
  ans = sum[d][r] - sum[u - 1][r] - sum[d][l - 1] + sum[u - 1][l - 1];
  return (ans % mod + mod) % mod;
}
int main() {
  fact[0] = 1;
  fact[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < maxn; ++i) {
    fact[i] = (ll)i * fact[i - 1] % mod;
    inv[i] = -(ll)(mod / i) * inv[mod % i] % mod;
    inv[i] = (inv[i] + mod) % mod;
    finv[i] = (ll)inv[i] * finv[i - 1] % mod;
  }
  int n, m, r;
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", x + i, y + i, v + i);
    sum[x[i]][y[i]] += 1;
  }
  for (int i = 1; i <= 1000; ++i) {
    for (int j = 1; j <= 1000; ++j) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    cnt[i] = query(x[i] - r, x[i] + r, y[i] - r, y[i] + r);
    ll c1 = c(n, m) - c(n - cnt[i], m) + mod;
    ans += c1 * v[i] % mod * v[i] % mod;
    ans %= mod;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      ll c1 = query(max(x[i], x[j]) - r, min(x[i], x[j]) + r,
                    max(y[i], y[j]) - r, min(y[i], y[j]) + r);
      ll c2 = cnt[i] - c1, c3 = cnt[j] - c1;
      ll temp = c(n, m) - c(n - c1, m);
      temp += c(n - c1, m) - c(n - c1 - c2, m) - c(n - c1 - c3, m) +
              c(n - c1 - c2 - c3, m);
      temp = (temp % mod + mod) % mod;
      ans += temp * v[i] % mod * v[j] * 2 % mod;
      ans %= mod;
    }
  }
  write(ans);
  putchar('\n');
}
