#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 9;
const int MOD = 1e9 + 7;
int mod = 999998639;
long long fact(long long x, long long y) {
  long long ans = 1;
  for (int i = 0; i < y; i++) ans *= x;
  return ans;
}
inline long long qpow(long long b, long long e, long long m = MOD) {
  long long a = 1;
  for (; e; e >>= 1, b = b * b % m)
    if (e & 1) a = a * b % m;
  return a;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long d = exgcd(b, a % b, x, y);
  long long z = x;
  x = y, y = z - y * (a / b);
  return d;
}
int s[1009][1009];
long long fac[2009], c[2009][2009];
struct node {
  int x, y, b;
} a[maxn];
int main() {
  fac[0] = 1;
  for (int i = 1; i < 2009; i++) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  for (int i = 0; i < 2009; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
      c[i][j] %= MOD;
    }
  }
  int n, m, r;
  while (scanf("%d%d%d", &n, &m, &r) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].b);
      s[a[i].x][a[i].y] += 1;
    }
    for (int i = 1; i < 1009; i++) {
      for (int j = 1; j < 1009; j++) {
        s[i][j] = s[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
      }
    }
    long long ans = 0, all = c[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        long long temp = all;
        long long lx = max(1, a[i].x - r), ly = max(1, a[i].y - r),
                  rx = min(1000, a[i].x + r), ry = min(1000, a[i].y + r);
        long long onlyi =
            s[rx][ry] - s[lx - 1][ry] - s[rx][ly - 1] + s[lx - 1][ly - 1];
        long long llx = max(1, a[j].x - r), lly = max(1, a[j].y - r),
                  rrx = min(1000, a[j].x + r), rry = min(1000, a[j].y + r);
        long long onlyj = s[rrx][rry] - s[llx - 1][rry] - s[rrx][lly - 1] +
                          s[llx - 1][lly - 1];
        long long comlx = max(lx, llx), comly = max(ly, lly),
                  comrx = min(rx, rrx), comry = min(ry, rry);
        long long com = 0;
        if (comlx <= comrx && comly <= comry) {
          com = s[comrx][comry] - s[comlx - 1][comry] - s[comrx][comly - 1] +
                s[comlx - 1][comly - 1];
        }
        temp -= c[n - onlyi][m], temp %= MOD;
        temp -= c[n - onlyj][m], temp %= MOD;
        temp += c[n - onlyi - onlyj + com][m], temp %= MOD,
            temp = (temp + MOD) % MOD;
        ans += temp * a[i].b % MOD * a[j].b;
        ans %= MOD;
      }
    }
    printf("%lld\n", ans);
  }
}
