malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long pow(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T x, T y) {     for (T t; x; t = x, x = y % x, y = t)       ;     return y;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     Graph() { adj.clear(); }     void resize(int n) { adj.resize(n + 5); }     void add(int s, edge e) { adj[s].push_back(e); }     void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }     vector<edge> &operator[](int t) { return adj[t]; }   };   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     if (m == 3) {       if (n == 3) {         cout <<  0 0  << endl <<  1 1  << endl <<  1 0  << endl;       } else if (n == 4) {         cout <<  0 0  << endl              <<  0 1  << endl              <<  -1 -1  << endl              <<  1 -1  << endl;       } else {         cout << -1 << endl;       }       return 0;     }     const int X = 1e7;     for (int i = 1; i <= m; ++i) {       cout << i <<     << +(X + i * i) << endl;     }     for (int i = 1; i <= n - m; ++i) {       cout << i <<     << -(X + i * i) << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <typename T>   bool mycomp(T x, T y) {     return (x == y);   }   bool paircomp(const pair<long long int, long long int> &x,                 const pair<long long int, long long int> &y) {     return x.second < y.second;   }   long long int f[6][6];   void solve() {     long long int m;     cin >> m;     for (long long int i = 0; i < m; i++) {       long long int x, y;       cin >> x >> y;       f[x][y] = 1;       f[y][x] = 1;     }     for (long long int i = 1; i <= 5; i++) {       for (long long int j = i + 1; j <= 5; j++) {         for (long long int k = j + 1; k <= 5; k++) {           if (f[i][j] && f[i][k] && f[j][k]) {             cout <<  WIN ;             return;           }           if (!f[i][j] && !f[i][k] && !f[j][k]) {             cout <<  WIN n ;             return;           }         }       }     }     cout <<  FAIL ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       solve();       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using vc = vector<T>;   using pii = pair<long long, long long>;   void xmax(long long& a, long long b) { a = max(a, b); }   void xmin(long long& a, long long b) { a = min(a, b); }   void print(vc<long long>& a, string second) {     cerr << second <<   :  ;     for (long long i = 0; i < a.size(); i++) {       cerr << a[i] <<    ;     }     cerr << endl;   }   long long dist(pii a, pii b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   long long find_min(vc<pii> p) {     if (p.size() == 1) return 1e18;     if (p.size() == 2) {       return dist(p[0], p[1]);     }     long long n = p.size();     long long mid = (p[0].first + p[n - 1].first) / 2;     vc<pii> ri;     vc<pii> le;     for (long long i = 0; i < n; i++) {       if (p[i].first <= mid)         le.push_back(p[i]);       else         ri.push_back(p[i]);     }     long long mini = 1e18;     xmin(mini, find_min(le));     xmin(mini, find_min(ri));     vc<pii> cut;     long double delta = sqrt(mini) + 1;     for (long long i = 0; i < le.size(); i++) {       if (abs(mid - le[i].first) <= delta)         cut.push_back({le[i].second, le[i].first});     }     for (long long i = 0; i < ri.size(); i++) {       if (abs(mid - ri[i].first) <= delta)         cut.push_back({ri[i].second, ri[i].first});     }     sort(cut.begin(), cut.end());     for (long long i = 0; i < cut.size(); i++) {       for (long long j = 1; j < 20 && i + j < cut.size(); j++) {         xmin(mini, dist(cut[i], cut[i + j]));       }     }     return mini;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vc<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     vc<long long> p(n);     for (long long i = 1; i < n; i++) {       p[i] = p[i - 1] + a[i];     }     vc<pair<long long, long long> > st(n);     for (long long i = 0; i < n; i++) {       st[i] = {i, p[i]};     }     long long res = find_min(st);     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   inline void sfr(int *a) {     char c = 0;     while (c < 33) c = fgetc(stdin);     *a = 0;     while (c > 33) {       *a = *a * 10 + c -  0 ;       c = fgetc(stdin);     }   }   inline void sfp(int a) {     char c[1000];     sprintf(c,  %d , a);     puts(c);   }   int main() {     int n;     cin >> n;     ;     int m;     cin >> m;     ;     int A[n][m];     getchar();     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char c =   n ;         while (c ==   n ) c = getchar();         A[i][j] = (c ==  1 );       }     }     int B[n];     int mx = 0;     for (int i = n - 1; i >= 0; i--) B[i] = 0;     for (int i = m - 1; i >= 0; i--) {       vector<int> D;       for (int j = 0; j < n; j++) {         if (A[j][i]) {           B[j] = B[j] + 1;           D.push_back(B[j]);         } else {           B[j] = 0;           D.push_back(0);         }       }       sort(D.begin(), D.end());       for (int j = 0; j < n; j++) mx = max(mx, D[j] * (n - j));     }     cout << mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, dir[200005];   long long cnt, le;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &dir[i]);       if (dir[i] == 0) le++;     }     for (int i = 0; i < n; i++) {       if (dir[i] == 1)         cnt += le;       else         le--;     }     printf( %I64d , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 2e5 + 6;   const long long int inf = 2e18 + 1;   long long int a[maxn];   int main() {     long long int n, k;     cin >> n >> k;     long long int next[n];     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     next[n - 1] = n;     for (long long int i = n - 2; i >= 0; i--) {       if (a[i + 1] != 1) {         next[i] = i + 1;       } else {         next[i] = next[i + 1];       }     }     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       if (k == 1) {         ans++;       }       long long int r = i;       long long int mul = a[i];       long long int sum = a[i];       while (next[r] != n && a[next[r]] <= inf / mul) {         mul = mul * a[next[r]];         sum = sum + next[r] - r - 1 + a[next[r]];         r = next[r];         long long int check = -1;         if (mul % k == 0) {           check = mul / k;         }         long long int store = next[r] - r - 1;         if (check >= sum && check <= sum + store) {           ans = ans + 1;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long T, W, B, H, P;   long long fpb(long long A, long long B) {     if (A == 0) {       return B;     }     return fpb(B % A, A);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> T >> W >> B;     H = W / fpb(W, B);     if (T / B < H) {       P = min(W, B) - 1 - max((long long)0, min(W, B) - 1 - T);     } else {       H *= B;       P = (T / H + 1) * min(W, B) - 1 - max((long long)0, min(W, B) - 1 - T % H);     }     H = fpb(P, T);     cout << P / H <<  /  << T / H <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct type {     int a, b;   } b[17];   int p[17];   int a[17];   int ans[101];   bitset<2001> f[65536];   int n, K, L, i, j, k, l, sum, len, s, tot;   bool cmp(type a, type b) { return a.b > b.b; }   int main() {     p[1] = 1;     for (i = 2; i <= 16; i++) p[i] = p[i - 1] << 1;     scanf( %d%d , &n, &K);     L = (p[n] << 1) - 1;     for (i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i];     sum /= K;     f[0][0] = 1;     for (i = 1; i <= L; i++) {       for (j = 1; j <= n; j++)         if (i & p[j]) f[i] |= f[i ^ p[j]] << a[j];       for (j = sum; j >= 1; j--)         if (f[i][j * K]) f[i][j] = 1;     }     if (!f[L][1])       printf( NO n );     else {       printf( YES n );       s = L;       j = 1;       while (j) {         if (j <= sum && f[s][j * K]) {           j *= K;           ans[++len] = -1;           continue;         }         for (i = 1; i <= n; i++)           if (s & p[i] && j >= a[i] && f[s - p[i]][j - a[i]]) {             s -= p[i];             j -= a[i];             ans[++len] = i;             break;           }       }       j = 0;       for (i = 1; i <= len; i++)         if (ans[i] == -1)           ++j;         else           b[++tot] = {a[ans[i]], -j};       while (tot > 1) {         sort(b + 1, b + tot + 1, cmp);         printf( %d %d n , b[tot - 1].a, b[tot].a);         b[tot - 1].a += b[tot].a;         --tot;         while (!(b[tot].a % K)) b[tot].a /= K, ++b[tot].b;       }     }   }
#include <bits/stdc++.h>   const int N = 209, MOD = 1000000007;   long long f[N][N], area[N][N];   struct point {     long long x, y;     point(const long long _x = 0, const long long _y = 0) : x(_x), y(_y) {}   } p[N];   int n;   inline int sign(long long x) { return x < 0 ? -1 : x > 0; }   inline long long cpr(const point &a, const point &b, const point &c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   inline bool cross(point &u, point &v, point &a, point &b) {     if (std::max(u.x, v.x) < std::min(a.x, b.x) ||         std::min(u.x, v.x) > std::max(a.x, b.x))       return false;     if (std::max(u.y, v.y) < std::min(a.x, b.y) ||         std::min(u.y, v.y) > std::max(a.y, b.y))       return false;     if (sign(cpr(u, v, a)) * sign(cpr(u, v, b)) <= 0 &&         sign(cpr(a, b, u)) * sign(cpr(a, b, v)) <= 0)       return true;     return false;   }   bool check(int i, int j) {     if (i + 1 == j || i == 1 && j == n) return true;     if (sign(cpr(p[i], p[j], p[i + 1])) * sign(cpr(p[i], p[j], p[i - 1])) > 0)       return false;     for (int k = 1; k <= n; ++k)       if (k != i && k % n + 1 != i && k != j && k % n + 1 != j) {         if (cross(p[i], p[j], p[k], p[k + 1])) return false;       } else if (!cpr(p[i], p[j], p[(k == i || k == j) ? k + 1 : k]))         return false;     return true;   }   long long F(int i, int j) {     if (f[i][j] != -1) return f[i][j];     if (i + 1 == j) return 1;     f[i][j] = 0;     for (int k = i + 1; k < j; ++k)       if (cpr(p[i], p[j], p[k]) > 0) f[i][j] += F(i, k) * F(k, j) % MOD;     f[i][j] %= MOD;     return f[i][j];   }   int main() {     memset(f, -1, sizeof f);     scanf( %d , &n);     long long S = 0;     for (int i = 1; i <= n; ++i) scanf( %I64d%I64d , &p[i].x, &p[i].y);     p[n + 1] = p[1];     p[0] = p[n];     for (int i = 1; i <= n; ++i) S += cpr(point(0, 0), p[i], p[i + 1]);     if (S > 0) std::reverse(p + 1, p + 1 + n);     p[n + 1] = p[1];     p[0] = p[n];     printf( %I64d n , F(1, n));   }
#include <bits/stdc++.h>   int main(void) {     int n;     scanf( %d , &n);     while (1) {       if (n % 2 == 1) {         int atk = n - 1;         n = n - atk;       } else if (n % 2 == 0) {         printf( Mahmoud n );         break;       }       if (n % 2 == 1) {         printf( Ehab n );         break;       } else {         int atk2 = n - 1;         n = n - atk2;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353, INF = 1e9;   const long long N = 2e5 + 1;   const double ep = 1e-10;   const double pi = 3.141592653589793238;   void floyd() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     long long a1 = 0, a2 = 0, k = 0, ans = INF, in = -1, in2 = -1;     for (long long i = 0; i < n; i++) {       if (a[i] ==  1 ) a1++;       if (b[i] ==  1 ) a2++;       if (a[i] ==  1  && b[i] ==  0 ) {         k++;         in2 = i;       }       if (a[i] ==  1  && b[i] ==  1 ) {         in = i;       }     }     if (a1 != a2 && (n - a1 + 1) != a2) {       cout << -1 <<   n ;       return;     }     if (a1 == a2) {       ans = min(k * 2, INF);     }     string t = a;     for (long long i = 0; i < n; i++) {       if (a[i] ==  1 )         a[i] =  0 ;       else         a[i] =  1 ;     }     if (in != -1) {       a[in] =  1 ;       long long k1 = 0, k2 = 0, k3 = 0, d = INF;       for (long long i = 0; i < n; i++) {         if (a[i] ==  1 ) k1++;         if (b[i] ==  1 ) k2++;         if (a[i] ==  1  && b[i] ==  0 ) {           k3++;         }       }       if (k1 == k2) {         d = k3 * 2 + 1;       }       ans = min(ans, d);     }     for (long long i = 0; i < n; i++) {       if (t[i] ==  1 )         t[i] =  0 ;       else         t[i] =  1 ;     }     if (in2 != -1) {       t[in2] =  1 ;       long long k1 = 0, k2 = 0, k3 = 0, d = INF;       for (long long i = 0; i < n; i++) {         if (t[i] ==  1 ) k1++;         if (b[i] ==  1 ) k2++;         if (t[i] ==  1  && b[i] ==  0 ) {           k3++;         }       }       if (k1 == k2) {         d = k3 * 2 + 1;       }       ans = min(ans, d);     }     if (ans == INF) {       cout << -1 <<   n ;       return;     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       floyd();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } h[(200000 + 5)];   int ql, qr;   namespace Seg_tree {   int hn, hv[(15000000 + 5)], ch[(15000000 + 5)][2];   void Modify(int &o, int L, int R, int p) {     if (!o) o = ++hn;     if (L == R) {       ++hv[o];       return;     }     if (p <= ((L + R) >> 1))       Modify(ch[o][0], L, ((L + R) >> 1), p);     else       Modify(ch[o][1], ((L + R) >> 1) + 1, R, p);     hv[o] = hv[ch[o][0]] + hv[ch[o][1]];   }   int Query(int &o, int L, int R) {     if (!o) return 0;     if (ql <= L && qr >= R) return hv[o];     int ret = 0;     if (ql <= ((L + R) >> 1)) ret += Query(ch[o][0], L, ((L + R) >> 1));     if (qr > ((L + R) >> 1)) ret += Query(ch[o][1], ((L + R) >> 1) + 1, R);     return ret;   }   };  // namespace Seg_tree   using namespace Seg_tree;   int n, ml[(200000 + 5)], mr[(200000 + 5)], mc[(200000 + 5)], rt[(200000 + 5)];   inline int lowbit(int x) { return x & (-x); }   void Add(int x, int y) {     while (x <= (n << 1)) {       Modify(rt[x], 1, (n << 1), y);       x += lowbit(x);     }   }   int Sum(int x) {     int ret = 0;     while (x > 0) {       ret += Query(rt[x], 1, n << 1);       x -= lowbit(x);     }     return ret;   }   int Qus(int l1, int r1, int l2, int r2) {     if (l1 > r1 || l2 > r2) return 0;     ql = l2;     qr = r2;     return Sum(r1) - Sum(l1 - 1);   }   void Init() {     for (int i = (1); i <= (int)(n); ++i) Add(h[i].l, h[i].r);     for (int i = (1); i <= (int)(n); ++i) {       ml[i] = Qus(h[i].l + 1, h[i].r - 1, h[i].l + 1, h[i].r - 1);       mc[i] = Qus(1, h[i].l - 1, h[i].l + 1, h[i].r - 1) +               Qus(h[i].l + 1, h[i].r - 1, h[i].r + 1, n << 1);       mr[i] = n - 1 - ml[i] - mc[i];     }   }   int Calc(node a, int v) {     if (v > a.l && v < a.r) return true;     return false;   }   bool Cross(node a, node b) {     int t1 = Calc(a, b.l), t2 = Calc(a, b.r);     return t1 ^ t2;   }   bool Check(node me, node a, node b) {     int ta = Calc(me, a.l), tb = Calc(me, b.l);     return ta == tb;   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (int)(n); ++i) {       scanf( %d%d , &h[i].l, &h[i].r);       if (h[i].l > h[i].r) swap(h[i].l, h[i].r);     }     if (n < 3) {       puts( 0 );       return 0;     }     if (n > 10000)       Init();     else {       for (int i = (1); i <= (int)(n); ++i)         for (int j = (1); j <= (int)(n); ++j)           if (i != j) {             if (Cross(h[i], h[j]))               ++mc[i];             else {               if (Calc(h[i], h[j].l))                 ++ml[i];               else                 ++mr[i];             }           }     }     long long ans = 1ll * n * (n - 1) * (n - 2) / 6;     for (int i = (1); i <= (int)(n); ++i) ans -= 1ll * ml[i] * mr[i];     long long cnt = 0;     for (int i = (1); i <= (int)(n); ++i) cnt += 1ll * mc[i] * (ml[i] + mr[i]);     cnt /= 2;     ans -= cnt;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   namespace std {   long long abs(long long x) { return x < 0 ? -x : x; }   }  // namespace std   using namespace std;   void dprintf(char* format, ...) {     fprintf(stderr,  DEBUG:  );     va_list argp;     va_start(argp, format);     vfprintf(stderr, format, argp);     va_end(argp);     fprintf(stderr,   n );   }   struct Exception {     const char* message;     const int line;     Exception(const char* m, int l) : message(m), line(l) {}   };   static char stringReader[2097152];   static inline bool ReadLine() {     char* ptr = fgets(stringReader, sizeof(stringReader), stdin);     if (ptr == 0) return false;     int N = strlen(stringReader);     if (stringReader[N - 1] ==   n ) stringReader[N - 1] = 0;     return true;   }   const long long ooLL = 0x3f3f3f3f3f3f3f3fLL;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   int main() {     try {       int N;       scanf( %d , &N);       int nt = 0;       int sol = oo;       vector<int> cnt(2 * N + 1, 0);       char t[1024];       scanf( %s , t);       for (int i = 0; i < N; ++i) {         if (t[i] ==  T ) {           ++nt;           cnt[i + 1] = cnt[i + N + 1] = 1;         }       }       for (int i = 1; i <= 2 * N; ++i) {         cnt[i] += cnt[i - 1];       }       int nh = N - nt;       for (int i = 1; i <= N; ++i) {         int have = cnt[i + nt - 1] - cnt[i - 1];         sol = min(sol, nt - have);       }       printf( %d n , sol);       return 0;     } catch (const Exception& exception) {       fprintf(stderr,  ****************************** n );       fprintf(stderr,  ERROR.%d: %s n , exception.line, exception.message);       fprintf(stderr,  ****************************** n );       throw exception;     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[200000 + 10];   int arr2[200000 + 10];   int main() {     int n, num1 = 0, num2 = 0, tem1, l1 = 0, l2 = 0, num = 0;     long long ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tem1;       if (tem1 == 0) {         ans += num;       } else         num++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     char T;     string a[100];     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < a[i].size(); j++) {         if (i % 2 == 0) {           if (j % 2 == 0) {             T =  B ;           } else {             T =  W ;           }         } else {           if (j % 2 == 0) {             T =  W ;           } else {             T =  B ;           }         }         if (a[i][j] ==  . ) {           a[i][j] = T;         } else {           a[i][j] =  - ;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, c, d, p, nl, np, a, b, f, mina;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     a = (l * k) / nl;     b = (c * d);     f = p / np;     if (a < b)       mina = a;     else       mina = b;     if (mina > f) mina = f;     cout << (mina / n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[10];   int n;   int cnt[10], sump;   vector<long long> tree;   int rec(int cur, int trees, int treessum) {     if (cur > n) return treessum + (trees > 1) + n - sump;     int ans = (int)1e9;     for (int i = 0; i < tree.size(); ++i)       if (tree[i] % a[cur] == 0) {         tree[i] /= a[cur];         tree.push_back(a[cur]);         ans = min(ans, rec(cur + 1, trees + (!i), treessum + (!i) * cnt[cur]));         tree[i] *= a[cur];         tree.pop_back();       }     return ans;   }   bool cmp(long long a, long long b) { return a > b; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , a + i);     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; ++i) {       long long x = a[i];       for (int j = 2; 1ll * j * j <= x; ++j)         while (x % j == 0) {           ++cnt[i];           x /= j;         }       if (x > 1) ++cnt[i];       if (cnt[i] == 1) ++sump;     }     tree.push_back(0);     printf( %d n , rec(1, 0, 0));     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1LL << 62LL;   const long double EPS = 1e-9;   const int SIZE = 200010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   int flag, u[SIZE], d[SIZE], a[SIZE], n;   int rec(int i) {     if (i == n - 1) return 1;     if (u[i] == flag) return d[i];     u[i] = flag;     if (a[i] == 1) {       return d[i] = !rec(i + 1);     }     return d[i] = 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     for (int rep_iter = 0; rep_iter < tt; ++rep_iter) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       int l = 0, r = n - 1, inv = 0;       for (auto& i : a) i -=  0 ;       for (auto& i : b) i -=  0 ;       vector<int> ans;       for (int len = n; len >= 1; --len) {         if ((a[r] ^ inv) != b[len - 1]) {           if ((a[l] ^ inv) == b[len - 1]) {             ans.push_back(1);             a[l] = !a[l];           }           ans.push_back(len);           inv = !inv;           swap(r, l);         }         if (r >= l)           --r;         else           ++r;       }       cout << ans.size() <<    ;       for (auto& i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int A[n][m], row[n], col[m];     char c;     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> c;         if (c ==  . )           A[i][j] = 0;         else           A[i][j] = 1;       }     }     for (int i = 0; i < n; ++i) {       if (row[i] == 0) {         for (int j = 0; j < m; ++j) {           if (A[i][j] == 1 && col[j]) {             cout <<  No  << endl;             return 0;           }         }         vector<int> X;         for (int j = i + 1; j < n; ++j) {           int ans = 1;           if (row[j]) continue;           for (int k = 0; k < m; ++k) {             if (A[i][k] != A[j][k]) {               ans = 0;               break;             }           }           if (ans == 1) X.push_back(j);         }         for (int j = 0; j < X.size(); ++j) row[X[j]] = 1;         for (int j = 0; j < m; ++j)           if (A[i][j]) col[j] = 1;       }     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100007;   int n, m, q[N], a[N], mn = 100000007, k, l;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q[i];       mn = min(mn, q[i]);     }     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       k += a[i];       l++;       if (l == mn) {         l = 0;         if (i == 1)           i--;         else if (i >= 2)           i -= 2;       }     }     cout << k;     return 0;   }