#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int X[2010], Y[2010], B[2010];
long long C[2010][2010], sum[2010][2010];
long long SUM(int l, int r, int x, int y) {
  if (x < l || r > y) return 0;
  l = max(l, 1);
  r = max(r, 1);
  x = min(x, 1000);
  y = min(y, 1000);
  return sum[x][y] - sum[l - 1][y] - sum[x][r - 1] + sum[l - 1][r - 1];
}
int main() {
  int N, M, R;
  cin >> 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 <= 1000; i++)
    for (int j = 1; j <= 1000; j++)
      sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
  C[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    C[i][0] = 1;
    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++) {
      long long U = SUM(X[i] - R, Y[i] - R, X[i] + R, Y[i] + R);
      long long V = SUM(X[j] - R, Y[j] - R, X[j] + R, Y[j] + R);
      long long W = SUM(max(X[i], X[j]) - R, max(Y[i], Y[j]) - R,
                        min(X[i], X[j]) + R, min(Y[i], Y[j]) + R);
      long long tot =
          (C[N][M] - C[N - U][M] - C[N - V][M] + C[N - U - V + W][M] + mod) %
          mod;
      ans = (ans + 1ll * tot * B[i] % mod * B[j] % mod) % mod;
    }
  }
  cout << (ans + mod) % mod << endl;
  return 0;
}
