#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 50;
const int mod = 1e9 + 7;
int n, m, r;
int x[N], y[N], b[N], a[N], d[N][N], sum[N][N];
long long c[N][N];
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 <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (abs(x[i] - x[j]) <= r && abs(y[i] - y[j]) <= r) a[i]++;
    }
  }
  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];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int lx = max(x[i] - r, x[j] - r), ly = max(y[i] - r, y[j] - r);
      int rx = min(x[i] + r, x[j] + r), ry = min(y[i] + r, y[j] + r);
      lx = max(1, lx);
      ly = max(ly, 1);
      rx = min(rx, 1000);
      ry = min(ry, 1000);
      if (lx > rx || ly > ry) continue;
      d[i][j] =
          sum[rx][ry] - sum[lx - 1][ry] - sum[rx][ly - 1] + sum[lx - 1][ly - 1];
      if (d[i][j] < 0) assert(0);
    }
  for (int i = 0; i < N; i++) c[i][0] = c[i][i] = 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;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans += ((c[n][m] - c[n - a[i]][m] - c[n - a[j]][m] +
               c[n - a[i] - a[j] + d[i][j]][m]) %
                  mod +
              mod) %
             mod * b[i] % mod * b[j] % mod;
      ans %= mod;
    }
  }
  printf("%lld\n", ans);
}
