malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   int up(int n) {     int r = 1;     while (r < n) r <<= 1;     return r;   }   class segtree {     vector<int> arr;     vector<bool> laz;     void inv(int l, int r, int cl, int cr, int v) {       if (r <= cl || cr <= l) return;       push(v);       if (l <= cl && cr <= r) {         laz[v] = !laz[v];         return;       }       int ct = (cl + cr) / 2;       inv(l, r, cl, ct, 2 * v);       inv(l, r, ct, cr, 2 * v + 1);       upd(v);     }     int cnt(int l, int r, int cl, int cr, int v) {       if (r <= cl || cr <= l) return 0;       push(v);       if (l <= cl && cr <= r) return arr[v];       int ct = (cl + cr) / 2;       ct = cnt(l, r, cl, ct, 2 * v) + cnt(l, r, ct, cr, 2 * v + 1);       upd(v);       return ct;     }     void push(int v) {       if (laz[v]) {         laz[v] = false;         arr[v] = arr.size() / up(v + 1) - arr[v];         if (v < (int)arr.size() / 2) {           laz[2 * v] = !laz[2 * v];           laz[2 * v + 1] = !laz[2 * v + 1];         }       }     }     void upd(int v) {       if (v < (int)arr.size() / 2) {         push(2 * v);         push(2 * v + 1);         arr[v] = arr[2 * v] + arr[2 * v + 1];       }     }       public:     segtree(int n) : arr(2 * up(n)), laz(2 * up(n)) {}     void inv(int l, int r) { inv(l, r, 0, arr.size() / 2, 1); }     int cnt(int l, int r) { return cnt(l, r, 0, arr.size() / 2, 1); }   };   void dfs(const vector<vector<int>> &gr, int v, vector<int> &in,            vector<int> &out, int &cnt) {     in[v] = cnt++;     for (auto it : gr[v]) dfs(gr, it, in, out, cnt);     out[v] = ++cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<vector<int>> gr(n);     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       gr[p].push_back(i);     }     vector<int> in(n), out(n);     n = 0;     dfs(gr, 0, in, out, n);     segtree st(n);     n /= 2;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         st.inv(in[i], in[i] + 1);         st.inv(out[i] - 1, out[i]);       }     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       string s;       int t;       cin >> s >> t;       t--;       if (s ==  get ) {         cout << st.cnt(in[t], out[t]) / 2 << endl;       } else {         assert(s ==  pow );         st.inv(in[t], out[t]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int p1 = 0, q1 = 0, r1 = 0, s1 = 0;     int ans = 1;     int a = 0, b = 0, c = 0, d = 0;     vector<int> v;     int sum = 0;     for (int j = 0; j < s.length(); j++) {       if (s[j] ==  R ) {         if ((q1 > 0)) {           ans++;           v.push_back(j);           q1 = 0;           r1 = 0;           s1 = 0;         }         p1++;       }       if (s[j] ==  L ) {         if ((p1 > 0)) {           ans++;           v.push_back(j);           p1 = 0;           r1 = 0;           s1 = 0;         }         q1++;       }       if (s[j] ==  U ) {         if (s1 > 0) {           ans++;           v.push_back(j);           q1 = 0;           p1 = 0;           s1 = 0;         }         r1++;       }       if (s[j] ==  D ) {         if ((r1 > 0)) {           ans++;           v.push_back(j);           q1 = 0;           r1 = 0;           p1 = 0;         }         s1++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n], sum = 0, fg = 0, cnt = 0, ind = 1, ans = 0;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         if (a[i] <= ind) {           ind++;           continue;         }         ans = ans + a[i] - ind;         ind = a[i] + 1;       }       cout << ans;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long s1[2100][2100], sum[2100][2100], cnt[2100][2100], cnt1[2100][2100];   int main() {     int n, m, i, j;     long long res;     scanf( %d%d , &n, &m);     for (i = 2; i <= m; i++) {       for (j = 1; j <= n; j++) {         cnt[i][j] = sum[i][j - 1] + 1;         cnt[i][j] %= 1000000007;         s1[i][j] = s1[i - 1][j] + cnt[i][j];         s1[i][j] %= 1000000007;         sum[i][j] = sum[i - 1][j] + s1[i][j];         sum[i][j] %= 1000000007;         cnt1[i][j] = cnt[i][j] - cnt[i][j - 1];         if (cnt1[i][j] < 0) cnt1[i][j] += 1000000007;       }     }     res = 0;     for (i = 2; i <= m; i++)       for (j = 1; j <= n; j++) {         res += ((cnt[i][j] * cnt1[i][n - j + 1]) % 1000000007) * (m - i + 1);         res %= 1000000007;       }     printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s =  *  + s;     int add = 0;     int n = (s.length()) - 1;     for (int i = 1; i + i <= n; i++) {       if (s[i] != s[s.size() - i]) {         add++;       }     }     if (add <= 1 && (n & 1) || add == 1)       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, i, j, arr[300] = {0}, p = 0, k = 0, c, d;     cin >> n >> a;     for (i = 1; i < n + 1; i++) {       cin >> arr[i];     }     arr[0] = 1, arr[n + 1] = 1;     j = min(a, n - a + 1);     for (i = j; i < n + 1; i++) {       c = a + k;       d = a - k;       if (d < 1) d = 0;       if (c > n) c = n + 1;       if (arr[d] == arr[c] and arr[c]) {         if (c != d and c <= n and d > 0)           p += 2;         else           p++;       }       k++;     }     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } arr[104];   vector<int> graph[105];   int visited[105] = {0};   void dfs(int i) {     visited[i] = 1;     int j = 0;     while (j < graph[i].size()) {       if (visited[graph[i][j]] == 0) {         dfs(graph[i][j]);       }       j++;     }   }   int main() {     int n;     scanf( %d , &n);     int x, y;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       arr[i].x = x;       arr[i].y = y;     }     int hash[102] = {0};     int ct = 0;     for (int i = 0; i < n; i++) {       int flag = 0;       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (arr[j].x == arr[i].x || arr[j].y == arr[i].y) {           graph[i].push_back(j);           graph[j].push_back(i);           flag = 1;         }       }       if (flag == 0) visited[i] = 1;     }     for (int i = 0; i < n; i++) {       if (visited[i] == 0) {         dfs(i);         ct++;       }     }     int c = 0;     for (int i = 0; i < n; i++) {       if (!graph[i].size()) c++;     }     printf( %d n , c - 1 + ct);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXT = (1 << 18) + 5;   int icT[MAXT], dcT[MAXT];   const int MAXN = 100010;   int a[MAXN], idxofa[MAXN], b[MAXN];   int n;   priority_queue<pair<int, int> > dc, ic;   int main() {     scanf( %d , &n);     for (int i = 1; i <= (int)(n); i++) {       scanf( %d , &a[i]);       idxofa[a[i]] = i;     }     for (int i = 0; i < (int)(MAXT); i++) icT[i] = dcT[i] = 1000000000;     int NN = (1 << 17) - 1;     for (int i = 1; i <= (int)(n); i++) {       scanf( %d , &b[i]);       if (i > idxofa[b[i]]) {         dc.push(make_pair(-(i - idxofa[b[i]]), b[i]));         dcT[NN + b[i]] = abs(i - idxofa[b[i]]);         for (int node = (NN + b[i]) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       } else {         ic.push(make_pair(-(i - 1), b[i]));         icT[NN + b[i]] = abs(i - idxofa[b[i]]);         for (int node = (NN + b[i]) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);       }     }     for (int t = 0; t < n; t++) {       int dcres = dcT[1] - t;       int icres = icT[1] + t;       printf( %d n , min(dcres, icres));       while (dc.size() > 0 && -dc.top().first == t) {         pair<int, int> qt = dc.top();         dc.pop();         ic.push(make_pair(-t - (idxofa[qt.second] - 1), qt.second));         dcT[NN + qt.second] = 1000000000;         icT[NN + qt.second] = -t;         for (int node = (NN + qt.second) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);         for (int node = (NN + qt.second) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       }       while (ic.size() > 0 && -ic.top().first == t) {         pair<int, int> qt = ic.top();         ic.pop();         dc.push(make_pair(-t - (n - idxofa[qt.second]) - 1, qt.second));         icT[NN + qt.second] = 1000000000;         dcT[NN + qt.second] = t + 1 + n - idxofa[qt.second];         for (int node = (NN + qt.second) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);         for (int node = (NN + qt.second) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, k, b, c;   int a[N], A[N], cost[N];   long long ans = inf;   void solve(int x) {     for (int i = 1; i <= n; ++i) {       A[i] = a[i];       cost[i] = 0;       while (A[i] % 5 != x) ++A[i], cost[i] += c;     }     priority_queue<long long> heap;     long long res = 0;     for (int i = 1; i <= k; ++i) {       long long val = 5 * cost[i] - 1LL * b * A[i];       res += val;       heap.push(val);     }     ans = min(ans, (res + 1LL * k * b * A[k]) / 5);     for (int i = k + 1; i <= n; ++i) {       long long val = 5 * cost[i] - 1LL * b * A[i];       if (val < heap.top()) {         res -= heap.top();         heap.pop();         heap.push(val);         res += val;       }       ans = min(ans, (res + 1LL * k * b * A[i]) / 5);     }   }   int main() {     cin >> n >> k >> b >> c;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       a[i] += 1e9;     }     sort(a + 1, a + n + 1);     b = min(b, c * 5);     for (int i = 0; i < 5; ++i) solve(i);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 5;   const int OO = 1e9 + 7;   using namespace std;   long long n, m, dishes[N], cost[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                  greater<pair<long long, long long>>>       q;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> dishes[i];     for (int i = 0; i < n; i++) cin >> cost[i], q.push({cost[i], i});     for (int i = 0; i < m; i++) {       long long kind, numofdishes, COST = 0;       cin >> kind >> numofdishes;       kind--;       if (numofdishes <= dishes[kind]) {         COST += (numofdishes * cost[kind]);         dishes[kind] -= numofdishes;         cout << COST <<   n ;       } else {         COST += (dishes[kind] * cost[kind]);         numofdishes -= dishes[kind];         dishes[kind] = 0;         while (!q.empty() && numofdishes > 0) {           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }           if (numofdishes <= dishes[q.top().second]) {             COST += (numofdishes * q.top().first);             dishes[q.top().second] -= numofdishes;             numofdishes = 0;           } else {             COST += (dishes[q.top().second] * q.top().first);             numofdishes -= dishes[q.top().second];             dishes[q.top().second] = 0;           }           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }         }         if (numofdishes > 0)           cout << 0 <<   n ;         else           cout << COST <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void myswap(int& a, int& b) {     int temp;     temp = a;     a = b;     b = temp;   }   void fun(vector<int>& vec, int k, int l, int r) {     if (k <= 1 || l >= r - 1) {       return;     }     int mid = (l + r) / 2;     if (k == 3) {       myswap(vec[mid - 1], vec[mid]);       return;     }     k--;     int p = k / 2;     if (p % 2 == 1) {       fun(vec, p, l, mid);       fun(vec, p, mid, r);     } else if (mid - l >= r - mid) {       fun(vec, p + 1, l, mid);       fun(vec, p - 1, mid, r);     } else {       fun(vec, p - 1, l, mid);       fun(vec, p + 1, mid, r);     }   }   int _count(int l, int r) {     if (l >= r) {       return 0;     }     if (l == r - 1) {       return 1;     }     int mid = (l + r) / 2;     return 1 + _count(l, mid) + _count(mid, r);   }   int main() {     int n, k, i, j;     cin >> n >> k;     if (k % 2 == 0) {       cout << -1;     } else if (k == 1) {       for (i = 1; i <= n; i++) {         cout << i <<    ;       }     } else {       int mm = _count(0, n);       if (k > mm) {         cout << -1;       } else {         vector<int> vec;         for (i = 1; i <= n; i++) {           vec.push_back(i);         }         fun(vec, k, 0, n);         for (i = 0; i < n; i++) {           cout << vec[i] <<    ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       int freq[26] = {0};       vector<int> v;       for (int i = 0; i < s.length(); ++i) {         freq[s[i] -  a ]++;       }       for (int i = 0; i < 26; ++i) {         v.push_back(freq[i]);       }       sort(v.begin(), v.end());       int maxAns = 1;       for (int i = 1; i <= k; ++i) {         if (k % i == 0) {           for (int j = i; j <= n; j += i) {             int ans = 0;             int div = j / i;             for (int k = 0; k < v.size(); ++k) {               ans += v[k] / div;             }             if (ans >= i) {               maxAns = max(maxAns, j);             }           }         }       }       cout << maxAns << endl;     }   }
#include <bits/stdc++.h>   int t;   long long n, k, d1, d2, td1, td2, x1, x2, x3;   bool solve() {     if (n % 3) return false;     for (int i = -1; i <= 1; ++i)       for (int j = -1; j <= 1; ++j) {         if (i == 0 || j == 0) continue;         d1 = i * td1;         d2 = j * td2;         if ((d1 * 2 + d2 + k) % 3 || (d2 - d1 + k) % 3 || (k - d1 - 2 * d2) % 3)           continue;         x1 = d1 * 2 + d2 + k;         x2 = d2 - d1 + k;         x3 = k - d1 - 2 * d2;         if (x1 <= n && x2 <= n && x3 <= n && x1 >= 0 && x2 >= 0 && x3 >= 0)           return true;       }     return false;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %lld%lld%lld%lld , &n, &k, &td1, &td2);       puts(solve() ?  yes  :  no );     }     return 0;   }
#include <bits/stdc++.h>   int n;   char str[50];   int F[50], sz[50];   inline int find(int x) { return x == F[x] ? x : F[x] = find(F[x]); }   inline void merge(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     F[y] = x;     sz[x] += sz[y];   }   std::vector<int> G[55];   int id[66];   int e[25];   int f[(1 << 23) + 5], g[(1 << 23) + 5], coe[(1 << 23) + 5];   int main() {     scanf( %d , &n);     for (int i = 0; i <= n - 1; ++i) F[i] = i, sz[i] = 1;     for (int i = 0; i <= n - 1; ++i) {       scanf( %s , str);       for (int j = i + 1; j <= n - 1; ++j) {         if (str[j] ==  A ) merge(i, j);         if (str[j] ==  X ) G[i].emplace_back(j), G[j].emplace_back(i);       }     }     int ans = n - 1;     n = 0;     for (int i = 0; i <= ans; ++i) id[i] = find(i);     for (int i = 0; i <= ans; ++i)       for (auto x : G[i])         if (id[i] == id[x]) {           puts( -1 );           exit(0);         }     for (int i = 0; i <= ans; ++i) {       if (sz[id[i]] == 1) {         id[i] = -1;         continue;       }       if (id[i] != i) {         id[i] = id[id[i]];         continue;       }       id[i] = n++;     }     if (n <= 1) {       printf( %d n , ans + n);       return 0;     }     assert(n <= 23);     for (int i = 0; i <= ans; ++i)       for (auto x : G[i])         if (~id[i] && ~id[x]) e[id[i]] |= (1 << id[x]);     f[0] = coe[0] = 1;     for (int S = 1; S <= (1 << n) - 1; ++S) {       int lb = __builtin_ctz(S);       f[S] = (!(e[lb] & S)) & f[S ^ (1 << lb)];       coe[S] = -coe[S ^ (1 << lb)];     }     for (int i = 0; i <= n - 1; ++i) {       for (int S = 0; S <= (1 << n) - 1; ++S) {         if ((S >> i) & 1) f[S] += f[S ^ (1 << i)];       }     }     for (int i = 0; i <= (1 << n) - 1; ++i) g[i] = f[i];     for (int k = 1; k <= n; ++k) {       auto chk = [&]() {         int ans = 0;         for (int S = 0; S <= (1 << n) - 1; ++S) ans += g[S] * coe[S];         return ans != 0;       };       if (chk()) {         printf( %d n , ans + k);         return 0;       }       for (int S = 0; S <= (1 << n) - 1; ++S) g[S] *= f[S];     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     while (scanf( %d , &n) != EOF) {       if (n % 2 == 1) {         printf( -1 n );         continue;       }       printf( 2 1 );       for (int i = 3; i < n; i = i + 2) printf(  %d %d , i + 1, i);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> Map;   pair<int, int> a[250001];   vector<int> b[250001], t[250001];   char type;   long long ans;   int len[250001], n, m, i, q, l, r, d, mid, nom, nomN, zn, sum;   bool pole[250001];   int get(int tl, int tr, int nom, int l, int r, int nomT) {     if (tl > tr) return 0;     if (tl > r || tr < l) return 0;     if (l <= tl && tr <= r) return t[nomT][nom];     int mid = (tl + tr) / 2;     return get(tl, mid, nom * 2, l, r, nomT) +            get(mid + 1, tr, nom * 2 + 1, l, r, nomT);   }   void update(int tl, int tr, int nom, int nomN, int zn, int nomT) {     if (tl > tr) return;     if (tl > nomN || tr < nomN) return;     t[nomT][nom] += zn;     if (tl == tr) return;     int mid = (tl + tr) / 2;     update(tl, mid, nom * 2, nomN, zn, nomT);     update(mid + 1, tr, nom * 2 + 1, nomN, zn, nomT);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (i = 0; i < n; i++)       if (!pole[i]) {         nom = i;         d++;         t[d].push_back(0);         b[d].push_back(0);         while (!pole[nom]) {           pole[nom] = true;           len[d]++;           a[nom + 1] = make_pair(d, len[d]);           b[d].push_back(nom);           t[d].push_back(0);           t[d].push_back(0);           t[d].push_back(0);           t[d].push_back(0);           nom = (nom + m) % n;         }       }     while (q--) {       cin >> type;       if (type ==  + ) {         cin >> zn >> nom;         nom++;         sum = 0;         if (get(1, len[a[nom].first], 1, a[nom].second, len[a[nom].first],                 a[nom].first) != len[a[nom].first] - a[nom].second + 1) {           l = a[nom].second;           r = len[a[nom].first];           while (l <= r) {             mid = (l + r) / 2;             if (get(1, len[a[nom].first], 1, a[nom].second, mid, a[nom].first) !=                 mid - a[nom].second + 1) {               r = mid - 1;               sum = mid - a[nom].second;             } else               l = mid + 1;           }           update(1, len[a[nom].first], 1, a[nom].second + sum, 1, a[nom].first);           Map[zn] = b[a[nom].first][a[nom].second + sum] + 1;         } else {           ans += len[a[nom].first] - a[nom].second + 1;           l = 1;           r = a[nom].second - 1;           while (l <= r) {             mid = (l + r) / 2;             if (get(1, len[a[nom].first], 1, 1, mid, a[nom].first) != mid) {               r = mid - 1;               sum = mid - 1;             } else               l = mid + 1;           }           update(1, len[a[nom].first], 1, sum + 1, 1, a[nom].first);           Map[zn] = b[a[nom].first][sum + 1] + 1;         }         ans += sum;       } else {         cin >> zn;         nom = Map[zn];         update(1, len[a[nom].first], 1, a[nom].second, -1, a[nom].first);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int nax = 1e5 + 5;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     for (auto &x : a) cin >> x;     long long int sum = 0, mx = 0;     for (long long int i = 0; i < n - 1; i++) {       sum += max((long long int)0, a[i] - a[i + 1]);     }     cout << sum <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int n = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       n = n * 10 + ch -  0 ;       ch = getchar();     }     return n * f;   }   char a[2000005], b[2000005];   int n;   int c[2000005];   int get(int x) {     int cur = 0, res = 0;     for (int i = 1; i <= n; i++) {       cur += x * c[i];       res = max(res, cur);       if (cur < 0) cur = 0;     }     return res;   }   int main() {     int s1 = 0, s2 = 0;     n = read();     scanf( %s%s , a + 1, b + 1);     for (int i = 1; i <= n; i++) {       if (a[i] != b[i] && a[i] ==  0 )         c[i] = -1, s1++;       else if (a[i] != b[i] && a[i] ==  1 )         c[i] = 1, s2++;     }     if (s1 != s2) {       printf( -1 n );       return 0;     }     printf( %d n , max(get(1), get(-1)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double sq(long double a) { return a * a; }   long double dist(pair<long double, long double> a,                    pair<long double, long double> b) {     return sqrt((long double)(sq(a.second - b.second) + sq(a.first - b.first)));   }   long double mandist(pair<long long, long long> a,                       pair<long long, long long> b) {     return abs(a.second - b.second) + abs(a.first - b.first);   }   long long a, b, c;   pair<long long, long long> p1, p2;   int main() {     scanf(  %lld%lld%lld , &a, &b, &c);     scanf(  %lld%lld%lld%lld , &p1.first, &p1.second, &p2.first, &p2.second);     if (a == 0 || b == 0)       printf( %.20Lf n , mandist(p1, p2));     else {       long double res = mandist(p1, p2);       long double interhoriz1 =           ((long double)(-c - a * p1.first)) / ((long double)b);       long double interhoriz2 =           ((long double)(-c - a * p2.first)) / ((long double)b);       long double intervert1 =           ((long double)(-c - b * p1.second)) / ((long double)a);       long double intervert2 =           ((long double)(-c - b * p2.second)) / ((long double)a);       res = min(res, abs((long double)p1.second - interhoriz1) +                          abs((long double)p2.second - interhoriz2) +                          dist(make_pair((long double)p1.first, interhoriz1),                               make_pair((long double)p2.first, interhoriz2)));       res = min(res, abs((long double)p1.second - interhoriz1) +                          abs((long double)p2.first - intervert2) +                          dist(make_pair((long double)p1.first, interhoriz1),                               make_pair(intervert2, (long double)p2.second)));       res = min(res, abs((long double)p1.first - intervert1) +                          abs((long double)p2.first - intervert2) +                          dist(make_pair(intervert1, (long double)p1.second),                               make_pair(intervert2, (long double)p2.second)));       res = min(res, abs((long double)p1.first - intervert1) +                          abs((long double)p2.second - interhoriz2) +                          dist(make_pair(intervert1, (long double)p1.second),                               make_pair((long double)p2.first, interhoriz2)));       printf( %.20Lf n , res);     }   }
#include <bits/stdc++.h>   using namespace std;   int a[2005], b[2005];   int main() {     int n, i, j, x, y, k;     long long s;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       a[x + y]++;       b[1001 + x - y]++;     }     s = 0;     for (i = 0; i < 2003; i++) {       k = a[i];       s += (k - 1) * k / 2;       k = b[i];       s += (k - 1) * k / 2;     }     cout << s << endl;     return 0;   }