#include <bits/stdc++.h>
using namespace std;
long long int fact[2005];
long long int fact_inv[2005];
long long int power(long long int x, long long int y, long long int m) {
  if (y == 0) return 1;
  long long int a = power(x, y / 2, m);
  if (y % 2) {
    return (a * ((a * x) % m)) % m;
  } else {
    return (a * a) % m;
  }
}
long long int mod_inverse(long long int x, long long int m) {
  return power(x, m - 2, m);
}
long long int ncr(long long int n, long long int r, long long int m) {
  if (r > n || r < 0) return 0ll;
  long long int res = (fact[n] * fact_inv[r]) % (long long int)1000000007;
  res = (res * fact_inv[n - r]) % (long long int)1000000007;
  return res;
}
int ispal(string s) {
  int len = s.size();
  int flag = 1;
  for (int i = 0; i < len; ++i) {
    if (s[i] != s[len - i - 1]) {
      flag = 0;
      break;
    }
  }
  return flag;
}
long long int sroot(long long int n, long long int low = 1,
                    long long int high = 1e9 + 1) {
  if (low == high) return low;
  if (low == high - 1) {
    if (high * high <= n)
      return high;
    else
      return low;
  }
  long long int mid = (low + high) / 2;
  long long int a = mid * mid;
  if (a > n)
    return sroot(n, low, mid - 1);
  else
    return sroot(n, mid, high);
}
long long int croot(long long int n, long long int low = 1,
                    long long int high = 1e6 + 1) {
  if (low == high) return low;
  if (low == high - 1) {
    if (high * high * high <= n)
      return high;
    else
      return low;
  }
  long long int mid = (low + high) / 2;
  long long int a = mid * mid * mid;
  if (a > n)
    return croot(n, low, mid - 1);
  else
    return croot(n, mid, high);
}
pair<int, int> operator+(pair<int, int> p1, pair<int, int> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
long long int g[2005][2005];
class solver {
 public:
  long long int n, m, r;
  vector<long long int> x, y, b;
  long long int find(long long int x1, long long int x2, long long int y1,
                     long long int y2) {
    if (x1 > x2) return 0ll;
    if (y1 > y2) return 0ll;
    x1 = max(1ll, x1);
    x2 = min(2000ll, x2);
    y1 = max(1ll, y1);
    y2 = min(2000ll, y2);
    long long int res =
        (g[x2][y2] - g[x1 - 1][y2] - g[x2][y1 - 1] + g[x1 - 1][y1 - 1]);
    return res;
  }
  void solve() {
    memset(g, 0, sizeof(g));
    cin >> n >> m >> r;
    x.resize(n + 1);
    y.resize(n + 1);
    b.resize(n + 1);
    for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> b[i];
    for (int i = 1; i <= n; ++i) {
      g[x[i]][y[i]] = 1ll;
    }
    for (int i = 1; i <= 2000; ++i)
      for (int j = 1; j <= 2000; ++j) {
        g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
      }
    long long int ans[n + 1][n + 1];
    memset(ans, 0, sizeof(ans));
    long long int final_ans = 0;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) {
        ans[i][j] = find(max(x[i] - r, x[j] - r), min(x[i] + r, x[j] + r),
                         max(y[i] - r, y[j] - r), min(y[i] + r, y[j] + r));
      }
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) {
        long long int cnt = ncr(n, m, (long long int)1000000007) -
                            ncr(n - ans[i][i], m, (long long int)1000000007) -
                            ncr(n - ans[j][j], m, (long long int)1000000007) +
                            ncr(n - (ans[i][i] + ans[j][j] - ans[i][j]), m,
                                (long long int)1000000007);
        cnt = (cnt + 10ll * (long long int)1000000007) %
              (long long int)1000000007;
        final_ans =
            (final_ans + ((cnt * ((b[i] * b[j]) % (long long int)1000000007)) %
                          (long long int)1000000007)) %
            (long long int)1000000007;
      }
    cout << final_ans << '\n';
  }
};
int main() {
  fact[0] = 1;
  fact_inv[0] = mod_inverse(1, (long long int)1000000007);
  for (long long int i = 1; i <= 2001; ++i) {
    fact[i] = (fact[i - 1] * i) % (long long int)1000000007;
    fact_inv[i] = mod_inverse(fact[i], (long long int)1000000007);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  while (test--) {
    solver o;
    o.solve();
  }
}
