malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a, b[100100], p[100100];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> a;     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= m; i++) cin >> p[i];     sort(b + 1, b + n + 1);     sort(p + 1, p + m + 1);     int le = -1, ri = min(n, m) + 1;     while (le + 1 < ri) {       int mi = (le + ri) / 2;       long long cnt = 0;       for (int i = 1; i <= mi; i++) {         cnt += max(0LL, p[mi + 1 - i] - b[n + 1 - i]);       }       if (cnt > a) {         ri = mi;       } else {         le = mi;       }     }     long long tot = 0;     for (int i = 1; i <= le; i++) tot += p[i];     cout << le <<     << max(tot - a, 0LL) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100000], outpalsz, inn, b[100000];   long long result;   int inicount[100001], iniodd;   int ccount[100001], codd;   int main() {     cin.sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1 - i && a[i] == a[n - 1 - i]; i++) outpalsz++;     for (int i = outpalsz; i < n - outpalsz; i++) {       inicount[a[i]]++;       if (inicount[a[i]] % 2)         iniodd++;       else         iniodd--;       b[inn++] = a[i];     }     if (inn <= 1) {       cout << 1LL * n * (n + 1) / 2 <<   n ;       return 0;     }     if (iniodd <= 1) result = 1LL * (outpalsz + 1) * (outpalsz + 1);     for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i];     codd = iniodd;     for (int i = 0; i < inn; i++) {       ccount[b[i]] -= 2;       if (i * 2 + 1 == inn) ccount[b[i]]++;       if (i > inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2;       if (ccount[b[i]] < 0) break;       if (codd <= 1) result += outpalsz + 1;     }     for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i];     codd = iniodd;     for (int i = inn - 1; i >= 0; i--) {       ccount[b[i]] -= 2;       if (i * 2 + 1 == inn) ccount[b[i]]++;       if (i < inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2;       if (ccount[b[i]] < 0) break;       if (codd <= 1) result += outpalsz + 1;     }     cout << result <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long get(string a) {     long long len = a.length();     long long b = 0;     long long cnt = 1;     for (int i = len - 1; i >= 0; i--) {       b += ((a[i] -  0 ) % 2) * cnt;       cnt *= 2;     }     return b;   }   int p[262150];   int main() {     int t;     cin >> t;     while (t--) {       char c;       cin >> c;       string a;       cin >> a;       long long b = get(a);       switch (c) {         case  + : {           p[b]++;           break;         }         case  - : {           p[b]--;           break;         }         case  ? : {           cout << p[b] << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   template <class T>   inline T isqrt(T k) {     T r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   template <class T>   inline T icbrt(T k) {     T r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int maxn = 2000 + 10;   const int maxm = 500000 + 10;   int n, m;   int a[maxm];   int b[maxm];   bitset<maxn << 1> mat[maxn];   void solve() {     cin >> n >> m;     for (int i = (0); i < (m); i++) {       cin >> a[i] >> b[i], a[i]--, b[i]--;       mat[b[i]][a[i]] = 1;     }     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++) mat[i][j + n] = i == j;     for (int i = (0); i < (n); i++) {       if (!mat[i][i]) {         for (int j = (i + 1); j < (n); j++)           if (mat[j][i]) {             mat[i] ^= mat[j];             break;           }       }       for (int j = (0); j < (n); j++) {         if (j == i) continue;         if (mat[j][i]) {           mat[j] ^= mat[i];         }       }     }     for (int i = (0); i < (m); i++) {       if (!mat[a[i]][b[i] + n]) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int ans(0);     for (int i = 0; i < str.size(); ++i)       if (str[i] != str[str.size() - 1 - i]) ++ans;     if (ans == 2 || (ans == 0 && str.size() % 2 == 1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     srand(1373737);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, t, k, d, q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 0; i < (int)q; i++) {       cin >> t >> k >> d;       int free = 0;       for (int j = 0; j < (int)n; j++) {         if (arr[j] <= t) free++;       }       if (free < k) {         cout << -1 <<   n ;         continue;       }       int res = 0;       for (int j = 0; j < n && k; j++) {         if (arr[j] <= t) {           arr[j] = t + d;           k--;           res += j + 1;         }       }       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long N, K;     cin >> N >> K;     if (K == 1) {       cout << N <<   n ;       return 0;     }     string be, en;     cin >> be >> en;     long long ans = 0, cur = 1;     for (int i = 0; i < N; ++i) {       cur *= 2LL;       if (be[i] ==  b ) --cur;       if (en[i] ==  a ) --cur;       uin(cur, K);       ans += cur;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   struct POINT {     int x, y;     POINT() : x(0), y(0) {}     POINT(int x, int y) : x(x), y(y) {}     POINT operator+(const POINT &t) const { return POINT(x + t.x, y + t.y); }     POINT operator-(const POINT &t) const { return POINT(x - t.x, y - t.y); }     POINT operator!() const { return POINT(-y, x); }   };   inline long long dot(const POINT &a, const POINT &b) {     return (long long)a.x * b.x + (long long)a.y * b.y;   }   inline long long cross(const POINT &a, const POINT &b) {     return (long long)a.x * b.y - (long long)a.y * b.x;   }   inline long long cross(const POINT &a, const POINT &b, const POINT &c) {     return cross(a - c, b - c);   }   inline bool halfPlane(const POINT &p) {     if (p.y == 0) return p.x < 0;     return p.y < 0;   }   inline bool angSortCmp(const POINT &a, const POINT &b) {     bool ha = halfPlane(a);     bool hb = halfPlane(b);     if (ha != hb) return ha < hb;     return cross(a, b) > 0;   }   const int N = 2000;   int n;   long long S;   POINT tab[N + 7];   int poz[N + 7];   POINT stab[N + 7];   struct kierunek {     POINT wek;     int p, q;   };   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> S;     S *= 2;     for (int i = 1; i <= n; ++i) cin >> tab[i].x >> tab[i].y;     sort(tab + 1, tab + n + 1, [](const POINT &a, const POINT &b) -> bool {       if (a.x == b.x) return a.y > b.y;       return a.x < b.x;     });     for (int i = 1; i <= n; ++i) {       poz[i] = i;       stab[i] = tab[i];     }     vector<kierunek> kol((n * (n - 1)) / 2);     int it = 0;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         kol[it].wek = !(tab[j] - tab[i]);         kol[it].p = i;         kol[it].q = j;         it++;       }     }     sort(kol.begin(), kol.end(),          [](const kierunek &a, const kierunek &b) -> bool {            return angSortCmp(a.wek, b.wek);          });     for (kierunek u : kol) {       int p = u.p;       int q = u.q;       swap(stab[poz[p]], stab[poz[q]]);       swap(poz[p], poz[q]);       int l = 1;       int r = n;       while (l <= r) {         int s = (l + r) / 2;         long long ww = cross(tab[q], stab[s], tab[p]);         if (ww == S) {           cout <<  Yes  << endl;           cout << tab[p].x <<     << tab[p].y << endl;           cout << tab[q].x <<     << tab[q].y << endl;           cout << stab[s].x <<     << stab[s].y << endl;           exit(0);         }         if (ww > S)           r = s - 1;         else           l = s + 1;       }       l = 1;       r = n;       while (l <= r) {         int s = (l + r) / 2;         long long ww = cross(tab[q], stab[s], tab[p]);         if (ww == -S) {           cout <<  Yes  << endl;           cout << tab[p].x <<     << tab[p].y << endl;           cout << tab[q].x <<     << tab[q].y << endl;           cout << stab[s].x <<     << stab[s].y << endl;           exit(0);         }         if (ww > -S)           r = s - 1;         else           l = s + 1;       }     }     cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int i, j, n, m, k, l, r;     cin >> n >> m;     int a[n][m];     pair<int, int> start_end[n][m];     for (i = 0; i < n; i += 1)       for (j = 0; j < m; j += 1) {         cin >> a[i][j];         start_end[i][j].first = i;         start_end[i][j].second = i;       }     for (j = 0; j < m; j += 1)       for (i = 1; i < n; i += 1)         if (a[i][j] >= a[i - 1][j])           start_end[i][j].first = start_end[i - 1][j].first;     int min_l[n];     for (i = 0; i < n; i++) min_l[i] = 100010;     for (i = 0; i < n; i += 1)       for (j = 0; j < m; j += 1)         if (start_end[i][j].first < min_l[i]) min_l[i] = start_end[i][j].first;     cin >> k;     while (k--) {       cin >> l >> r;       cout << ((min_l[r - 1] <= l - 1) ?  Yes n  :  No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   long long n, a[100005];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       long long x = 0;       for (long long i = n; i >= 1; i--)         if (a[i] < 0)           x += -a[i];         else if (x >= a[i])           x -= a[i];         else           x = 0;       cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, h;     cin >> n >> m >> h;     vector<int> ms(m), ns(n);     vector<vector<int> > ok(n, vector<int>(m));     for (int i = 0; i < m; i++) {       cin >> ms[i];     }     for (int i = 0; i < n; i++) {       cin >> ns[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ok[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ok[i][j] == 0) {           cout << 0 <<    ;         } else {           cout << min(ms[j], ns[i]) <<    ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int r, g, j, f[200001], sc, kq, mod = round(1e9) + 7;   long long i, h;   int main() {     cin >> r >> g;     f[0] = 1;     for (i = 1; i * (i + 1) / 2 <= r + g; i++) {       for (j = r; j >= 0; j--) {         if (j >= i) f[j] = (f[j] + f[j - i]) % mod;       }     }     h = i - 1;     for (i = 0; i <= r; i++)       if (h * (h + 1) / 2 - i <= g) kq = (kq + f[i]) % mod;     cout << kq;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   vector<pair<int, int> > s;   int co[maxn], deg[maxn];   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       pair<int, int> q;       cin >> q.first >> q.second;       s.push_back(q);     }     for (int i = 1; i <= n; i++) {       cin >> co[i];     }     int x = 0;     for (auto i : s) {       if (co[i.first] != co[i.second]) {         deg[i.first]++;         deg[i.second]++;         x++;       }     }     int flag = 0;     for (int i = 1; i <= n; i++) {       if (deg[i] == x) {         flag = i;       }     }     if (flag) {       printf( YES n%d n , flag);     } else {       printf( NO n );     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k, kol = 0;     cin >> n >> k;     string s;     cin >> s;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       a[i] = s[i] -  0 ;     }     for (long long i = 0; i < n - 1 && k; i++) {       if (a[i] == 4 && a[i + 1] == 7) {         if (i % 2 == 0) {           a[i + 1] = 4;           k--;         } else {           if (i > 0 && a[i - 1] == 4) {             if (k % 2 == 1) {               a[i] = 7;             }             break;           }           a[i] = a[i + 1] = 7;           k--;         }       }     }     for (long long i = 0; i < n; i++) {       cout << a[i];     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n, l;   long long a[300000][3];   long long b[300000][3];   long long t[300000][2];   vector<int> c[3000000];   vector<pair<long long, long long> > g;   long long p[3000000];   long long dab[3000000][2];   void sayno() {     printf( NO );     exit(0);   }   void calc() {     int i, j, k;     long long d = -1;     for (i = 0; i < l; i++) {       if (c[i].size() >= 2) {         d = (t[c[i][1]][1] - t[c[i][0]][1]) /             ((t[c[i][1]][0] - t[c[i][0]][0]) / l);         break;       }     }     if (d == -1) {       int past = 0;       g.clear();       for (i = 1; i <= l; i++) {         if (!c[i % l].size()) continue;         int x = c[past][0], y = c[i % l][0];         if (t[x][0] < t[y][0]) {           long long u = (t[y][0] - t[x][0]) / l;           long long v = t[y][1] - t[x][1];           long long w = (t[y][0] - t[x][0]) % l;           if (u != 0)             g.push_back(pair<long long, long long>((v - w + u - 1) / u, v / u));         } else {           long long u = (t[x][0] - t[y][0]) / l + 1;           long long v = t[x][1] - t[y][1];           long long w = t[y][0] + u * l - t[x][0];           if (u != 0)             g.push_back(pair<long long, long long>((v + u - 1) / u, (v + w) / u));         }         past = i;       }       sort(g.begin(), g.end());       for (auto e : g) {         if (e.second < g.back().first) sayno();       }       d = g.back().first;     }     memset(p, -1, sizeof(p));     for (i = 0; i < n; i++) {       long long u = t[i][1] - d * (t[i][0] / l);       long long v = t[i][0] % l;       if (p[v] == -1)         p[v] = u;       else if (p[v] != u)         sayno();     }     p[l] = d;     int past = 0;     for (i = 1; i <= l; i++) {       if (p[i] == -1) continue;       if (p[i] - p[past] < 0 || p[i] - p[past] > i - past) sayno();       for (j = 0; j < p[i] - p[past]; j++) {         dab[past + j][1] = 1;       }       for (j = p[i] - p[past]; j < i - past; j++) {         dab[past + j][1] = -1;       }       past = i;     }   }   int main() {     int i, j, k;     cin >> n >> l;     for (i = 0; i <= n; i++) {       if (i != 0) scanf( %I64d%I64d%I64d , &a[i][0], &a[i][1], &a[i][2]);       b[i][0] = a[i][0], b[i][1] = a[i][1] + a[i][2], b[i][2] = a[i][1] - a[i][2];       if ((b[i][1] + b[i][0]) % 2 == 1 || (b[i][2] + b[i][0]) % 2 == 1) sayno();       b[i][1] = (b[i][1] + b[i][0]) / 2, b[i][2] = (b[i][2] + b[i][0]) / 2;       c[b[i][0] % l].push_back(i);     }     n++;     for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][1];     calc();     for (i = 0; i < l; i++) dab[i][0] = dab[i][1];     for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][2];     calc();     for (i = 0; i < l; i++) {       if (dab[i][0] == -1 & dab[i][1] == -1)         printf( L );       else if (dab[i][0] == 1 && dab[i][1] == 1)         printf( R );       else if (dab[i][0] == -1 && dab[i][1] == 1)         printf( D );       else         printf( U );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > matmul(vector<vector<long long> > &a,                                     vector<vector<long long> > &b) {     int i, j, k, n = a.size();     vector<vector<long long> > ans(n, vector<long long>(n));     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         long long temp = 0;         for (k = 0; k < n; k++)           temp = (temp + a[i][k] * b[k][j]) % (1000000007LL);         ans[i][j] = temp;       }     return ans;   }   vector<vector<long long> > matpwr(vector<vector<long long> > &a, long long p) {     int n = a.size();     vector<vector<long long> > ans(n, vector<long long>(n));     for (int i = 0; i < n; i++) ans[i][i] = 1;     while (p) {       if (p & 1) ans = matmul(ans, a);       a = matmul(a, a);       p >>= 1;     }     return ans;   }   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long invMod(long long n, long long mod = (1000000007LL)) {     return pwr(n, mod - 2);   }   int n, arr[2000003];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) arr[i] = i;     int start = 1;     for (int iter = 2; iter <= n; iter++) {       int last = arr[start];       for (int j = start + iter; j < start + n; j += iter) {         int temp = last;         last = arr[j];         arr[j] = temp;       }       arr[start + n] = last;       start++;     }     for (int i = start; i < start + n; i++) cout << arr[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[110], b[110], sum = 0;   pair<int, int> dp[110][11000], q = {-1, -1};   pair<int, int> Rec(int i, int W) {     if (i == n) {       if (W >= sum)         return {0, 0};       else         return {1e9, 1e9};     }     if (dp[i][W] != q) return dp[i][W];     pair<int, int> Res1 = {1e9, 1e9}, Res2 = {1e9, 1e9};     Res1 = {0 + Rec(i + 1, W).first, a[i] + Rec(i + 1, W).second};     Res2 = {1 + Rec(i + 1, W + b[i]).first, 0 + Rec(i + 1, W + b[i]).second};     return dp[i][W] = min(Res1, Res2);   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];     for (int i = 0; i < n; i++) cin >> b[i];     cout << Rec(0, 0).first <<     << Rec(0, 0).second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200005];   int n;   int mem[200005][27];   int dirr[200005][27];   bool vis[200005][27];   char other(char c, char d) {     if ( a  != c &&  a  != d) return  a ;     if ( b  != c &&  b  != d) return  b ;     return  c ;   }   int solve(int ind, int lst) {     if (ind >= n) return 0;     if (vis[ind][lst]) return mem[ind][lst];     vis[ind][lst] = 1;     int ans1 = -1, ans2 = -1, ans = -1, dir = -1;     if (s[ind] -  a  != lst) ans1 = solve(ind + 1, s[ind] -  a );     ans2 = 1 + solve(ind + 1, other(s[ind + 1], lst +  a ) -  a );     if (ans1 == -1 || ans2 <= ans1)       dir = 1, ans = ans2;     else       dir = 0, ans = ans1;     dirr[ind][lst] = dir;     return mem[ind][lst] = ans;   }   int main() {     ios::sync_with_stdio(false);     scanf( %s , s);     n = strlen(s);     solve(0, 26);     int lst = 26;     for (int i = 0; i < n; i++)       if (dirr[i][lst] == 0)         lst = s[i] -  a ;       else         s[i] = lst = other(s[i + 1], lst +  a ), lst -=  a ;     puts(s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int N = 3020;   const int D = 1001;   int c[N][N], x[N], y[N], b[N], v[N][N], f[N][N], w[N];   int dis(int i, int j) { return max(abs(x[i] - x[j]), abs(y[i] - y[j])); }   int C(int x, int y) { return x >= y ? c[x][y] : 0; }   int main() {     int n, m, r, i, j, u, d, l, ri, ans = 0, tmp;     scanf( %d%d%d , &n, &m, &r);     c[0][0] = 1;     for (i = 1; i <= 2000; i++) {       c[i][0] = 1;       for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;     }     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &x[i], &y[i], &b[i]);       x[i] += D, y[i] += D;       v[x[i]][y[i]]++;     }     for (i = 1; i <= 3000; i++)       for (j = 1; j <= 3000; j++)         v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];     for (i = 1; i <= n - 1; i++) {       for (j = i + 1; j <= n; j++) {         u = max(y[i], y[j]) - r;         d = min(y[i], y[j]) + r;         l = max(x[i], x[j]) - r;         ri = min(x[i], x[j]) + r;         if (l <= ri && u <= d)           f[i][j] = v[ri][d] - v[l - 1][d] - v[ri][u - 1] + v[l - 1][u - 1];       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         if (dis(i, j) > r) w[i]++;       }       ans = (ans +              (long long)(C(n, m) - C(w[i], m) + mod) * b[i] % mod * b[i] % mod) %             mod;     }     for (i = 1; i <= n - 1; i++)       for (j = i + 1; j <= n; j++) {         tmp = ((C(w[i], m) + C(w[j], m) -                 C(n - (n - w[i] + n - w[j] - f[i][j]), m)) %                    mod +                mod) %               mod;         ans = (ans +                (long long)(C(n, m) - tmp + mod) * b[j] % mod * b[i] * 2 % mod) %               mod;       }     printf( %d n , ans);     return 0;   }