#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2010;
long long qpow(long long x, long long times) {
  long long res = 1;
  while (times) {
    if (times & 1) res = 1LL * res * x % mod;
    times >>= 1;
    x = 1LL * x * x % mod;
  }
  return res;
}
long long jc[N], ny[N];
void init() {
  jc[0] = 1;
  for (long long i = 1; i <= N - 1; i++) jc[i] = 1LL * jc[i - 1] * i % mod;
  ny[0] = 1;
  for (long long i = 1; i <= N - 1; i++) ny[i] = qpow(jc[i], mod - 2);
}
long long C(long long n, long long m) {
  if (n < 0 || m < 0) return 0;
  if (m > n) return 0;
  return jc[n] * ny[m] % mod * ny[n - m] % mod;
}
struct node {
  long long x, y, val;
} Node[2010];
long long mapp[1005][1005];
long long n, m, r;
void cal() {
  for (long long i = 1; i <= 1000; i++) {
    for (long long j = 1; j <= 1000; j++) {
      mapp[i][j] =
          mapp[i][j] + mapp[i - 1][j] + mapp[i][j - 1] - mapp[i - 1][j - 1];
    }
  }
}
long long cals(long long x1, long long x2, long long y1, long long y2) {
  if (x2 < x1 || y2 < y1) return 0;
  x1 = max(x1, 1ll);
  x2 = max(x2, 1ll);
  y1 = max(y1, 1ll);
  y2 = max(y2, 1ll);
  x1 = min(x1, 1000ll);
  x2 = min(x2, 1000ll);
  y1 = min(y1, 1000ll);
  y2 = min(y2, 1000ll);
  return mapp[x2][y2] - mapp[x1 - 1][y2] - mapp[x2][y1 - 1] +
         mapp[x1 - 1][y1 - 1];
}
signed main() {
  init();
  cin >> n >> m >> r;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &Node[i].x, &Node[i].y, &Node[i].val);
    mapp[Node[i].x][Node[i].y]++;
  }
  cal();
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      long long tmp = Node[i].val * Node[j].val % mod;
      long long maxx = max(Node[i].x, Node[j].x);
      long long minx = min(Node[i].x, Node[j].x);
      long long maxy = max(Node[i].y, Node[j].y);
      long long miny = min(Node[i].y, Node[j].y);
      long long tmpp = C(n, m);
      tmpp = (tmpp - C(n - cals(Node[i].x - r, Node[i].x + r, Node[i].y - r,
                                Node[i].y + r),
                       m)) %
             mod;
      tmpp += mod;
      tmpp %= mod;
      tmpp = (tmpp - C(n - cals(Node[j].x - r, Node[j].x + r, Node[j].y - r,
                                Node[j].y + r),
                       m)) %
             mod;
      tmpp += mod;
      tmpp %= mod;
      long long tmppp =
          n - cals(Node[j].x - r, Node[j].x + r, Node[j].y - r, Node[j].y + r) -
          cals(Node[i].x - r, Node[i].x + r, Node[i].y - r, Node[i].y + r) +
          cals(maxx - r, minx + r, maxy - r, miny + r);
      tmpp += C(tmppp, m);
      tmpp %= mod;
      ans += tmpp * tmp % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
}
