#include <bits/stdc++.h>
using namespace std;
constexpr int seed = 131;
constexpr long long LLMAX = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-8;
constexpr int MAXN = 2e3 + 10;
constexpr int hmod1 = 0x48E2DCE7;
constexpr int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inline int sqr(int x) { return x * x; }
inline double sqr(double x) { return x * x; }
inline int mul(int x, int y) { return 1ll * x * y % MOD; }
inline int sub(int x, int y) { return x >= y ? x - y : MOD + x - y; }
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return (x > 0 ? 1 : -1);
}
inline long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return sum;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d;
  (b == 0 ? (x = 1, y = 0, d = a)
          : (d = exgcd(b, a % b, y, x), y -= a / b * x));
  return d;
}
int x[MAXN], y[MAXN], b[MAXN], num[MAXN];
int fac[MAXN], rfac[MAXN], ds[MAXN], is[2010][2010], id[MAXN], bit[MAXN];
int C(int n, int m) {
  if (m > n) return 0;
  return 1ll * fac[n] * rfac[m] % MOD * rfac[n - m] % MOD;
}
bool judge(int i, int j, int r) {
  return max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= r;
}
void update(int x, int y) {
  for (int i = x; i <= 2000; i += (i & (-i))) bit[i] += y;
}
int sum(int x) {
  int ans = 0;
  for (int i = x; i >= 1; i -= (i & (-i))) ans += bit[i];
  return ans;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fac[0] = fac[1] = rfac[0] = rfac[1] = 1;
  for (int i = 2; i <= 2001; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
  rfac[2001] = qpow(fac[2001], MOD - 2);
  for (int i = 2000; i >= 2; i--) rfac[i] = 1ll * rfac[i + 1] * (i + 1) % MOD;
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> b[i], id[i] = i;
  sort(id, id + n, [](int a, int b) { return x[a] < x[b]; });
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++) is[i][j] = is[j][i] = judge(i, j, r);
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) cnt += is[i][j];
    num[i] = 1ll * b[i] * (C(n, m) - C(n - cnt, m) + MOD) % MOD;
  }
  long long ans = 0, zz = 0, qw = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) cnt += is[i][j];
    ds[i] = cnt;
    zz = (zz + 1ll * b[i] * (C(n, m) - C(n - cnt, m) + MOD) % MOD) % MOD;
  }
  for (int i = 0; i < n; i++) {
    int cnt = ds[i];
    vector<int> st;
    for (int j = 0; j < n; j++)
      if (is[i][j]) st.push_back(j);
    sort(st.begin(), st.end(), [](int a, int b) { return x[a] < x[b]; });
    long long qw = 0, l = 0, rr = 0;
    for (int j = 0; j < n; j++) {
      while (rr < st.size() && x[st[rr]] <= x[id[j]] + r)
        update(y[st[rr]], 1), rr++;
      while (l < st.size() && x[st[l]] < x[id[j]] - r)
        update(y[st[l]], -1), l++;
      qw = (qw + 1ll * b[id[j]] *
                     (C(n - cnt, m) -
                      C(n - ds[id[j]] - cnt + sum(min(y[id[j]] + r, 2000)) -
                            sum(max(0, y[id[j]] - r - 1)),
                        m) +
                      MOD) %
                     MOD) %
           MOD;
    }
    ans = (ans + 1ll * b[i] * (zz - qw + MOD)) % MOD;
    for (int j = 0; j <= 2000; j++) bit[j] = 0;
  }
  cout << ans << endl;
  return 0;
}
