#include <bits/stdc++.h>
using namespace std;
int b[2005], x[2005], y[2005];
int a[1000 + 5][1000 + 5];
long long F[2005];
long long Pow(int a, int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long t = Pow(a, b / 2);
  t = (t * t) % 1000000007;
  if (b % 2 == 1) t = (t * a) % 1000000007;
  return t;
}
long long nCk(int n, int k) {
  if (k > n) return 0;
  return F[n] * Pow(F[k] * F[n - k] % 1000000007, 1000000007 - 2) % 1000000007;
}
int getSum(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  return a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  F[0] = 1;
  for (int i = 1; i <= n; i++) F[i] = (F[i - 1] * i) % 1000000007;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> b[i];
    a[x[i]][y[i]]++;
  }
  for (int i = 1; i <= 1000; i++)
    for (int j = 1; j <= 1000; j++)
      a[i][j] = a[i - 1][j] + a[i][j - 1] + a[i][j] - a[i - 1][j - 1];
  long long nCm = nCk(n, m);
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      long long num = 0;
      int xMin = max(1, max(x[i], x[j]) - r),
          yMin = max(1, max(y[i], y[j]) - r);
      int xMax = min(1000, min(x[i], x[j]) + r),
          yMax = min(1000, min(y[i], y[j]) + r);
      int w = getSum(xMin, yMin, xMax, yMax);
      num += (nCm - nCk(n - w, m) + 1000000007) % 1000000007;
      num %= 1000000007;
      int u = getSum(max(1, x[i] - r), max(1, y[i] - r), min(1000, x[i] + r),
                     min(1000, y[i] + r)) -
              w;
      int v = getSum(max(1, x[j] - r), max(1, y[j] - r), min(1000, x[j] + r),
                     min(1000, y[j] + r)) -
              w;
      num += (nCk(n - w, m) - nCk(n - w - u, m) - nCk(n - w - v, m) +
              nCk(n - w - u - v, m) + 2LL * 1000000007) %
             1000000007;
      if (i == j)
        res += num * b[i] % 1000000007 * b[j] % 1000000007;
      else
        res += num * 2 % 1000000007 * b[i] % 1000000007 * b[j] % 1000000007;
      res %= 1000000007;
    }
  }
  cout << res;
}
