#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 3020;
const int D = 1001;
int c[N][N], x[N], y[N], b[N], v[N][N], f[N][N], w[N];
int dis(int i, int j) { return max(abs(x[i] - x[j]), abs(y[i] - y[j])); }
int C(int x, int y) { return x >= y ? c[x][y] : 0; }
int main() {
  int n, m, r, i, j, u, d, l, ri, ans = 0, tmp;
  scanf("%d%d%d", &n, &m, &r);
  c[0][0] = 1;
  for (i = 1; i <= 2000; i++) {
    c[i][0] = 1;
    for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &x[i], &y[i], &b[i]);
    x[i] += D, y[i] += D;
    v[x[i]][y[i]]++;
  }
  for (i = 1; i <= 3000; i++)
    for (j = 1; j <= 3000; j++)
      v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      u = max(y[i], y[j]) - r;
      d = min(y[i], y[j]) + r;
      l = max(x[i], x[j]) - r;
      ri = min(x[i], x[j]) + r;
      if (l <= ri && u <= d)
        f[i][j] = v[ri][d] - v[l - 1][d] - v[ri][u - 1] + v[l - 1][u - 1];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (dis(i, j) > r) w[i]++;
    }
    ans = (ans +
           (long long)(C(n, m) - C(w[i], m) + mod) * b[i] % mod * b[i] % mod) %
          mod;
  }
  for (i = 1; i <= n - 1; i++)
    for (j = i + 1; j <= n; j++) {
      tmp = ((C(w[i], m) + C(w[j], m) -
              C(n - (n - w[i] + n - w[j] - f[i][j]), m)) %
                 mod +
             mod) %
            mod;
      ans = (ans +
             (long long)(C(n, m) - tmp + mod) * b[j] % mod * b[i] * 2 % mod) %
            mod;
    }
  printf("%d\n", ans);
  return 0;
}
