#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)(1e9) + 7LL;
int n, m, r;
long long x[2005];
long long y[2005];
long long b[2005];
long long s[2005];
long long c[2005][2005];
bitset<2005> f[2005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> m >> r;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> b[i];
  c[0][0] = 1;
  for (int i = 0; i <= 2000; i++)
    for (int j = 0; j <= i; j++) {
      c[i][j] %= mod;
      c[i + 1][j + 1] += c[i][j];
      c[i + 1][j] += c[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      if (max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= r) f[i][j] = f[j][i] = 1;
  for (int i = 1; i <= n; i++) s[i] = f[i].count();
  long long sol = 0LL;
  for (int i = 1; i <= n; i++)
    sol = (sol + b[i] * b[i] % mod * (c[n][m] - c[n - s[i]][m])) % mod;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++) {
      int xx = (f[i] & f[j]).count();
      sol = (sol + 2 * b[i] * b[j] % mod *
                       (c[n][m] - c[n - s[i]][m] - c[n - s[j]][m] +
                        c[n - s[i] - s[j] + xx][m])) %
            mod;
    }
  if (sol < 0) sol += mod;
  cout << sol;
  return 0;
}
