#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long X = 1e7;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
long long n, m, r;
long long x[N], y[N], b[N], f[N], g1[N], g2[N], fact[N], e[N][N], a[N][N];
vector<pair<pair<int, int>, pair<int, int> > > myvec;
long long power(long long a, long long n) {
  long long c = a, ans = 1;
  while (n) {
    if (n % 2) ans = ans * c % mod;
    c = c * c % mod;
    n /= 2;
  }
  return ans;
}
long long inv(long long a) { return power(a, mod - 2); }
long long C(long long k, long long n) {
  if (k > n) return 0;
  return fact[n] * inv(fact[k]) % mod * inv(fact[n - k]) % mod;
}
void get_area(int x, int y, int r, pair<pair<int, int>, pair<int, int> > &p) {
  p.first.first = x - r;
  p.first.second = y - r;
  p.second.first = x + r;
  p.second.second = y + r;
}
int contain(pair<pair<int, int>, pair<int, int> > p, int x, int y) {
  if (x >= p.first.first && x <= p.second.first && y >= p.first.second &&
      y <= p.second.second)
    return 1;
  return 0;
}
long long find(int i, int j) {
  int x2 = min(x[i], x[j]) + r;
  int x1 = max(x[i], x[j]) - r;
  int y2 = min(y[i], y[j]) + r;
  int y1 = max(y[i], y[j]) - r;
  if (x1 > x2 || y1 > y2) return 0;
  x1 = max(1, x1);
  x2 = min(2000, x2);
  y1 = max(1, y1);
  y2 = min(2000, y2);
  return e[x2][y2] - e[x1 - 1][y2] - e[x2][y1 - 1] + e[x1 - 1][y1 - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  fact[0] = 1;
  for (long long i = 1; i <= 2000; i++) fact[i] = fact[i - 1] * i % mod;
  cin >> n >> m >> r;
  for (long long i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> b[i];
    pair<pair<int, int>, pair<int, int> > p;
    get_area(x[i], y[i], r, p);
    myvec.push_back(p);
    a[x[i]][y[i]] = 1;
  }
  for (long long i = 1; i <= 2000; i++)
    for (long long j = 1; j <= 2000; j++)
      e[i][j] = e[i - 1][j] + e[i][j - 1] - e[i - 1][j - 1] + a[i][j];
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long c = n;
    for (auto p : myvec) c -= contain(p, x[i], y[i]);
    f[i] = c;
    long long w = C(m, n) - C(m, c) + mod;
    w %= mod;
    g1[i] = C(m, c);
    g2[i] = w;
    ans += w * b[i] % mod * b[i] % mod;
    ans %= mod;
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = i + 1; j <= n; j++) {
      long long k = find(i, j);
      long long c = f[i] + f[j] - n + k;
      long long w = g2[i] + g2[j] - g1[i] - g1[j] + 2 * C(m, c) + mod + mod;
      w %= mod;
      ans += b[i] * b[j] % mod * w % mod;
      ans %= mod;
    }
  cout << ans;
}
