#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
const int MOD = 1e9 + 7;
int x[N], y[N], b[N], in[N], ot[N], n, m, r, c[N][N], ans;
bitset<N> op[N], tp;
bool ok(int i, int j) { return abs(x[i] - x[j]) <= r && abs(y[i] - y[j]) <= r; }
int main() {
  for (int i = 0; i < N; ++i) c[i][0] = 1;
  for (int i = 1; i < N; ++i)
    for (int j = 1; j <= i; ++j)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < n; ++i) scanf("%d %d %d", &x[i], &y[i], &b[i]);
  for (int i = 0; i < n; ++i) {
    op[i].reset();
    op[i][i] = 1;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      if (ok(i, j)) op[i][j] = 1;
    }
  }
  for (int i = 0, d; i < n; ++i) {
    d = op[i].count();
    ot[i] = c[n - d][m];
    in[i] = (c[n][m] - c[n - d][m] + MOD) % MOD;
    ans = (ans + 1ll * b[i] * b[i] % MOD * in[i]) % MOD;
  }
  for (int i = 0, d, k; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      tp = op[i] | op[j];
      d = tp.count();
      k = (1ll * ot[i] + 1ll * ot[j] - c[n - d][m] + MOD) % MOD;
      ans =
          (1ll * ans + 1ll * 2 * b[i] * b[j] % MOD * (c[n][m] - k + MOD)) % MOD;
    }
  }
  printf("%d\n", ans);
}
