#include <bits/stdc++.h>
using namespace std;
const int L = 1000;
int n, m, r, a[1010][1010], s[1010][1010], x[2010], y[2010];
long long b[2010];
int gt(int x1, int y1, int x2, int y2) {
  if (x1 < 1) x1 = 1;
  if (y1 < 1) y1 = 1;
  if (x2 < 1) x2 = 1;
  if (y2 < 1) y2 = 1;
  if (x1 > L) x1 = L;
  if (y1 > L) y1 = L;
  if (x2 > L) x2 = L;
  if (y2 > L) y2 = L;
  if (x1 > x2 || y1 > y2) return 0;
  return max(0, s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]);
}
long long C[2020][2020];
int main() {
  int i, j;
  cin >> n >> m >> r;
  long long ans = 0;
  C[0][0] = 1;
  for (i = 1; i <= 2000; i++) {
    C[i][0] = 1;
    for (j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  }
  for (i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    cin >> b[i];
    a[x[i]][y[i]] = 1;
  }
  for (i = 1; i <= L; i++)
    for (j = 1; j <= L; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      int ni = gt(x[i] - r, y[i] - r, x[i] + r, y[i] + r),
          nj = gt(x[j] - r, y[j] - r, x[j] + r, y[j] + r);
      int nij = ni + nj -
                gt(max(x[i] - r, x[j] - r), max(y[i] - r, y[j] - r),
                   min(x[i] + r, x[j] + r), min(y[i] + r, y[j] + r));
      long long tp = C[n][m] - (C[n - ni][m] + C[n - nj][m] - C[n - nij][m]) +
                     1000000007 + 1000000007 + 1000000007;
      tp %= 1000000007;
      tp *= b[i];
      tp %= 1000000007;
      tp *= b[j];
      tp %= 1000000007;
      ans += tp;
      ans %= 1000000007;
    }
  cout << ans;
}
