func_code_string: #include <bits/stdc++.h>   using namespace std;   int xs[2123], ys[2123], bs[2123];   long long fat[2123], prefix[2123][2123];   long long fatinv[2123];   long long sum(int row1, int row2, int col1, int col2) {     if (row1 > row2 || col1 > col2) return 0ll;     row2 = min(row2, 2000);     col2 = min(col2, 2000);     --row1, --col1;     if (row1 < 0) row1 = 0;     if (col1 < 0) col1 = 0;     if (row2 <= row1 or col2 <= col1) return 0ll;     return prefix[row2][col2] - prefix[row2][col1] - prefix[row1][col2] +            prefix[row1][col1];   }   long long sumR(int i, int r) {     return sum(xs[i] - r, xs[i] + r, ys[i] - r, ys[i] + r);   }   long long fastexp(long long a, long long b, long long m) {     long long r = 1;     for (a %= m; b; b >>= 1, a = (a * a) % m)       if (b & 1) r = (r * a) % m;     return r;   }   long long comb(int n, int k) {     if (n < k) return 0ll;     return (((fat[n] * fatinv[k]) % 1000000007) * fatinv[n - k]) % 1000000007;   }   int main() {     fat[0] = 1;     for (int i = 1; i < 2123; ++i) fat[i] = (fat[i - 1] * i) % 1000000007;     int n, m, r;     cin >> n >> m >> r;     for (int i = 0; i < 2123; ++i)       fatinv[i] = fastexp(fat[i], 1000000007 - 2, 1000000007);     for (int i = 0; i < n; ++i) {       cin >> xs[i] >> ys[i] >> bs[i];       prefix[xs[i]][ys[i]] = 1;     }     for (int i = 1; i < 2123; ++i) {       for (int j = 1; j < 2123; ++j) {         prefix[i][j] +=             prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1];       }     }     long long resp = 0ll;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         int row1 = xs[i] - r;         int row2 = xs[i] + r;         int col1 = ys[i] - r;         int col2 = ys[i] + r;         row1 = max(row1, xs[j] - r);         row2 = min(row2, xs[j] + r);         col1 = max(col1, ys[j] - r);         col2 = min(col2, ys[j] + r);         long long s = sum(row1, row2, col1, col2);         long long si = sumR(i, r);         long long sj = sumR(j, r);         long long diff = si + sj - s;         long long count = (((comb(n, m) - comb(n - si, m) - comb(n - sj, m) +                              comb(n - diff, m)) %                             1000000007) *                            bs[i]) %                           1000000007;         resp = (resp + (count * bs[j]) % 1000000007) % 1000000007;       }     }     if (resp < 0) resp += 1000000007;     cout << resp <<   n ;     return 0;   }   