#include <bits/stdc++.h>
using namespace std;
long long c[2005][2005];
struct node {
  long long x, y, v;
};
node a[2005];
bitset<2005> ed[2005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % (long long)1000000007;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].v;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      long long mx = max(abs(a[i].x - a[j].x), abs(a[i].y - a[j].y));
      if (mx <= r) {
        ed[i][j] = 1;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long nm1 = ed[i].count();
    long long nm11 = (c[n][m] - c[n - nm1][m] + (long long)1000000007) %
                     (long long)1000000007;
    long long w = (a[i].v * a[i].v % (long long)1000000007 * nm11 %
                   (long long)1000000007) %
                  (long long)1000000007;
    ans = (ans + w) % (long long)1000000007;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      long long nm1 = ed[i].count();
      long long nm11 = (c[n][m] - c[n - nm1][m] + (long long)1000000007) %
                       (long long)1000000007;
      long long nm2 = ed[j].count();
      long long nm22 = (c[n][m] - c[n - nm2][m] + (long long)1000000007) %
                       (long long)1000000007;
      bitset<2005> tp = ed[i] | ed[j];
      long long nm3 = tp.count();
      long long nm = ((((nm11 + nm22) % (long long)1000000007 - c[n][m] +
                        (long long)1000000007) %
                           (long long)1000000007 +
                       c[n - nm3][m]) %
                          (long long)1000000007 +
                      (long long)1000000007) %
                     (long long)1000000007;
      long long w = nm * a[i].v % (long long)1000000007 * a[j].v %
                    (long long)1000000007 * 2 % (long long)1000000007;
      ans = (ans + w) % (long long)1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
