#include <bits/stdc++.h>
using namespace std;
bitset<2002> affect[2000 + 1];
pair<int, int> snake[2000 + 1];
int C[2000 + 1][2000 + 1];
int bonus[2000 + 1];
int range[2000 + 1];
int N, M, R;
void Precalc() {
  for (int i = 0; i <= 2000; i++) C[i][0] = 1;
  for (int i = 1; i <= 2000; i++)
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
}
int main() {
  int i, j, coef, both, res = 0;
  scanf("%d %d %d", &N, &M, &R);
  for (i = 1; i <= N; i++)
    scanf("%d %d %d", &snake[i].first, &snake[i].second, &bonus[i]);
  for (i = 1; i <= N; i++)
    for (j = 1; j <= N; j++)
      if (max(abs(snake[i].first - snake[j].first),
              abs(snake[i].second - snake[j].second)) <= R) {
        affect[i][j] = 1;
        ++range[j];
      }
  Precalc();
  for (i = 1; i <= N; i++) {
    coef = (C[N][M] - C[N - range[i]][M] + 1000000007) % 1000000007;
    res = (res + (1LL * bonus[i] * coef) % 1000000007 * bonus[i]) % 1000000007;
  }
  for (i = 1; i <= N; i++)
    for (j = i + 1; j <= N; j++) {
      both = (affect[i] | affect[j]).count();
      coef =
          (C[N][M] - C[N - range[i]][M] - C[N - range[j]][M] + C[N - both][M]) %
          1000000007;
      if (coef < 0) coef += 1000000007;
      res =
          (res + (2LL * bonus[i] * coef) % 1000000007 * bonus[j]) % 1000000007;
    }
  printf("%d\n", res);
  return 0;
}
