#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC target("sse4")
using namespace std;
const long long oo = (long long)(1e9);
long long pascal[(long long)(2e3 + 5)][(long long)(2e3 + 5)];
long long vb[(long long)(2e3 + 5)][40];
long long v[(long long)(2e3 + 5)];
long long xy[(long long)(2e3 + 5)][2];
long long cant[(long long)(2e3 + 5)];
long long comb(int n, int m) {
  if (n < 0) return 0;
  return pascal[n][m + 1];
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  pascal[0][1] = 1;
  for (int i = 1; i < (long long)(2e3 + 5) - 1; i++)
    for (int j = 1; j <= i + 1; j++)
      pascal[i][j] =
          (pascal[i - 1][j] + pascal[i - 1][j - 1]) % (long long)(1e9 + 7);
  long long n, m, r;
  cin >> n >> m >> r;
  long long res = 0;
  for (int i = 0; i < n; i++) cin >> xy[i][0] >> xy[i][1] >> v[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      bool kk = max(abs(xy[i][0] - xy[j][0]), abs(xy[i][1] - xy[j][1])) <= r;
      if (kk) vb[i][j / 60] |= (1ll << (j % 60));
    }
    long long vv = 0;
    for (int j = 0; j < 40; j++) vv += __builtin_popcountll(vb[i][j]);
    cant[i] = vv;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      vector<long long> v1(40);
      for (int k = 0; k < 40; k++) v1[k] = vb[i][k] & vb[j][k];
      long long c2 = 0;
      for (auto y : v1) c2 += __builtin_popcountll(y);
      long long f1 = (comb(n, m) - comb(n - c2, m) + (long long)(1e9 + 7)) %
                     (long long)(1e9 + 7);
      res = (res + f1 * ((v[i] * v[j]) % (long long)(1e9 + 7))) %
            (long long)(1e9 + 7);
      long long p1 = cant[i] - c2;
      long long p2 = cant[j] - c2;
      long long f2 =
          (comb(n - c2, m) - comb(n - c2 - p1, m) + (long long)(1e9 + 7)) %
          (long long)(1e9 + 7);
      f2 = (f2 - comb(n - c2 - p2, m) + (long long)(1e9 + 7)) %
           (long long)(1e9 + 7);
      f2 = (f2 + comb(n - c2 - p1 - p2, m)) % (long long)(1e9 + 7);
      res = (res + f2 * ((v[i] * v[j]) % (long long)(1e9 + 7))) %
            (long long)(1e9 + 7);
    }
  }
  cout << (res) << '\n';
  return 0;
}
