#include <bits/stdc++.h>
using namespace std;
bitset<2005> hit[2005] = {0};
long long x[2005] = {0}, y[2005] = {0}, B[2005] = {0};
long long C[2005][2005] = {0};
long long cnt[2005] = {0};
long long n, m, r, ans, temp;
void reset() {}
void input() { cin >> n >> m >> r; }
void solve() {
  ans = 0, temp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= r) {
        hit[i][j] = 1;
        cnt[i]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      long long intersection = (hit[i] & hit[j]).count();
      long long insideI = cnt[i] - intersection;
      long long insideJ = cnt[j] - intersection;
      temp = C[n][m] - C[n - insideI - intersection][m];
      temp -= C[n - insideJ - intersection][m];
      temp += C[n - insideI - insideJ - intersection][m];
      if (temp < 0) temp += 1000000007;
      temp %= 1000000007;
      ans += (((temp * B[i]) % 1000000007) * B[j]) % 1000000007;
      if (ans < 0) ans += 1000000007;
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
}
void LetsRock() {
  for (int i = 0; i <= n; i++) {
    C[i][i] = 1;
    for (int j = 0; j < i; j++) {
      if (j == 0)
        C[i][j] = 1;
      else
        C[i][j] = 0;
      if (j) {
        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> B[i];
  }
  solve();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  input();
  reset();
  LetsRock();
  return 0;
}
