#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, mod = 1e9 + 7;
int n, m, r, x[N], y[N], b[N], sum[N][N], c[N][N];
bitset<N> seg[N];
long long ans;
int cal(int l1, int r1, int l2, int r2) {
  if (l1 > l2 || r1 > r2) return 0;
  l1 = max(l1, 1);
  r1 = max(r1, 1);
  l2 = min(l2, 1000);
  r2 = min(r2, 1000);
  return sum[l2][r2] - sum[l2][r1 - 1] - sum[l1 - 1][r2] + sum[l1 - 1][r1 - 1];
}
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &x[i], &y[i], &b[i]);
    sum[x[i]][y[i]]++;
  }
  for (int i = 1; i <= 1000; ++i) {
    for (int j = 1; j <= 1000; ++j) {
      sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (int i = 0; i <= n; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= r) {
        seg[i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      long long v = 1ll * b[i] * b[j] % mod;
      long long cnt = (seg[i] & seg[j]).count();
      long long v1 = cal(x[i] - r, y[i] - r, x[i] + r, y[i] + r);
      long long v2 = cal(x[j] - r, y[j] - r, x[j] + r, y[j] + r);
      long long noi = c[n - v1][m];
      long long noj = c[n - v2][m];
      long long noij = c[n - v1 - v2 + cnt][m];
      long long no = noi + noj - noij;
      long long ways = c[n][m] - no;
      ways %= mod;
      if (ways < 0) ways += mod;
      ans = (ans + ways * v % mod) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
