#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long cache[2005][2005];
int n, m, r;
pair<pair<int, int>, int> arr[2005];
int dist(int i, int j) {
  return max(abs(arr[i].first.first - arr[j].first.first),
             abs(arr[i].first.second - arr[j].first.second));
}
long long ncr(int a, int b) {
  if (a < 0 || b < 0) return 0;
  return cache[a][b];
}
int sum[1005][1005];
int calc(int le, int ri) {
  int max_x = min(arr[le].first.first + r, arr[ri].first.first + r);
  int max_y = min(arr[le].first.second + r, arr[ri].first.second + r);
  int min_x = max(arr[le].first.first - r, arr[ri].first.first - r);
  int min_y = max(arr[le].first.second - r, arr[ri].first.second - r);
  max_x = min(1000, max_x);
  max_y = min(1000, max_y);
  min_x = max(1, min_x);
  min_y = max(1, min_y);
  if (min_x > max_x || min_y > max_y) return 0;
  return sum[max_x][max_y] - sum[max_x][min_y - 1] - sum[min_x - 1][max_y] +
         sum[min_x - 1][min_y - 1];
}
int main() {
  for (int i = 0; i <= 2000; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i)
        cache[i][j] = 1;
      else
        cache[i][j] = (cache[i - 1][j - 1] + cache[i - 1][j]) % mod;
    }
  }
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < n; i++) {
    int x, y, b;
    scanf("%d%d%d", &x, &y, &b);
    arr[i] = {{x, y}, b};
    sum[x][y]++;
  }
  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 1000; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j <= 1000; j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      long long cur = arr[i].second;
      cur = (cur * arr[j].second) % mod;
      int cnt = 0;
      int k = calc(i, j);
      int ak = calc(i, i);
      int bk = calc(j, j);
      int a = ak - k;
      int b = bk - k;
      cnt = (ncr(n, m) - ncr(n - k, m) + mod) % mod;
      long long le = (ncr(n - k, m) - ncr(n - a - k, m) + mod) % mod;
      long long ri = (ncr(n - b - k, m) - ncr(n - b - a - k, m) + mod) % mod;
      long long temp = (le - ri + mod) % mod;
      cnt = (cnt + temp) % mod;
      cur = (cur * cnt) % mod;
      ans = (ans + cur) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
