malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n, d, m, t[200005][2], l, p, r, b;   long long ans;   std::pair<int, int> s[200005];   bool a = true;   int main() {     scanf( %d %d %d , &d, &n, &m);     for (int i = 0; i < m; i++) scanf( %d %d , &s[i].first, &s[i].second);     std::sort(s, s + m);     t[l][0] = 0;     t[l++][1] = n;     s[m].first = d;     s[m].second = 0;     for (int i = 0; i <= m && a; i++) {       if (s[i].first - p > n)         a = false;       else {         r = s[i].first - p;         while (s[i].first > p) {           if (p + t[b][1] <= s[i].first) {             ans += (long long)t[b][0] * t[b][1];             p += t[b][1];             b++;           } else {             ans += (long long)t[b][0] * (s[i].first - p);             t[b][1] -= s[i].first - p;             p = s[i].first;           }         }         while (l > b && s[i].second <= t[l - 1][0]) r += t[--l][1];         t[l][0] = s[i].second;         t[l++][1] = r;       }     }     printf( %I64d n , a ? ans : -1);     scanf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i;   int p[200011];   int aib[200011];   int ord[2][200011];   int ans[200011];   int zrs(int x) { return (x & (x - 1)) ^ x; }   void add(int x, int v) {     while (x <= n) {       aib[x] += v;       x += zrs(x);     }   }   int sum(int x) {     int ans = 0;     while (x > 0) {       ans += aib[x];       x -= zrs(x);     }     return ans;   }   int cb(int x) {     int ans = 0;     for (int step = (1 << 19); step > 0; step >>= 1)       if (ans + step <= n)         if (aib[ans + step] <= x) x -= aib[ans += step];     return ans;   }   void get_order(int n, int *p, int *ans) {     int i;     for (i = 1; i <= n; i++) aib[i] = zrs(i);     memset(ans, 0, sizeof(ans));     for (i = 1; i <= n; i++) {       ans[n - i] = sum(p[i] - 1);       add(p[i], -1);     }   }   void get_perm(int n, int *ord, int *ans) {     int i, cnt, pos;     for (i = 1; i <= n; i++) aib[i] = zrs(i);     memset(ans, 0, sizeof(ans));     for (i = 1; i <= n; i++) {       cnt = ord[n - i] + 1;       pos = cb(cnt - 1) + 1;       ans[i] = pos;       add(pos, -1);     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), p[i]++;     get_order(n, p, ord[0]);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), p[i]++;     get_order(n, p, ord[1]);     for (i = 1; i <= n; i++) ord[0][i] += ord[1][i];     for (i = 1; i <= n; i++) {       ord[0][i + 1] += ord[0][i] / (i + 1);       ord[0][i] %= i + 1;     }     get_perm(n, ord[0], ans);     for (i = 1; i <= n; i++) printf( %d  , ans[i] - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int nax = 1e6 + 10;   vector<int> tree(4 * nax);   long long i, j, x, y, k;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, t;     cin >> t;     while (t--) {       cin >> n;       vector<long long> a;       set<long long> b;       for (i = 0; i < n; i++) {         cin >> x;         a.push_back(x);         b.insert(x);       }       if (b.size() == 1) {         cout << 1 << endl;         for (i = 0; i < n; i++) cout << 1 <<    ;       } else if (a.size() % 2 == 0) {         cout << 2 << endl;         for (i = 0; i < n / 2; i++) cout << 1 <<     << 2 <<    ;       } else if (a.size() % 2 != 0) {         vector<long long> ans;         int p = 0, q = 0;         ans.push_back(1);         for (i = 1; i < a.size() - 1; i++) {           if (a[i] == a[i - 1] && p == 0) {             ans.push_back(ans[i - 1]);             p = 1;           } else if (q == 0) {             ans.push_back(2);             q = 1;           } else if (q == 1) {             ans.push_back(1);             q = 0;           }         }         if (p == 1) {           if (q == 1)             ans.push_back(1);           else             ans.push_back(2);         } else {           if (a[n - 1] == a[n - 2])             ans.push_back(ans[n - 2]);           else if (a[n - 1] == a[0])             ans.push_back(ans[0]);           else             ans.push_back(3);         }         if (ans[n - 1] == 3)           cout << 3 << endl;         else           cout << 2 << endl;         for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> lucky;   void backtrack(long long x) {     if (x > 1e10) return;     lucky.push_back(x);     backtrack(x * 10 + 4);     backtrack(x * 10 + 7);   }   int main() {     long long ans = 0;     backtrack(0);     sort(lucky.begin(), lucky.end());     int a, b;     cin >> a >> b;     for (int i = 1; i < (int)lucky.size(); i++) {       int l, r, m;       l = a, r = b;       while (l <= r) {         m = (l + r) >> 1;         if (m <= lucky[i]) {           ans += lucky[i] * (m - l + 1);           a = m + 1;           i--;           break;         } else {           r = m - 1;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     vector<pair<int, int>> vp(n);     for (int i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;     sort(vp.begin(), vp.end());     long long res = 1;     pair<int, int> pa = {vp[0].first, vp[0].second};     for (int i = 0; i < n; i++) {       if (vp[i].first > pa.second)         pa = {vp[i].first, vp[i].second}, res++;       else if (vp[i].second < pa.second)         pa = {vp[i].first, vp[i].second};     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int m, c;     int mc = 0, cc = 0;     cin >> t;     while (t--) {       cin >> m >> c;       if (m > c)         mc++;       else if (m < c)         cc++;     }     if (mc == cc)       cout <<  Friendship is magic!^^ ;     else if (mc < cc)       cout <<  Chris ;     else       cout <<  Mishka ;   }
#include <bits/stdc++.h>   using namespace std;   int N;   struct node {     int val, pos;   } A[2005];   int res[2005];   int cmp1(node a, node b) { return a.val > b.val; }   int main() {     A[0].val = 0x7fffffff;     cin >> N;     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i].val);       A[i].pos = i;     }     sort(A + 1, A + 1 + N, cmp1);     for (int i = 1; i <= N; i++) {       if (A[i - 1].val == A[i].val)         res[A[i].pos] = res[A[i - 1].pos];       else         res[A[i].pos] = i;     }     for (int i = 1; i <= N; i++) printf( %d%c , res[i], i == N ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 10;   const long long M = 1e6 + 11;   const long long big = 1e17;   const long long hsh2 = 1964325029;   const long long mod = 1e9 + 7;   const double EPS = 1e-9;   const long long block = 1e14;   const long long shift = 2e3;   const double pi = acos(-1.0);   mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());   long long n;   struct dsu {     long long p[N], sz[N];     set<long long> comp;     void init() {       for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1, comp.insert(i);     }     long long fnd(long long a) { return (p[a] = (p[a] == a ? a : fnd(p[a]))); }     void unt(long long a, long long b) {       a = fnd(a), b = fnd(b);       if (a == b) return;       if (sz[a] < sz[b]) swap(a, b);       comp.erase(b);       sz[a] += sz[b];       p[b] = a;     }   } rt[2];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     rt[0].init();     rt[1].init();     long long m[2] = {0};     cin >> m[0] >> m[1];     long long sm[2] = {m[0], m[1]};     while (m[0]--) {       long long a, b;       cin >> a >> b;       rt[0].unt(a, b);     }     while (m[1]--) {       long long a, b;       cin >> a >> b;       rt[1].unt(a, b);     }     vector<pair<long long, long long> > ans;     while (sm[0] < n - 1 && sm[1] < n - 1) {       long long i = bruh() % n + 1, j = bruh() % n + 1;       auto it = rt[0].comp.lower_bound(i), it2 = rt[1].comp.lower_bound(j);       if (it == rt[0].comp.end()) it--;       if (it2 == rt[1].comp.end()) it2--;       i = *it, j = *it2;       if (rt[0].fnd(i) != rt[0].fnd(j) && rt[1].fnd(i) != rt[1].fnd(j)) {         sm[0]++, sm[1]++;         rt[0].unt(i, j);         rt[1].unt(i, j);         ans.push_back(make_pair(i, j));       }     }     cout << ans.size() <<   n ;     for (auto u : ans) cout << u.first <<     << u.second <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[100005];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int cur = min(2, n);     int best = min(2, n);     for (int i = 2; i < n; i++) {       if (arr[i - 2] + arr[i - 1] == arr[i])         cur++;       else         cur = 2;       best = max(best, cur);     }     cout << best << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> l;       cin >> s;       int ans = 0;       bool lol = false;       int tmp = 0;       for (int j = 0; j < l; j++) {         if (s[j] ==  A ) {           lol = true;           if (tmp > ans) ans = tmp;           tmp = 0;         } else {           if (lol) {             tmp++;           }         }       }       if (tmp > ans) ans = tmp;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     int sol;     int s[100009];     cin >> x >> y;     s[0] = 0;     for (int i = 1; i < x; i++) {       cin >> z;       s[i] = z + s[i - 1];     }     sol = s[y];     for (int i = y + 1; i < x; i++) {       sol = min(sol, s[i] - s[i - y]);     }     cout << sol << endl;   }
#include <bits/stdc++.h>   const int N = 1010;   double f[N][N];   bool vis[N][N];   inline double F(int m, int n) {     if (!m) return 1. / (n + 1);     if (!n) return 1;     if (vis[m][n]) return f[m][n];     vis[m][n] = true;     double p = 1 / (1 + (1. / ((n + 1) * F(n, m - 1))));     return f[m][n] = p * n / (n + 1) * (1 - F(n - 1, m)) + 1 - p;   }   int main() {     int m, n;     scanf( %d%d , &m, &n);     printf( %.11f %.11f n , F(m, n), 1 - F(m, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, len, ct;   int a[maxn], tot[maxn], cur[maxn];   long long ans;   void solve() {     for (int i = 1; i <= n; i++) tot[i] = cur[i] = 0;     for (int i = 1; i <= n; i++) tot[a[i]]++;     int r = 1;     for (int i = 1; i <= (n - 1) / 2; i++) {       while (r <= (n - 1) / 2 && (cur[a[r]] + 1) * 2 <= tot[a[r]]) {         cur[a[r]]++;         r++;       }       ans += r - i + 1;       if (a[i] != a[n - i + 1]) break;       tot[a[i]] -= 2;       cur[a[i]]--;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), tot[a[i]]++;     int val = 0;     for (int i = 1; i <= n; i++)       if (tot[i] & 1) {         if (val) {           puts( 0 );           return 0;         }         val = i;       }     while (1 + len <= n && n - len >= 1 && a[1 + len] == a[n - len]) len++;     if (len == n) {       printf( %lld n , 1LL * n * (n + 1) / 2);       return 0;     }     int l = n / 2, r = n / 2 + 1 + (n & 1);     while (l - ct >= 1 && r + ct <= n && a[l - ct] == a[r + ct]) ct++;     for (int i = 1; i <= n; i++) cur[i] = 0;     for (int i = len + 1; i <= l - ct; i++) cur[a[i]]++;     bool bad = false;     for (int i = r + ct; i <= n - len; i++) {       if (!cur[a[i]]) {         bad = true;         break;       }       cur[a[i]]--;     }     if (!bad) ans = 2LL * (len + 1) * (ct + 1);     solve();     reverse(a + 1, a + 1 + n);     solve();     ans -= len + 1;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int ans = 0;       if (a >= 1) {         a--;         ans++;       }       if (b >= 1) {         b--;         ans++;       }       if (c >= 1) {         c--;         ans++;       }       if (a < b) swap(a, b);       if (b < c) swap(b, c);       if (a < b) swap(a, b);       if (a >= 1 && b >= 1) {         a--;         b--;         ans++;       }       if (a >= 1 && c >= 1) {         a--;         c--;         ans++;       }       if (b >= 1 && c >= 1) {         b--;         c--;         ans++;       }       if (a >= 1 && b >= 1 && c >= 1) ans++;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int a[N];   long long ans[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << -a[1] <<   n ;       return 0;     }     for (int i = 1; i <= n; i++) {       long long x = a[i];       long long yu = x % (n - 1);       long long byu = (n - 1 - yu) * n;       ans[i] = byu + a[i];     }     cout << 1 <<     << n <<   n ;     for (int i = 1; i <= n; i++) {       cout << ans[i] - a[i] <<    ;     }     cout <<   n ;     cout << 1 <<     << 1 <<   n ;     cout << -ans[1] <<   n ;     cout << 2 <<     << n <<   n ;     for (int i = 2; i <= n; i++) {       cout << -ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1100000;   const long long M = 1000000007;   long long i, j, k, l, m, n, o, p, K, w, F[N], ni[N];   inline long long fastmi(long long x, long long m) {     long long ans = 1;     while (m) {       if (m & 1) ans = (ans * x) % M;       x = (x * x) % M;       m >>= 1;     }     return ans;   }   inline long long get(long long l, long long r) {     long long ans;     if ((r < 0) || (l < 0)) return 0;     if (l > r) return 1;     if (l == 0) return 0;     ans = (F[r] * ni[l - 1]) % M;     return ans;   }   inline long long Solve() {     long long ans1, ans2, ans, cul, cant;     F[0] = 1;     ni[0] = 1;     for (i = 1; i <= K; i++) {       F[i] = (F[i - 1] * i) % M;       ni[i] = fastmi(F[i], M - 2);     }     ans = 0;     for (i = 0; i <= K - 1; i++) {       cant = i + 1 - w + 1;       if (cant < 0) cant = 0;       k = K - cant;       o = (get(K - i, K - 1) * min(w, i + 1)) % M;       l = w - i - 2;       if (l < 0) l = 0;       j = w - 1 - l;       p = (fastmi(k, l) * get(k - j + 1, k)) % M;       cul = (o * p) % M;       ans += cul;       if (ans >= M) ans -= M;     }     ans1 = ans;     ans = 0;     for (i = 0; i <= K - 1; i++) {       cant = i + 1 - (w - 1) + 1;       if (cant < 0) cant = 0;       k = K - cant;       o = (get(K - i, K - 1) * min(w - 1, i + 1)) % M;       l = w - 1 - i - 2;       if (l < 0) l = 0;       j = w - 1 - l;       p = (fastmi(k, l) * get(k - j + 1, k)) % M;       cul = (o * p) % M;       ans += cul;       if (ans >= M) ans -= M;     }     ans2 = ans1 - ans;     if (ans2 < 0) ans2 += M;     ans1 = ans1 + ans1;     if (ans1 >= M) ans1 -= M;     ans1 -= ans2;     if (ans1 < 0) ans1 += M;     ans = (ans1 * K) % M;     return ans;   }   int main() {     cin >> K >> w;     cout << Solve() << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 5;   const int MOD = 1000000009;   int s[N * 4], f[N], a[N], taga[N * 4], tagb[N * 4];   int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   void update(int x) { s[x] = (s[x << 1] + s[x << 1 | 1]) % MOD; }   void push(int x, int a, int b, int n) {     taga[x] = (taga[x] + a) % MOD;     tagb[x] = (tagb[x] + b) % MOD;     s[x] = ((long long)f[n] * a + (long long)(f[n + 1] - 1) * b + s[x]) % MOD;   }   void pushdown(int x, int l, int r) {     if (taga[x] > 0 || tagb[x] > 0) {       int mid = (l + r) >> 1, a = taga[x], b = tagb[x], C = mid - l,           A = ((long long)f[C] * a + (long long)f[C + 1] * b) % MOD,           B = ((long long)f[C + 1] * a + (long long)f[C + 2] * b) % MOD;       push(x << 1, a, b, mid - l + 1), push(x << 1 | 1, A, B, r - mid);       taga[x] = tagb[x] = 0;     }   }   void build(int x, int l, int r) {     if (l == r) {       s[x] = a[l];       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     update(x);   }   void change(int x, int l, int r, int p, int q) {     if (l > q || r < p) return;     if (l >= p && r <= q) {       push(x, f[l - p + 1], f[l - p + 2], r - l + 1);       return;     }     int mid = (l + r) >> 1;     pushdown(x, l, r);     change(x << 1, l, mid, p, q);     change(x << 1 | 1, mid + 1, r, p, q);     update(x);   }   int query(int x, int l, int r, int p, int q) {     if (l > q || r < p) return 0;     if (l >= p && r <= q) return s[x];     int mid = (l + r) >> 1;     pushdown(x, l, r);     return (query(x << 1, l, mid, p, q) + query(x << 1 | 1, mid + 1, r, p, q)) %            MOD;   }   void prints(int x, int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     pushdown(x, l, r);     prints(x << 1, l, mid);     prints(x << 1 | 1, mid + 1, r);   }   int main() {     int n = read(), m = read();     f[0] = 0, f[1] = 1;     for (int i = 2; i <= n + 2; i++) f[i] = (f[i - 1] + f[i - 2]) % MOD;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, 1, n);     for (int i = 1; i <= m; i++) {       int t = read(), l = read(), r = read();       if (t == 1)         change(1, 1, n, l, r);       else         printf( %d n , query(1, 1, n, l, r));     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q, fa[50005], ff[50005], h[50005], tot, e[50005 << 1], nxt[50005 << 1],       mx[50005][256], cnt[50005][256], Ans[50005][256], ans, val[50005],       dep[50005];   template <class T>   inline void read(T &x) {     x = 0;     bool emm = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) emm = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     x *= emm;   }   inline void add(int x, int y) { e[++tot] = y, nxt[tot] = h[x], h[x] = tot; }   inline void dfs(int x) {     dep[x] = dep[fa[x]] + 1;     int i;     if (dep[x] >= 256) {       int l, r, mid, s;       for (i = x; dep[x] - dep[i] < 256; i = fa[i]) {         mx[x][val[i] >> 8] =             max(mx[x][val[i] >> 8], (dep[x] - dep[i] ^ val[i]) & 255);         cnt[x][val[i] >> 8]++;       }       ff[x] = i;       for (i = 1; i < 256; i++) cnt[x][i] += cnt[x][i - 1];       for (i = 0; i <= (n - 1) / 256; i++) {         for (l = s = 0, r = 256, mid = r >> 1; l < r - 1; mid = l + r >> 1) {           if ((s ^ i) < mid) {             if (cnt[x][r - 1] > cnt[x][mid - 1])               s |= r - mid, l = mid;             else               r = mid;           } else {             if (cnt[x][mid - 1] > ((l) ? cnt[x][l - 1] : 0))               s |= r - mid, r = mid;             else               l = mid;           }         }         Ans[x][i] = (s << 8) | mx[x][l];       }     }     for (i = h[x]; i; i = nxt[i])       if (e[i] != fa[x]) fa[e[i]] = x, dfs(e[i]);   }   int main() {     read(n), read(q);     for (int i = 1; i <= n; i++) read(val[i]);     for (int x, y, i = 1; i < n; i++) read(x), read(y), add(x, y), add(y, x);     for (dfs(1); q--;) {       int u, v, dis;       read(u), read(v);       for (dis = ans = 0; dep[v] - dep[u] >= 256; v = ff[v], dis++)         ans = max(ans, Ans[v][dis]);       for (dis <<= 8; v != fa[u]; v = fa[v], dis++) ans = max(ans, dis ^ val[v]);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:67108864 )   const int MOD = 1000000007;   const long long INF = 3000000000000000001;   const double EPS = 1e-6;   const int HASH_POW = 29;   const double PI = acos(-1.0);   using namespace std;   double workTime() { return double(clock()) / CLOCKS_PER_SEC; }   void my_return(int code) { exit(code); }   int n, q;   char p[2][200010];   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   int cur = 0, cmp[2][200010];   void dfs(int x, int y) {     if (p[x][y] ==  X ) return;     cmp[x][y] = cur;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (0 <= nx && nx < 2 && 0 <= ny && ny < n && cmp[nx][ny] == 0) dfs(nx, ny);     }   }   int sum[200010], ll[200010], rr[200010];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     mt19937 mt_rand(time(0));     scanf( %d %d n , &n, &q);     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < n; ++j) p[i][j] = getchar();       getchar();     }     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < n; ++j) {         if (!cmp[i][j]) {           ++cur;           dfs(i, j);         }       }     }     int lastx = -1;     for (int j = 0; j < n; ++j) {       if (p[0][j] ==  X  && p[1][j] ==  . ) {         if (lastx == 1) ++sum[j];         lastx = 0;       } else if (p[0][j] ==  .  && p[1][j] ==  X ) {         if (lastx == 0) ++sum[j];         lastx = 1;       } else if (p[0][j] ==  X  && p[1][j] ==  X )         lastx = -1;     }     for (int j = 1; j < n; ++j) sum[j] += sum[j - 1];     ll[0] = -1;     for (int j = 0; j < n; ++j)       if ((p[0][j] ==  X  && p[1][j] ==  . ) ||           (p[0][j] ==  .  && p[1][j] ==  X ))         ll[j] = j;     for (int j = 1; j < n; ++j)       if (!ll[j]) ll[j] = ll[j - 1];     rr[n - 1] = -1;     for (int j = n - 1; j >= 0; --j)       if ((p[0][j] ==  X  && p[1][j] ==  . ) ||           (p[0][j] ==  .  && p[1][j] ==  X ))         rr[j] = j;     for (int j = n - 2; j >= 0; --j)       if (!rr[j]) rr[j] = rr[j + 1];     while (q--) {       int foo, bar;       scanf( %d %d , &foo, &bar);       int x1, y1, x2, y2;       x1 = (foo - 1) / n;       y1 = (foo - 1) % n;       x2 = (bar - 1) / n;       y2 = (bar - 1) % n;       if (y1 > y2) {         swap(x1, x2);         swap(y1, y2);       }       if (cmp[x1][y1] != cmp[x2][y2])         printf( -1 n );       else {         if (rr[y1] == rr[y2])           printf( %d n , abs(y1 - y2) + abs(x1 - x2));         else {           int ans = 0;           int nxtL = rr[y1], nxtR = ll[y2];           ans += abs(nxtL - y1) + abs(nxtR - y2);           if (p[x1][nxtL] ==  X ) ++ans;           if (p[x2][nxtR] ==  X ) ++ans;           ans += abs(nxtR - nxtL) + sum[nxtR];           if (nxtL) ans -= sum[nxtL];           printf( %d n , ans);         }       }     }     my_return(0);   }
#include <bits/stdc++.h>   using namespace std;   using point_t = pair<int, int>;   int main() {     size_t n;     cin >> n;     vector<point_t> obelisks(n), clues(n);     for (point_t &p : obelisks) cin >> p.first >> p.second;     for (point_t &p : clues) cin >> p.first >> p.second;     point_t treasure;     map<point_t, size_t> finds;     for (point_t &ob : obelisks)       for (point_t &cl : clues) {         point_t p{ob.first + cl.first, ob.second + cl.second};         size_t &c{++finds[p]};         if (c == n) {           cout << p.first <<     << p.second << endl;           return 0;         }       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, mini, c = 0;     scanf( %d %d %d , &n, &m, &mini);     for (int i = m; i < mini + 1; i += m) {       if (i % n == 0) c++;     }     printf( %d n , c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long num[20];   int cnt;   int main() {     int n;     long long k, x;     long long ans = 0LL;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cnt = 0;       scanf( %I64d%I64d , &x, &k);       long long r = x + k - 1LL;       long long l = x;       while (l % 4 != 0 && l <= r) num[++cnt] = l++;       l--;       while (r % 4 != 3 && l < r) num[++cnt] = r--;       for (int j = 1; j <= cnt; j++) ans ^= num[j];     }     if (ans == 0LL)       printf( bolik n );     else       printf( tolik n );     return 0;   }