malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       vector<int> ans;       int l = 0, r = n - 1, x = 0;       for (int i = n - 1; i >= 0; --i) {         int cur = (a[r] -  0 ) ^ x;         if (cur == (b[i] -  0 )) {           if (l < r)             --r;           else             ++r;           continue;         }         cur = (a[l] -  0 ) ^ x;         if (cur == (b[i] -  0 )) {           ans.push_back(1);         }         ans.push_back(i + 1);         x ^= 1;         swap(l, r);         if (l < r)           --r;         else           ++r;       }       cout << ans.size() <<    ;       for (auto i : ans) cout << i <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int N = 3e5 + 100;   const double PI = acos(-1.0);   void fre() {     freopen( /Users/luras/Desktop/in.txt ,  r , stdin);     freopen( /Users/luras/Desktop/out.txt ,  w , stdout);   }   int n, m, i, j, ans, p;   char s[N], ch;   int main() {     while (~scanf( %d%d , &n, &m)) {       scanf( %s , s + 1);       ans = 0;       for (i = 2; i <= n; i++) {         if (s[i] ==  .  && s[i - 1] ==  . ) ans++;       }       for (i = 1; i <= m; i++) {         scanf( %d %c , &p, &ch);         if ((s[p] ==  .  && ch ==  . ) || (s[p] !=  .  && ch !=  . )) {           printf( %d n , ans);           continue;         }         if (s[p] ==  . ) {           if (p == 1) {             if (s[p + 1] ==  . ) {               ans--;             }           } else {             if (s[p + 1] ==  . ) ans--;             if (s[p - 1] ==  . ) ans--;           }         } else {           if (p == 1) {             if (s[p + 1] ==  . ) ans++;           } else {             if (s[p + 1] ==  . ) ans++;             if (s[p - 1] ==  . ) ans++;           }         }         s[p] = ch;         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 3 * 100002;   int a[N], pr[N];   ll cnt[N];   map<int, int> s[N];   int main() {     int q;     cin >> q;     while (q--) {       ll ans = 0;       int n;       cin >> n;       for (int i = 0; i <= n; i++) {         pr[i] = -1;         s[i].clear();       }       for (int i = 1; i <= n; i++) {         cnt[i] = 0;         cin >> a[i];         if (i != 1) {           if (pr[i - 1] != -1) {             swap(s[i], s[pr[i - 1]]);             s[i][a[pr[i - 1] - 1]] = pr[i - 1] - 1;           }           if (s[i][a[i]])             pr[i] = s[i][a[i]];           else             pr[i] = -1;           if (a[i] == a[i - 1]) pr[i] = i - 1;         }         if (pr[i] != -1) cnt[i] = cnt[pr[i] - 1] + 1;         ans += cnt[i];       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using   namespace  std ;   using LL  =  long long ;      short int mark[500005] ;      class cmp{   public:        bool operator () (const pair<int, int> &p1, const pair<int, int> &p2){           return ((p1.first < p2.first) || (p1.first == p2.first && p1.second > p2.second)) ;       }   } ;      int main(){          ios_base::sync_with_stdio(false);       cin.tie(0);              int q ;       cin >>  q ;          int id = 0 ;       queue<int> a ;       priority_queue<pair<int, int> , vector<pair<int, int> > , cmp > b ;          for(int i = 1 ; i <= q ; i++){           int x ;           cin >> x ;              if(x == 1){               int m ;               cin >> m ;               a.push(++id) ;               b.push(make_pair(m, id)) ;           }           else if(x == 2){               while(mark[a.front()])                   a.pop() ;               cout << a.front() <<     ;               mark[a.front()] = 1 ;               a.pop() ;           }           else if(x == 3) {               while(mark[b.top().second])                   b.pop() ;               cout << b.top().second <<     ;               mark[b.top().second] = 1 ;               b.pop() ;           }       }       cout << endl ;          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     int k;     cin >> n >> k;     int ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     sort(ar, ar + n);     long long lista[n];     int cantidad[n];     int index = 0;     for (int i = 0; i < n; i++) {       if (i == 0) {         lista[i] = ar[i];         cantidad[index] = 1;       } else if (ar[i] == ar[i - 1]) {         cantidad[index]++;       } else {         index++;         cantidad[index] = 1;         lista[index] = ar[i];       }     }     int diferentes = index + 1;     long long L[diferentes];     long long R[diferentes];     int LeftAmount[diferentes];     int RightAmount[diferentes];     L[0] = 0;     LeftAmount[0] = 0;     R[diferentes - 1] = 0;     RightAmount[diferentes - 1] = 0;     for (int i = 1; i < diferentes; i++) {       LeftAmount[i] = LeftAmount[i - 1] + cantidad[i - 1];       L[i] = L[i - 1] + (lista[i] - 1 - lista[i - 1]) * cantidad[i - 1];       L[i] += (lista[i] - 1 - (lista[i - 1] - 1)) * LeftAmount[i - 1];     }     for (int i = diferentes - 2; i >= 0; i--) {       RightAmount[i] = RightAmount[i + 1] + cantidad[i + 1];       R[i] = R[i + 1] + (lista[i + 1] - (lista[i] + 1)) * cantidad[i + 1];       R[i] += (lista[i + 1] - lista[i]) * RightAmount[i + 1];     }     long long ans = 1000000000000000005;     for (int i = 0; i < diferentes; i++) {       if (cantidad[i] >= k) {         ans = 0;       } else {         int needed = k - cantidad[i];         if ((LeftAmount[i] >= needed) && (RightAmount[i] >= needed)) {           ans = min(min(L[i], R[i]) + needed, ans);         } else if (LeftAmount[i] >= needed) {           ans = min(L[i] + needed, ans);         } else if (RightAmount[i] >= needed) {           ans = min(R[i] + needed, ans);         } else {           ans = min(L[i] + R[i] + needed, ans);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       vector<vector<long long>> a(n, vector<long long>(3));       vector<long long> b(k);       vector<int> make_pair(n + 1);       for (int i = 0; i < n; ++i) {         cin >> a[i][0];         make_pair[a[i][0]] = i;         a[i][1] = i - 1;         a[i][2] = i < n - 1 ? i + 1 : -1;       }       vector<int> st(n + 1, false);       for (auto &i : b) {         cin >> i;         st[i] = true;       }       long long ans = 1;       for (long long i = 0; i < k; ++i) {         int pos = make_pair[b[i]];         int cnt = 0;         if (a[pos][1] != -1) {           int nbr = a[pos][1];           if (!st[a[nbr][0]]) cnt++;         }         if (a[pos][2] != -1) {           int nbr = a[pos][2];           if (!st[a[nbr][0]]) cnt++;         }         st[b[i]] = false;         int l = a[pos][1];         int r = a[pos][2];         if (l != -1) a[l][2] = r;         if (r != -1) a[r][1] = l;         if (!cnt) {           ans = 0;           break;         }         ans = (ans * cnt) % ((long long)(998244353));       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void bfs(long long root, list<long long> adj[], vector<long long> &level) {     level[root] = 0;     queue<long long> qu;     qu.push(root);     while (!qu.empty()) {       long long cur = qu.front();       qu.pop();       for (auto it : adj[cur]) {         if (level[it] == -1) {           level[it] = level[cur] + 1;           qu.push(it);         }       }     }   }   void solve() {     long long V, E, a, b;     cin >> V >> E;     list<long long> adj[V + 1];     vector<long long> level(V + 1, -1);     for (long long i = 0; i < E; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     bfs(1, adj, level);     map<long long, vector<long long> > mp;     for (int i = 1; i <= V; i++) {       mp[level[i]].push_back(i);     }     a = mp.size();     vector<long long> ans1, ans2;     for (int i = 0; i < a; i += 2) {       vector<long long> hold = mp[i];       for (auto it : hold) ans1.push_back(it);     }     for (int i = 1; i < a; i += 2) {       vector<long long> hold = mp[i];       for (auto it : hold) ans2.push_back(it);     }     if (ans1.size() < ans2.size()) {       cout << ans1.size() << endl;       for (auto it : ans1) cout << it <<    ;       cout << endl;     } else {       cout << ans2.size() << endl;       for (auto it : ans2) cout << it <<    ;       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q = 1;     cin >> q;     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     int n, c = 0;     char x;     vector<pair<int, int> > v;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x;         if (x ==  C ) {           v.push_back(make_pair(i, j));         }       }     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       for (int j = i + 1; j < v.size(); j++) {         if (v[i].first == v[j].first) c++;         if (v[i].second == v[j].second) c++;       }     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   const int kM = 4e4 + 5;   const int kN = 55;   int M, n, m, k;   long long T[kM << 3], tag[kM << 3], a[kN][kM], pre[kM], s[kM], f[kN][kM];   void Update(int cur) { T[cur] = std::max(T[cur << 1], T[cur << 1 | 1]); }   void PushTag(int cur) {     T[cur << 1] += tag[cur];     T[cur << 1 | 1] += tag[cur];     tag[cur << 1] += tag[cur];     tag[cur << 1 | 1] += tag[cur];     tag[cur] = 0;   }   void Build(int cur, int l, int r) {     if (l < r) {       int mid = (l + r) >> 1;       Build(cur << 1, l, mid);       Build(cur << 1 | 1, mid + 1, r);       Update(cur);     } else       T[cur] = s[l];   }   void Modify(int cur, int l, int r, int ql, int qr, long long v) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr)       T[cur] += v, tag[cur] += v;     else {       int mid = (l + r) >> 1;       PushTag(cur);       if (ql <= mid) Modify(cur << 1, l, mid, ql, qr, v);       if (qr > mid) Modify(cur << 1 | 1, mid + 1, r, ql, qr, v);       Update(cur);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]);     for (int i = 1; i <= m + k; ++i) pre[i] = pre[i - 1] + a[1][i];     for (int i = 1; i <= m; ++i) f[1][i] = pre[i + k - 1] - pre[i - 1];     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= m + k; ++j) pre[j] = pre[j - 1] + a[i][j];       for (int j = 1; j <= m; ++j)         s[j] = pre[j + k - 1] - pre[std::max(k, j - 1)] + f[i - 1][j];       memset(tag, 0, sizeof(tag));       Build(1, 1, m);       for (int j = 1; j <= m; ++j) {         f[i][j] = T[1] + pre[j + k - 1] - pre[j - 1];         Modify(1, 1, m, j - k + 1, j, a[i][j]);         Modify(1, 1, m, j + 1, j + k, -a[i][j + k]);       }     }     long long ans = 0;     for (int i = 1; i <= m; ++i) ans = std::max(ans, f[n][i]);     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, mxn = 2e5 + 5;   int n;   int a[200005];   int mp1[200005], mp2[200005];   map<int, int> mp;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     int ele, ma = 0;     for (auto ii : mp) {       if (ma < ii.second) {         ma = ii.second;         ele = ii.first;       }     }     int an = 0;     for (int i = 1; i <= 100; i++) {       if (ele == i) continue;       memset(mp1, -1, sizeof(mp1));       memset(mp2, -1, sizeof(mp2));       int su = 0;       mp1[0] = 0;       for (int j = 0; j < n; j++) {         if (a[j] == ele)           su++;         else if (a[j] == i)           su--;         if (su >= 0) {           if (mp1[su] != -1) {             int idx = mp1[su];             int tm = j + 1 - idx;             an = max(tm, an);           } else {             mp1[su] = j + 1;           }         } else {           if (mp2[-1 * su] != -1) {             int idx = mp2[-1 * su];             int tm = j + 1 - idx;             an = max(tm, an);           } else {             mp2[-1 * su] = j + 1;           }         }       }     }     cout << an;     return 0;   }
#include <bits/stdc++.h>   char str[4005] = {0};   long T[4005] = {0};   long f[4005][4005] = {0};   long s[4005][4005] = {0};   int main() {     long i, j, k;     long tot = 1;     long sum = 0;     scanf( %s , str + 1);     for (i = 1; str[i]; i++) {       if ((str[i] ==  *  || str[i] ==  / ) &&           (str[i - 1] >  9  || str[i - 1] <  0 )) {         printf( 0 n );         return 0;       }       if (str[i] >  9  || str[i] <  0 )         T[tot]++;       else if (str[i - 1] >  9  || str[i - 1] <  0 )         sum += T[tot++];     }     if (str[i - 1] >  9  || str[i - 1] <  0 ) {       printf( 0 n );       return 0;     }     tot--;     f[0][0] = 1;     s[0][0] = 1;     for (i = 1; i <= tot; i++) {       for (j = sum; j >= 0; j--) {         f[i][j] =             (f[i][j] + s[i - 1][((j - T[i]) > (0) ? (j - T[i]) : (0))]) % 1000003;         s[i][j] = (s[i][j + 1] + f[i][j]) % 1000003;       }     }     printf( %ld n , f[tot][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, dist[110][110];     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &dist[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           dist[j][k] = dist[j][k] > dist[j][i] + dist[i][k]                            ? dist[j][i] + dist[i][k]                            : dist[j][k];     int max = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) max = max > dist[i][j] ? max : dist[i][j];     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, x, y, z, ans2, ans;   int ans1[101];   int main() {     cin >> n >> m;     for (i = 1; i <= m; i++) {       y = -1;       for (j = 1; j <= n; j++) {         cin >> x;         if (x > y) {           y = x;           z = j;         }       }       ans1[z]++;     }     for (i = 1; i <= 101; i++) {       if (ans1[i] > ans2) {         ans2 = ans1[i];         ans = i;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v, w, id;   } e[500001];   int f[500001], last[500001];   int Left[500001];   struct que {     int x, y, next;   } q[1000001];   int head[500001];   int cnt;   void init() {     cnt = 0;     memset(head, -1, sizeof(head));   }   void add_edge(int w, int i, int id) {     q[cnt].x = i;     q[cnt].y = id;     q[cnt].next = head[w];     head[w] = cnt++;   }   int fa[500001];   int stid[500001 << 3], stfa[500001 << 3], top = 0;   bool cmp(edge a, edge b) {     if (a.w == b.w) return a.id < b.id;     return a.w < b.w;   }   int Find(int u) {     if (u == fa[u]) {       return u;     } else {       int v = Find(fa[u]);       ++top;       stid[top] = u, stfa[top] = fa[u];       fa[u] = v;       return v;     }   }   bool add(int id) {     int u = e[id].u, v = e[id].v;     u = Find(u), v = Find(v);     if (u == v) return false;     ++top;     stid[top] = u, stfa[top] = fa[u];     fa[u] = v;     return true;   }   void back(int ret) {     while (top > ret) {       fa[stid[top]] = stfa[top];       top--;     }   }   int main() {     init();     int n, m, Q;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       e[i].id = i;     }     sort(e + 1, e + 1 + m, cmp);     for (int i = 1; i <= m; i++) f[e[i].id] = i;     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int qn;       scanf( %d , &qn);       for (int j = 1; j <= qn; j++) {         int id;         scanf( %d , &id);         id = f[id];         if (last[e[id].w] != i) {           last[e[id].w] = i;           Left[i]++;         }         add_edge(e[id].w, i, id);       }     }     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       if (e[i].w != e[i - 1].w) {         int w = e[i].w;         int rec = top;         for (int j = head[w]; ~j; j = q[j].next) {           bool ok = true;           while (q[j].next != -1 && q[j].x == q[q[j].next].x) {             ok &= add(q[j].y);             j = q[j].next;           }           ok &= add(q[j].y);           if (ok) {             Left[q[j].x]--;           }           back(rec);         }       }       for (; e[i].w == e[i + 1].w; i++) {         add(i);       }       add(i);     }     for (int i = 1; i <= Q; i++) {       if (!Left[i])         printf( YES n );       else         printf( NO n );     }   }
#include <bits/stdc++.h>   inline int read() {     int x;     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     for (x = c -  0 ; (c = getchar()) >=  0  && c <=  9 ;) x = x * 10 + c -  0 ;     return x;   }   int a[100000 + 5];   void solve(int n) {     for (int i = 20, x; i; --i)       if (n & (1 << i)) {         x = ((1 << i + 1) - 1) ^ n;         if (x > 1) solve(x - 1);         while (n >= x) printf( %d  , n--);         return;       }   }   int main() {     int n = read(), i;     if (n & 1)       puts( NO );     else       puts( YES ), solve(n), puts(  );     if (n < 6 || n == (n & -n))       puts( NO );     else {       puts( YES );       a[1] = 3;       a[2] = 6;       a[3] = 2;       a[4] = 5;       a[5] = 1;       a[6] = 4;       for (i = 7; i <= n; ++i)         if (i == (i & -i))           a[i] = i + 1, a[i + 1] = i, ++i;         else           a[i] = a[i & -i], a[i & -i] = i;       for (i = 1; i <= n; ++i) printf( %d  , a[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   double cp(const complex<double> &a, const complex<double> &b) {     return a.real() * b.imag() - b.real() * a.imag();   }   inline complex<double> line_inter(const complex<double> &a,                                     const complex<double> &b,                                     const complex<double> &c,                                     const complex<double> &d) {     return a + cp(c - a, d - c) / cp(b - a, d - c) * (b - a);   }   inline double lp_dist(const complex<double> &a, const complex<double> &b,                         const complex<double> &p) {     return cp(b - a, p - a) / abs(b - a);   }   int main() {     int y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     yw -= r;     y1 += r;     y2 -= r;     if (y1 == y2)       cout << -1 << endl;     else {       double cc = yw + (yw - (y1 + 0.00001));       complex<double> a(0, cc), b(xb, yb), c(0, yw), d(xb, yw);       complex<double> e(0, yw + yw - (y2 + r));       if (lp_dist(b, a, e) <= r)         cout << -1 << endl;       else {         complex<double> s = line_inter(a, b, c, d);         cout << fixed << setprecision(12) << s.real() << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int read(T& x) {     x = 0;     char c = getchar(), f = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       if (c == -1) return -1;       c = getchar();     }     while (c <=  9  && c >=  0 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     x *= f;     return 1;   }   template <typename T, typename... Args>   inline int read(T& x, Args&... args) {     return read(x) + read(args...);   }   template <typename T>   inline int write(T x) {     if (x < 0) return putchar( - ) & write((~x) + 1);     if (x / 10) return write(x / 10) & putchar(x % 10 | 48);     return putchar(x | 48);   }   template <typename T>   inline int write(T x, char c) {     return write(x) + putchar(c);   }   int n, m;   struct edge {     int u, v, nxt;   } e[1000005 << 1];   int f[1000005], tot = 1;   inline void addEdge(int u, int v) {     tot++, e[tot].u = u, e[tot].v = v, e[tot].nxt = f[u], f[u] = tot;   }   int dfn[1000005], low[1000005], idx;   int bel[1000005], siz[1000005], scc;   bool ins[1000005];   int sta[1000005], tp;   inline void tarjan(int x, int fa) {     dfn[x] = low[x] = ++idx;     sta[++tp] = x;     ins[x] = 1;     for (int i = f[x]; i; i = e[i].nxt) {       int v = e[i].v;       if (!dfn[v]) {         tarjan(v, x);         low[x] = ((low[x]) < (low[v]) ? (low[x]) : (low[v]));       } else if (ins[v])         low[x] = ((low[x]) < (dfn[v]) ? (low[x]) : (dfn[v]));     }     if (dfn[x] == low[x]) {       int v;       scc++;       do {         v = sta[tp--];         bel[v] = scc;         siz[scc]++;         ins[v] = 0;       } while (v != x);     }   }   signed main() {     int t;     read(t);     while (t--) {       read(n, m);       tot = idx = scc = 0;       for (int i = 1; i <= n; i++) bel[i] = dfn[i] = low[i] = f[i] = siz[i] = 0;       for (int i = 1; i <= m; i++) {         int u, v;         read(u, v);         if (u != v) addEdge(u, v);       }       for (int i = 1; i <= n; i++)         if (!dfn[i]) tarjan(i, -1);       if (scc == 1) {         puts( No );         continue;       }       puts( Yes );       write(siz[1],    ), write(n - siz[1],   n );       for (int i = 1; i <= n; i++)         if (bel[i] == 1) write(i,    );       putchar(10);       for (int i = 1; i <= n; i++)         if (bel[i] != 1) write(i,    );       putchar(10);     }   }