malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void RD(int &x) { scanf( %d , &x); }   void RD(long long &x) { scanf( %I64d , &x); }   void RD(unsigned int &x) { scanf( %u , &x); }   void RD(double &x) { scanf( %lf , &x); }   void RD(int &x, int &y) { scanf( %d%d , &x, &y); }   void RD(long long &x, long long &y) { scanf( %I64d%I64d , &x, &y); }   void RD(unsigned int &x, unsigned int &y) { scanf( %u%u , &x, &y); }   void RD(double &x, double &y) { scanf( %lf%lf , &x, &y); }   void RD(int &x, int &y, int &z) { scanf( %d%d%d , &x, &y, &z); }   void RD(long long &x, long long &y, long long &z) {     scanf( %I64d%I64d%I64d , &x, &y, &z);   }   void RD(unsigned int &x, unsigned int &y, unsigned int &z) {     scanf( %u%u%u , &x, &y, &z);   }   void RD(double &x, double &y, double &z) { scanf( %lf%lf%lf , &x, &y, &z); }   void RD(char &x) { x = getchar(); }   void RD(char *s) { scanf( %s , s); }   void RD(string &s) { cin >> s; }   void PR(int x) { printf( %d n , x); }   void PR(int x, int y) { printf( %d %d n , x, y); }   void PR(long long x) { printf( %I64d n , x); }   void PR(unsigned int x) { printf( %u n , x); }   void PR(unsigned long long x) { printf( %I64u n , x); }   void PR(double x) { printf( %.6lf n , x); }   void PR(char x) { printf( %c n , x); }   void PR(char *x) { printf( %s n , x); }   void PR(string x) { cout << x << endl; }   const int mod = 1000000007;   const long long inf = ((long long)1) << 60;   const int INF = 100000000;   const int N = 1000005;   vector<pair<int, int> > V;   long long Pow[N];   int n, m, K;   void init() {     Pow[0] = 1;     int i;     for (i = 1; i <= N - 1; i++) Pow[i] = Pow[i - 1] * 2 % mod;   }   int main() {     init();     while (scanf( %d , &n) != -1) {       RD(m, K);       V.clear();       int i, x, y, cnt, flag = 1;       for (i = 1; i <= m; i++) {         RD(x, y);         if (y - x != 1 && y - x != K + 1) flag = 0;         if (y - x == K + 1) V.push_back(make_pair(x, y));       }       if (!flag) {         puts( 0 );         continue;       }       sort(V.begin(), V.end());       if (!K || K >= n - 1) {         puts( 1 );         continue;       }       for (i = 0; i < V.size(); i++)         if (!(V[i].first >= V[0].first && V[i].first < V[0].second)) {           break;         }       if (i < V.size()) {         puts( 0 );         continue;       }       long long ans = 0;       if (!V.size()) ans++;       int t = V.size();       for (i = 1; i <= n; i++) {         x = i;         y = i + K + 1;         cnt = t;         if (y > n || t && x > V[0].first) break;         if (t && !(x <= V[0].first && V[t - 1].first < y)) continue;         if (t && x == V[0].first) cnt--;         y = ((y) < (n - K) ? (y) : (n - K));         ans += Pow[y - x - 1 - cnt];         ans %= mod;       }       PR(ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1001];   int main(void) {     int k, l, r, i, j;     cin >> s >> k;     l = strlen(s);     r = l / k;     if (l % k != 0) {       cout <<  NO  << endl;       return 0;     }     for (i = 0; i < l; i += r)       for (j = 0; j < r / 2; j++) {         if (s[i + j] != s[i + r - j - 1]) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   int main() {     int n, k, m;     scanf( %d%d%d , &n, &k, &m);     int interior = 0;     vector<pair<int, int>> t;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       if (t.empty() || t.back().first != x)         t.push_back({x, 1});       else {         t.back().second++;         if (t.back().second == k) {           t.pop_back();           ++interior;         }       }     }     vector<pair<int, int>> memo = t;     int border = 0;     int start = 0;     while ((int)t.size() - start >= 2 && t[start].first == t.back().first &&            t[start].second + t.back().second >= k) {       int tmp = t[start].second + t.back().second;       border += tmp / k;       tmp -= tmp / k * k;       if (tmp == 0) {         ++start;         t.pop_back();       } else {         t.pop_back();         t[start].second = tmp;       }     }     debug() <<   [              <<  interior                  :               << (interior)             <<  ]                    [              <<  border                  :               << (border) <<  ]  ;     long long answer =         (long long)interior * m * k + (long long)border * (m - 1) * k;     if ((int)t.size() == start + 1) {       long long a = (long long)m * t[start].second;       answer += a / k * k;       a -= a / k * k;       if (a == 0) {         debug() <<  spec case ;         vector<pair<int, int>> nowy;         for (int i = 0; i < start; ++i) nowy.push_back(memo[i]);         for (int i = (int)t.size(); i < (int)memo.size(); ++i)           nowy.push_back(memo[i]);         debug() <<   [                  <<  nowy                      :                   << (nowy) <<  ]  ;         vector<pair<int, int>> dwa;         for (pair<int, int> p : nowy) {           if (dwa.empty() || dwa.back().first != p.first)             dwa.push_back(p);           else {             dwa.back().second += p.second;             answer += dwa.back().second / k * k;             dwa.back().second %= k;             if (dwa.back().second == 0) dwa.pop_back();           }         }       }     }     printf( %lld n , (long long)n * m - answer);   }
#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   void clock_out() {     cerr <<   nTime Elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;   }   void fileio() {     freopen( /home/dwai/Desktop/cp/input.txt ,  r , stdin);     freopen( /home/dwai/Desktop/cp/output.txt ,  w , stdout);     freopen( /home/dwai/Desktop/cp/debug.txt ,  w , stderr);   }   void ofileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   int IT_MAX = 1 << 20;   const long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   void solve() {     long long n, sx, sy;     cin >> n >> sx >> sy;     vector<pair<long long, long long> > v(n);     long long i;     long long d[n];     for (i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       d[i] = abs(v[i].first - sx) + abs(v[i].second - sy);     }     pair<long long, long long> p;     long long m = 0;     vector<pair<long long, long long> > pos({{0, 1}, {0, -1}, {1, 0}, {-1, 0}});     for (pair<long long, long long> cord : pos) {       long long cx = cord.first + sx, cy = cord.second + sy;       long long cm = 0;       i = 0;       for (pair<long long, long long> x : v) {         long long cd = abs(cx - x.first) + abs(cy - x.second);         if (cd < d[i]) cm++;         i++;       }       if (cm > m) {         m = cm;         p = make_pair(cx, cy);       }     }     cout << m <<   n  << p.first <<     << p.second;   }   int main() {     42;     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, fp = 0;     cin >> n;     vector<int> p(n);     bool nice = false;     bool entrou = false;     for (int i = 0; i < n; i++) {       cin >> p[i];       if (i == p[i]) fp = fp + 1;     }     for (int i = 0; i < n; i++) {       if (p[i] != i) {         entrou = true;         if (p[p[i]] == i) {           fp = fp + 2;           nice = true;           break;         }       }     }     if (!nice && entrou) {       fp = fp + 1;     }     cout << fp << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct disjoint_set {     vector<int> p;     disjoint_set(int n) : p(n, -1) {}     bool share(int a, int b) { return root(a) == root(b); }     int sz(int u) { return -p[root(u)]; }     int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); }     bool merge(int u, int v) {       u = root(u), v = root(v);       if (u == v) return false;       if (p[u] > p[v]) swap(u, v);       p[u] += p[v], p[v] = u;       return true;     }   };   template <class T>   struct graph {     struct edge {       int from, to;       T cost;     };     int n;     vector<edge> edges;     vector<vector<int>> adj;     function<bool(int)> ignore;     graph(int n) : n(n), adj(n), ignore(nullptr) {}     int link(int u, int v, T w = 1) {       int id = (int)edges.size();       adj[u].push_back(id), adj[v].push_back(id), edges.push_back({u, v, w});       return id;     }     int orient(int u, int v, T w = 1) {       int id = (int)edges.size();       adj[u].push_back(id), edges.push_back({u, v, w});       return id;     }     graph reversed() const {       graph res(n);       for (auto &e : edges) {         res.orient(e.to, e.from, e.cost);       }       return res;     }   };   template <class T, class U>   T &ctmax(T &x, const U &y) {     return x = max<T>(x, y);   }   template <class T, class U>   T &ctmin(T &x, const U &y) {     return x = min<T>(x, y);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(ios::badbit | ios::failbit);     int n, m;     cin >> n >> m;     disjoint_set dsu(n << 1);     graph<int> g(n);     for (auto i = 0; i < m; ++i) {       int u, v;       cin >> u >> v, --u, --v;       dsu.merge(u, v + n), dsu.merge(v, u + n);       if (dsu.share(u, u + n)) {         cout <<  -1 n ;         return 0;       }       g.link(u, v);     }     int res = 0;     vector<int> dist(n, -1), vis(n);     for (auto s = 0; s < n; ++s) {       if (!vis[s]) {         vector<int> cur;         function<void(int)> dfs = [&](int u) {           vis[u] = true;           cur.push_back(u);           for (auto id : g.adj[u]) {             auto &e = g.edges[id];             int v = u ^ e.from ^ e.to;             if (!vis[v]) {               dfs(v);             }           }         };         dfs(s);         auto get_max_dist = [&](int s) {           for (auto u : cur) {             dist[u] = -1;           }           deque<int> dq{s};           dist[s] = 0;           int res = 0;           while (!dq.empty()) {             int u = dq.front();             dq.pop_front();             for (auto id : g.adj[u]) {               auto &e = g.edges[id];               int v = u ^ e.from ^ e.to;               if (!~dist[v]) {                 dq.push_back(v);                 res = dist[v] = dist[u] + 1;               }             }           }           return res;         };         int cur_max = 0;         for (auto s : cur) {           ctmax(cur_max, get_max_dist(s));         }         res += cur_max;       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 101000;   int n, m, k[N], g[50][50], cnt[50], tmp[50];   vector<pair<int, int> > v[N];   inline int gcd(int first, int second) {     return (!second) ? first : gcd(second, first % second);   }   inline void init() {     int i, j;     for (i = 1; i <= 40; ++i)       for (j = 1; j <= 40; ++j) g[i][j] = gcd(i, j);   }   inline bool insert(pair<int, int> p) {     int i;     for (i = 1; i <= 40; ++i)       if (cnt[i] && (p.second - tmp[i]) % g[k[p.first]][i]) return 0;     return tmp[k[p.first]] = p.second, ++cnt[k[p.first]], 1;   }   inline void erase(pair<int, int> p) {     --cnt[k[p.first]];     if (!cnt[k[p.first]]) tmp[k[p.first]] = 0;   }   inline void solve(int first) {     int i = 0, j = 0, ans = 0, t = 0;     memset(cnt, 0, sizeof(cnt));     while (j < v[first].size()) {       while (j < v[first].size() &&              j - i == v[first][j].first - v[first][i].first &&              insert(v[first][j]))         ++j;       ans = max(ans, j - i);       erase(v[first][i]), ++i;     }     cout << ans << endl;   }   int main() {     ios ::sync_with_stdio(false);     int i, j, first;     init();     cin >> n >> m;     for (i = 1; i <= n; ++i) {       cin >> k[i];       for (j = 1; j <= k[i]; ++j)         cin >> first, v[first].push_back(make_pair(i, j));     }     for (i = 1; i <= m; ++i) solve(i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void moveLeft() { cout <<  LEFT  << endl; }   void moveRight() { cout <<  RIGHT  << endl; }   void print(char ch) { cout <<  PRINT   << ch << endl; }   int main() {     int numberOfCells, currentCell;     cin >> numberOfCells >> currentCell;     string slogan;     cin >> slogan;     if (currentCell <= numberOfCells - currentCell) {       while (currentCell != 1) {         moveLeft();         currentCell--;       }       while (currentCell <= numberOfCells) {         print(slogan[currentCell - 1]);         if (currentCell == numberOfCells) {           break;         }         moveRight();         currentCell++;       }     } else {       while (currentCell != numberOfCells) {         moveRight();         currentCell++;       }       while (currentCell >= 1) {         print(slogan[currentCell - 1]);         if (currentCell == 1) {           break;         }         moveLeft();         currentCell--;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = int(2e5);   const long double pi = 3.1415926535897932384626433832795;   char s[MaxN];   int main() {     while (gets(s)) {       int len = strlen(s);       int l = 0;       while (s[l] == 32) ++l;       int r = len - 1;       while (s[r] == 32) --r;       if (l > r) {         puts(  );         continue;       }       bool space = false;       bool znak = false;       for (int i = l; i <= r; i++) {         if (isalpha(s[i])) {           if (space && !znak)             printf(  %c , s[i]);           else             printf( %c , s[i]);           znak = false;           space = false;         }         if (s[i] ==  .  || s[i] ==  ,  || s[i] ==  !  || s[i] ==  ? )           printf( %c  , s[i]), znak = true;         if (s[i] == 32) space = true;       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k, n, m;       cin >> n;       map<long long int, long long int> mp, diff;       for (i = 0; i < n; i++) {         cin >> k;         if (mp.find(k) == mp.end())           mp[k] = i, diff[k] = 0;         else if (diff[k] == 0 || i - mp[k] == diff[k]) {           if (diff[k] == 0) diff[k] = i - mp[k];           mp[k] = i;         } else           diff[k] = -1;       }       set<pair<long long int, long long int> > ans;       for (auto i : diff)         if (i.second != -1) ans.insert(make_pair(i.first, i.second));       cout << ans.size() <<   n ;       for (auto i : ans) cout << i.first <<     << i.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 401;   const int MOD = 1000000007;   struct matr {     long long a[8][8];   };   matr d, f, e;   int n;   void make() {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) f.a[i][j] = d.a[i][j] = e.a[i][j] = 0;     d.a[0][1] = 1;     d.a[0][4] = 1;     d.a[1][0] = 1;     d.a[2][3] = 1;     d.a[2][6] = 1;     d.a[3][2] = 1;     d.a[4][5] = 1;     d.a[4][7] = 1;     d.a[5][1] = 1;     d.a[5][4] = 1;     d.a[6][5] = 1;     d.a[6][7] = 1;     d.a[7][3] = 1;     d.a[7][6] = 1;     for (int i = 0; i < 8; i++) f.a[0][i] = e.a[i][i] = 1;   }   void print(matr a) {     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) cout << a.a[i][j] <<    ;       cout << endl;     }   }   matr mul(matr a, matr b) {     matr c;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         c.a[i][j] = 0;         for (int z = 0; z < 8; z++) {           c.a[i][j] += a.a[i][z] * b.a[z][j];           if (c.a[i][j] >= MOD) c.a[i][j] %= MOD;         }       }     return c;   }   matr sum(matr a, matr b) {     matr c;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) c.a[i][j] = (a.a[i][j] + b.a[i][j]) % MOD;     return c;   }   matr sqr(matr a) { return mul(a, a); }   matr pow_(matr p, int n) {     if (n <= 1) return p;     if (n % 2 == 0) return sqr(pow_(p, n / 2));     return mul(p, sqr(pow_(p, n / 2)));   }   long long sum(matr a) {     long long ans = 0;     for (int i = 0; i < 8; i++) ans += a.a[0][i];     return ans;   }   long long solve_palin(int n) {     if (n == 1) return 4;     if (n == 2) return 4;     return sum(mul(f, pow_(d, n - 2)));   }   long long solve_one(int n) {     if (n == 1) return 4;     if (n == 2) return 4;     if (n % 2 == 0) return solve_palin(n) / 2;     return solve_palin(n) / 2 + solve_palin((n + 1) / 2);   }   matr clear(matr a) {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) a.a[i][j] = 0;     return a;   }   int log_(int n) {     int l = 0;     while ((1 << l) <= n) l++;     return l - 1;   }   int log_less(int n) {     int l = 0;     while ((1 << l) - 1 < n) l++;     return l - 1;   }   int step_2(int n) { return (1 << n); }   matr magic_func(int n) {     if (n == 0) return e;     if (n == 1) return sum(d, e);     matr ans;     ans = clear(ans);     int w = log_less(n);     ans = sum(d, e);     for (int i = 1; i < w; i++) ans = mul(ans, sum(pow_(d, step_2(i)), e));     return sum(ans, mul(pow_(d, step_2(w)), magic_func(n - step_2(w))));   }   long long solve(int n) {     if (n == 1) return 4;     matr ans;     ans = clear(ans);     n -= 2;     ans = magic_func(n);     return sum(mul(f, ans)) + 4;   }   long long real_ans(int n) { return solve(n) / 2 + solve((n + 1) / 2) / 2; }   int l, r;   int main() {     cin >> l >> r;     make();     if (r == 1) {       cout << 4;       return 0;     }     if (l == r) {       cout << solve_one(l) % MOD;       return 0;     }     long long razn = 0;     if (l == 1) {       razn = 4;       l++;     }     cout << ((real_ans(r) - real_ans(l - 1) + razn) % MOD + MOD) % MOD;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > v;   int x;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int arr[500001];   int tree[500001 * 5];   void init(int node, int b, int e) {     if (b == e) {       tree[node] = arr[b];       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     init(Left, b, mid);     init(Right, mid + 1, e);     tree[node] = gcd(tree[Left], tree[Right]);   }   void query(int node, int b, int e, int i, int j) {     if (i > e || j < b) return;     if (b >= i && e <= j) {       if (tree[node] % x != 0) v.push_back(make_pair(node, make_pair(b, e)));       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     query(Left, b, mid, i, j);     query(Right, mid + 1, e, i, j);   }   void update(int node, int b, int e, int i, int newvalue) {     if (i > e || i < b) return;     if (b >= i && e <= i) {       tree[node] = newvalue;       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     if (i <= mid)       update(Left, b, mid, i, newvalue);     else       update(Right, mid + 1, e, i, newvalue);     tree[node] = gcd(tree[Left], tree[Right]);   }   int rquery(int node, int b, int e) {     if (b == e) {       if (tree[node] % x == 0) return 0;       return 1;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     if (tree[Left] % x != 0 && tree[Right] % x != 0)       return 2;     else if (tree[Left] % x != 0)       return rquery(Left, b, mid);     else       return rquery(Right, mid + 1, e);   }   int main() {     int n;     scanf( %d , &n);     int i;     for (i = 1; i <= n; i++) scanf( %d , &arr[i]);     int q;     scanf( %d , &q);     int t, l, r;     init(1, 1, n);     int ans;     while (q--) {       v.clear();       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d , &l, &r, &x);         query(1, 1, n, l, r);         if (v.size() < 2) {           if (v.size() == 1) {             ans = rquery(v[0].first, v[0].second.first, v[0].second.second);             if (ans < 2)               cout <<  YES  << endl;             else               cout <<  NO  << endl;           } else             cout <<  YES  << endl;         } else           cout <<  NO  << endl;       } else {         scanf( %d%d , &l, &r);         update(1, 1, n, l, r);       }     }     return 0;   }
#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     register char c = getchar();     register bool f = 0;     while (!isdigit(c)) f ^= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   template <class T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void print(T x, char c) {     print(x), putchar(c);   }   const int N = 2e5 + 10;   int T, n, m, q, cur, max, lst, a[N], b[N];   long long ans;   std::set<int> set[N];   struct edge {     int l, r, x;     inline bool operator<(const edge &other) const { return l < other.l; }   } e[N];   signed main() {     read(n), read(q);     for (int i = 1; i <= n; i++) read(a[i]), b[++m] = a[i];     std::sort(b + 1, b + n + 1), m = std::unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) {       a[i] = std::lower_bound(b + 1, b + m + 1, a[i]) - b;       set[a[i]].insert(i);     }     for (int i = 1; i <= m; i++) {       e[i].l = *set[i].begin();       e[i].r = *--set[i].end();       e[i].x = set[i].size();     }     std::sort(e + 1, e + m + 1);     if (!q) {       lst = 0, cur = 0;       for (int i = 1; i <= m; i++) {         cur = std::max(cur, e[i].r);         if (i == m || e[i + 1].l > cur) {           max = 0;           for (int j = lst + 1; j <= i; j++) {             max = std::max(max, e[j].x);             ans += e[j].x;           }           ans -= max;           lst = i, cur = 0;         }       }       print(ans,   n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     int br = 0;     for (int i = 0; i < s.size() / 2; i++) {       if (s[i] == s[s.size() - i - 1]) continue;       br++;     }     if (br >= 2 || br == 0) {       if (s.size() % 2 == 1 && br == 0) {         cout <<  YES ;         return 0;       }       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }