#include <bits/stdc++.h>
using namespace std;
int dX1[4] = {0, 0, -1, 1};
int dY1[4] = {-1, 1, 0, 0};
int dX2[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dY2[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int MOD = 1000000007;
const int mxn = 3000;
const int gsz = 1001;
int N, M, R;
int x[mxn], y[mxn], d[mxn], g[gsz][gsz];
long long fact[mxn], inv[mxn];
long long exp(long long x, long long n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return x;
  }
  long long ret = exp(x, n >> 1) % MOD;
  if (n & 1) {
    return ret * ret % MOD * x % MOD;
  }
  return ret * ret % MOD;
}
long long ncr(int n, int r) {
  if (n < r) {
    return 0;
  }
  return fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}
int query(int x, int y) {
  int top_x = min(gsz - 1, x + R);
  int top_y = min(gsz - 1, y + R);
  int bot_x = max(0, x - R - 1);
  int bot_y = max(0, y - R - 1);
  return g[top_x][top_y] - g[top_x][bot_y] - g[bot_x][top_y] + g[bot_x][bot_y];
}
int overlap(int x1, int y1, int x2, int y2) {
  int top_x1 = min(gsz - 1, x1 + R);
  int top_y1 = min(gsz - 1, y1 + R);
  int bot_x1 = max(0, x1 - R - 1);
  int bot_y1 = max(0, y1 - R - 1);
  int top_x2 = min(gsz - 1, x2 + R);
  int top_y2 = min(gsz - 1, y2 + R);
  int bot_x2 = max(0, x2 - R - 1);
  int bot_y2 = max(0, y2 - R - 1);
  if (top_x2 <= bot_x1 || top_y2 <= bot_y1 || top_x1 <= bot_x2 ||
      top_y1 <= bot_y2)
    return 0;
  int top_x3 = min(top_x1, top_x2);
  int top_y3 = min(top_y1, top_y2);
  int bot_x3 = max(bot_x1, bot_x2);
  int bot_y3 = max(bot_y1, bot_y2);
  return g[top_x3][top_y3] - g[top_x3][bot_y3] - g[bot_x3][top_y3] +
         g[bot_x3][bot_y3];
}
int main() {
  cin >> N >> M >> R;
  for (int i = 0; i < gsz; i++) {
    for (int j = 0; j < gsz; j++) {
      g[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> d[i];
    g[x[i]][y[i]]++;
  }
  for (int i = 1; i < gsz; i++) {
    for (int j = 1; j < gsz; j++) {
      g[i][j] = g[i][j] + g[i][j - 1] + g[i - 1][j] - g[i - 1][j - 1];
    }
  }
  fact[0] = fact[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = inv[i - 1] * exp(i, MOD - 2) % MOD;
  }
  long long ans = 0;
  long long total = ncr(N, M);
  for (int i = 0; i < N; i++) {
    int cnt = query(x[i], y[i]);
    int way = (MOD + total - ncr(N - cnt, M)) % MOD;
    assert(way >= 0);
    ans = (ans + 1LL * way * d[i] % MOD * d[i] % MOD) % MOD;
  }
  for (int i = 0; i < N; i++) {
    int cnt1 = query(x[i], y[i]);
    for (int j = i + 1; j < N; j++) {
      int cnt2 = query(x[j], y[j]);
      int over = overlap(x[i], y[i], x[j], y[j]);
      assert(cnt1 >= over && cnt2 >= over);
      int way1 = ncr(N - cnt1, M);
      int way2 = ncr(N - cnt2, M);
      int way3 = ncr(N - cnt1 - cnt2 + over, M);
      int both = (total + MOD + MOD - way1 - way2 + way3) % MOD;
      assert(both >= 0);
      ans = (ans + 2LL * both * d[i] % MOD * d[j] % MOD) % MOD;
    }
  }
  cout << ans << '\n';
}
