malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mod(long long x) {     return ((x % 1000000007 + 1000000007) % 1000000007);   }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   template <class T>   void print(T a) {     cerr << a;   }   template <class T, class V>   void print(pair<T, V> p);   template <class T>   void print(vector<T> v);   template <class T>   void print(set<T> v);   template <class T, class V>   void print(map<T, V> v);   template <class T>   void print(multiset<T> v);   template <class T, class V>   void print(pair<T, V> p) {     cerr <<  { ;     print(p.first);     cerr <<  , ;     print(p.second);     cerr <<  } ;   }   template <class T>   void print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T>   void print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T>   void print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T, class V>   void print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   long long modPow(long long a, long long b) {     if (b == 0) return 1LL;     if (b == 1) return a % 1000000007;     long long res = 1;     while (b) {       if (b % 2 == 1) res = mul(res, a);       a = mul(a, a);       b = b / 2;     }     return res;   }   const long long N = 2e5 + 2;   long long fact[N];   void precalc() {     fact[0] = 1;     for (long long i = 1; i < N; i++) {       fact[i] = mul(fact[i - 1], i);     }   }   long long inv(long long x) { return modPow(x, 1000000007 - 2); }   long long divide(long long a, long long b) { return mul(a, inv(b)); }   long long nCr(long long n, long long r) {     return divide(fact[n], mul(fact[r], fact[n - r]));   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) {         if ((i + 1) <= n / 2) {           cout << i + 1 <<     << n <<     << i + 2 <<     << n << endl;           return;         } else {           cout << 1 <<     << i + 1 <<     << 1 <<     << i << endl;           return;         }       }     }     cout << 1 <<     << n - 1 <<     << 2 <<     << n << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 9e18;   void __print(long long int x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void tc() {     long long int n;     cin >> n;     string a, b;     cin >> a >> b;     for (long long int i = 0; i < n; i++) {       if (a[i] > b[i]) {         cout << -1 << endl;         return;       }     }     long long int ans = 0;     for (char ch =  a ; ch <=  z ; ch++) {       set<long long int> idx;       char mini =  z ;       for (long long int i = 0; i < n; i++) {         if (a[i] == ch && a[i] != b[i]) {           idx.insert(i);           mini = min(mini, b[i]);         }       }       bool done = false;       for (auto it = idx.begin(); it != idx.end(); it++) {         a[(*it)] = mini;         done = true;       }       if (done) {         ans++;       }     };     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       tc();     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   char S[100005];   int main() {     scanf( %d , &N);     scanf( %s , S);     string ANS =   ;     int a = (N - 11) / 2, b = a;     for (int i = 0; i < N; i++) {       if (S[i] ==  8 ) {         if (a)           --a;         else           ANS += S[i];       } else {         if (b)           --b;         else           ANS += S[i];       }     }     if (ANS[0] ==  8 )       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (T &i : arr) {       in >> i;     }     return in;   }   template <class T>   ostream &operator<<(ostream &in, vector<T> &arr) {     for (T &i : arr) {       in << i <<    ;     }     return in;   }   long long debb = 1;   long long next(vector<long long> &t) {     long long c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]);     long long u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2]));     long long su = c + u;     t[2] += 1;     c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]);     u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2]));     long long su1 = c + u;     t[2] -= 1;     return su - su1;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     long long co = k - n;     multiset<vector<long long>, greater<vector<long long>>> u;     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       vector<long long> k = {x, x, 1};       long long ra = next(k);       u.insert({ra, x, x, 1});     }     for (int i = 0; i < co; ++i) {       vector<long long> r = *(u.begin());       u.erase(u.begin());       vector<long long> o = {r[1], r[2], r[3]};       o[2] += 1;       o[0] = o[1] / o[2] + min(o[1] % o[2], 1ll);       long long ra = next(o);       u.insert({ra, o[0], o[1], o[2]});     }     long long ans = 0;     for (auto r : u) {       vector<long long> t = {r[1], r[2], r[3]};       for (int i = 0; i < t[2]; ++i) {         long long c = t[1] / t[2] + max(min(t[1] % t[2] - i, 1ll), 0ll);         ans += c * c;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans, up, top;   unsigned long long k;   unsigned long long st[201], ed[201], sum[201], num[201];   int s[300010];   inline void init() {     unsigned long long mi = 1;     st[0] = 0;     ed[0] = 0;     for (int i = 1; i <= 64; i++) {       st[i] = ed[i - 1] + i;       num[i] = ((mi * 10 - 1) - mi + 1);       ed[i] = st[i] + i * (num[i] - 1);       sum[i] = sum[i - 1] + (st[i] + ed[i]) * num[i] / 2;       up = i;       if (sum[i] >= 1e18) break;       mi *= 10;     }   }   inline void prework() { scanf( %lld , &k); }   inline int findans(unsigned long long x, int pos) {     top = 0;     while (x > 0) {       s[++top] = x % 10;       x /= 10;     }     return s[top - pos + 1];   }   inline void mainwork() {     unsigned long long mi = 1, id;     for (int i = 1; i <= up; i++) {       if (sum[i] >= k) {         id = i;         break;       }       mi *= 10;     }     k -= sum[id - 1];     unsigned long long l = 0, r = num[id] - 1, mid;     unsigned long long t, d;     while (l + 1 < r) {       mid = (l + r) >> 1;       t = (st[id] + id * (mid - 1) + st[id]) * mid / 2;       if (t < k)         l = mid;       else         r = mid;     }     if ((st[id] + id * (r - 1) + st[id]) * r / 2 < k)       d = r;     else       d = r - 1;     k -= (st[id] + id * (d - 1) + st[id]) * d / 2;     unsigned long long len = st[id] + d, sum = 0;     for (int i = 1; i <= up; i++) {       if (k <= num[i] * i) {         id = i;         break;       }       k -= num[i] * i;       sum += num[i];     }     unsigned long long val = k / id;     if (k % id == 0)       ans = findans(val + sum, id);     else       ans = findans(val + sum + 1, k % id);   }   inline void print() { printf( %d n , ans); }   int main() {     init();     int t = 1;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       prework();       mainwork();       print();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[10][10];   int main() {     int bl = 0, wh = 0;     for (int i = 0; i < 8; i++) scanf( %s , s[i]);     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (s[i][j] ==  Q )           wh += 9;         else if (s[i][j] ==  R )           wh += 5;         else if (s[i][j] ==  B )           wh += 3;         else if (s[i][j] ==  N )           wh += 3;         else if (s[i][j] ==  P )           wh += 1;         else if (s[i][j] ==  q )           bl += 9;         else if (s[i][j] ==  r )           bl += 5;         else if (s[i][j] ==  b )           bl += 3;         else if (s[i][j] ==  n )           bl += 3;         else if (s[i][j] ==  p )           bl += 1;       }     if (bl > wh)       printf( Black n );     else if (bl == wh)       printf( Draw n );     else       printf( White n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5, maxm = 1e4 + 5, maxe = maxn * 4 + maxm,             maxp = 4 * maxe;   int n, m, b[maxe], id[maxe], tot, cnt, d;   double p[maxp], ans;   int read() {     int ret = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return ret * f;   }   struct tree {     int x, h, l, r;   } a[maxn];   struct mogu {     int x, v;   } c[maxn];   int find(int x) {     int L = 1, R = cnt, mid;     while (L <= R) {       mid = L + R >> 1;       if (id[mid] == x) return mid;       id[mid] < x ? L = mid + 1 : R = mid - 1;     }   }   void build(int l, int r, int k) {     p[k] = 1, d++;     if (l == r) return;     int mid = l + r >> 1;     build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);   }   void change(int L, int R, int k, int l, int r, double x) {     if (L > r || R < l) return;     if (l <= L && R <= r) {       p[k] *= x / 100.0;       return;     }     if (L == R) return;     int mid = L + R >> 1;     change(L, mid, k << 1, l, r, x), change(mid + 1, R, k << 1 | 1, l, r, x);   }   double ask(int l, int r, int k, int x) {     if (l == r) return p[k];     int mid = l + r >> 1;     if (mid >= x)       return ask(l, mid, k << 1, x) * p[k];     else       return ask(mid + 1, r, k << 1 | 1, x) * p[k];   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) {       a[i].x = read(), a[i].h = read(), a[i].l = read(), a[i].r = read();       b[++tot] = a[i].x - a[i].h, b[++tot] = a[i].x - 1, b[++tot] = a[i].x + 1,       b[++tot] = a[i].x + a[i].h;     }     for (int i = 1; i <= m; i++) {       c[i].x = read(), c[i].v = read();       b[++tot] = c[i].x;     }     sort(b + 1, b + 1 + tot);     for (int i = 1; i <= tot; i++)       if (b[i] != b[i + 1]) id[++cnt] = b[i];     build(1, cnt, 1);     for (int i = 1; i <= n; i++) {       int L = find(a[i].x - a[i].h), midl = find(a[i].x - 1),           midr = find(a[i].x + 1), R = find(a[i].x + a[i].h);       change(1, cnt, 1, L, midl, (double)100.0 - a[i].l),           change(1, cnt, 1, midr, R, (double)100.0 - a[i].r);     }     for (int i = 1; i <= m; i++) {       int x = find(c[i].x);       ans += (double)ask(1, cnt, 1, x) * c[i].v;     }     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   constexpr static int MAXD = 20000;   using namespace std;   bool check() {     int n;     cin >> n;     int dist = 0;     bool r = true;     for (int i = 0; i < n; i++) {       int t;       string dir;       cin >> t >> dir;       if (dist == 0 && dir !=  South ) r = false;       if (dist == MAXD && dir !=  North ) r = false;       if (dir ==  North ) {         dist -= t;         if (dist < 0) r = false;       }       if (dir ==  South ) {         dist += t;         if (dist > MAXD) r = false;       }     }     if (dist != 0) r = false;     return r;   }   int main() {     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int cmpint(const void *a, const void *b) {     if (((int *)a)[0] == ((int *)b)[0]) return ((int *)a)[1] - ((int *)b)[1];     return ((int *)a)[0] - ((int *)b)[0];   }   char s[100005];   int a[4] = {0};   int abs(int a) {     if (a > 0) return a;     return -a;   }   int main() {     int i, j, n, m, k, l, o, p;     n = m = k = 0;     gets(s);     l = strlen(s);     for (i = (0); i < (l); i++)       if (s[i] ==  0 )         m++;       else if (s[i] ==  1 )         n++;       else         k++;     if (m + k - n >= 1) a[0] = 1;     if (n + k - m >= 2) a[3] = 1;     if (l % 2 == 0) {       if (abs(n - m) <= k) {         if (abs(n - m) == k && s[l - 1] ==  ? ) {           if (n < m)             s[l - 1] =  1 ;           else             s[l - 1] =  0 ;         }         if (s[l - 1] ==  0 )           a[2] = 1;         else if (s[l - 1] ==  1 )           a[1] = 1;         else {           a[1] = a[2] = 1;         }       }     } else {       if (n == 0)         k--;       else         n -= 1;       if (abs(n - m) <= k) {         if (abs(n - m) == k && s[l - 1] ==  ? ) {           if (n < m)             s[l - 1] =  1 ;           else             s[l - 1] =  0 ;         }         if (s[l - 1] ==  0 )           a[2] = 1;         else if (s[l - 1] ==  1 )           a[1] = 1;         else {           a[1] = a[2] = 1;         }       }     }     for (i = (0); i < (4); i++)       if (a[i] == 1) {         printf( %d%d n , i / 2, i % 2);       }     return 0;   }
/*    #include <ext/pb_ds/assoc_container.hpp>    #include <ext/pb_ds/priority_queue.hpp>       using namespace __gnu_pbds;         __gnu_pbds::priority_queue<int, less<int>> pq;   gp_hash_table<int, int> mp;   */      /** Begin fast allocation */   /*   const int mx_MEM = 10 * 1e7;   int mpos = 0;   char mem[mx_MEM];      inline void *operator new(size_t n) {       assert((mpos += n) <= mx_MEM);       return (void *) (mem + mpos - n);   }      inline void operator delete(void *) noexcept {} // must have!   */   /** End fast allocation */      /** Pragmas */   // mt19937 gen(2281337);      //#pragma GCC optimize( O3 ,  Ofast ,  unroll-loops ,  unswitch-loops ,  fast-math ,  no-stack-protector )      //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx )   // sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,   //#pragma comment(linker,  /STACK:66777216 )      /*    * @author kamil.sharipov    */      #include <bits/stdc++.h>      //#define int long long   #define all(x) (x).begin(), (x).end()   #define fo(i, a, b) for (int i = a; i < b; ++i)   #define ll long long   #define pii pair<int, int>      using namespace std;      int n, m, inf = 2e9, dst = 51;      vector<vector<pii > > adj;      vector<vector<vector<int> > > we;      int dist[100001][51];      signed main() {   #ifdef _LOCAL       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif          cin >> n >> m;          adj.resize(n), we.resize(n);       for (int i = 0; i < n; ++i) {           we[i].resize(dst);       }          for (int i = 0; i < m; ++i) {           int u, v, w;           cin >> u >> v >> w;           --u, --v;           adj[u].push_back({v, w});           adj[v].push_back({u, w});       }          for (int i = 0; i < n; ++i) {           for (int j = 0; j < dst; ++j) {               dist[i][j] = inf;           }       }          dist[0][0] = 0;          set<pair<int, pii > > st;       st.insert({0, {0, 0}});          while (!st.empty()) {           auto[w, p] = *st.begin();           st.erase(st.begin());           int v = p.first;           int d = p.second;              if (w > dist[v][d]) continue;              if (d == 0) {               for (int i = 0; i < adj[v].size(); ++i) {                   int to = adj[v][i].first;                   int wei = adj[v][i].second;                      if (dist[to][wei] > w) {                       dist[to][wei] = w;                       st.insert({dist[to][wei], {to, wei}});                   }               }           } else {               for (int i = 0; i < adj[v].size(); ++i) {                   int to = adj[v][i].first;                   int wei = adj[v][i].second;                      int len = (d + wei) * (d + wei) + w;                      if (dist[to][0] > len) {                       dist[to][0] = len;                       st.insert({dist[to][0], {to, 0}});                   }               }           }       }          for (int i = 0; i < n; ++i) {           if (dist[i][0] == inf) cout <<  -1  ;           else cout << dist[i][0] <<    ;       }   }
#include <bits/stdc++.h>   using namespace std;   int L, R;   int main() {     int n, m, i, j, u, v;     cin >> n >> m;     int ans = 100001;     for (i = 0; i < m; i++) {       scanf( %d%d , &L, &R);       ans = min(ans, R - L + 1);     }     cout << ans << endl;     for (i = 1; i <= n; i++) cout << i % ans <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, INF = 2000000000000000000;   vector<long long> g[N];   long long power(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   vector<long long> prime;   bool isprime[N];   void pre() {     for (long long i = 2; i < N; i++) {       if (isprime[i]) {         for (long long j = i * i; j < N; j += i) isprime[j] = false;         prime.push_back(i);       }     }     return;   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long gcd(long long a, long long b) {     if (a < b)       return gcd(b, a);     else if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long spf[N + 1];   void spfFun() {     for (long long i = 0; i <= N; i++) spf[i] = i;     for (long long i = 2; i * i <= N; i++) {       if (spf[i] == i) {         for (long long j = i * i; j <= N; j += i) {           spf[j] = min(spf[j], i);         }       }     }   }   bool isPerfectSquare(long double x) {     long double sr = sqrt(x);     return ((sr - floor(sr)) == 0);   }   void print(bool n) {     if (n) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n;     cin >> n;     long long l[n], r[n];     for (long long i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     long long k;     cin >> k;     k--;     long long ans = n;     for (long long i = 0; i < n; i++) {       if (r[i] > k) {         ans = i;         break;       }     }     cout << n - ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int num;     bool flag = true;     int* numbers = new int[n];     for (int i = 0; i < n; i++) {       cin >> num;       numbers[i] = num;       if (i == n - 1) break;     }     for (int i = 0; i < n - 1; i++)       for (int j = i + 1; j < n; j++) {         if (numbers[i] > numbers[j]) swap(numbers[i], numbers[j]);       }     int s;     if (n == 1)       flag = false;     else {       for (int i = 0; i < n; i++) {         if (numbers[i] > numbers[0]) {           flag = true;           s = numbers[i];           break;         }         flag = false;       }     }     if (flag)       cout << s << endl;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int qa[100010] = {0}, qb[100010] = {0}, qla[100010] = {0};   int pa[100010] = {0}, pb[100010] = {0}, pla[100010] = {0};   char a[100010], b[100010];   int n, m;   int la, lb, l1, r1, l2, r2;   int main() {     cin >> a >> b;     cin >> n;     la = strlen(a);     lb = strlen(b);     for (int i = 1; i <= la; i++) {       if (a[i - 1] ==  A ) {         qa[i] = qa[i - 1] + 1;         qla[i] = qla[i - 1];         qb[i] = qb[i - 1];       } else {         qa[i] = qa[i - 1];         qla[i] = i;         qb[i] = qb[i - 1] + 1;       }     }     for (int i = 1; i <= lb; i++) {       if (b[i - 1] ==  A ) {         pa[i] = pa[i - 1] + 1;         pla[i] = pla[i - 1];         pb[i] = pb[i - 1];       } else {         pla[i] = i;         pa[i] = pa[i - 1];         pb[i] = pb[i - 1] + 1;       }     }     for (int i = 0; i < n; i++) {       cin >> l1 >> r1 >> l2 >> r2;       int cna = qb[r1] - qb[l1 - 1], cnb = pb[r2] - pb[l2 - 1];       int ans = 0;       if (cnb == cna && cnb == 0 &&           (r2 - l2 - r1 + l1 == 0 ||            ((r2 - l2 - r1 + l1) % 3 == 0 && r2 - l2 - r1 + l1 < 0))) {         ans = 1;       }       if (cna == 0 && cnb % 2 == 0 && cnb > 0 && (r2 - pla[r2] < r1 - l1 + 1)) {         ans = 1;       }       if (cnb > cna && (cnb - cna) % 2 == 0 && cna > 0) {         if ((r2 - pla[r2] <= r1 - qla[r1])) ans = 1;       }       if (cnb == cna && cnb > 0) {         if (!((r1 - qla[r1] != r2 - pla[r2]) &&               !((r1 - qla[r1] - r2 + pla[r2]) > 0 &&                 (r1 - qla[r1] - r2 + pla[r2]) % 3 == 0)))           ans = 1;       }       cout << ans;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return b < a ? a : b;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0, b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 300007;   int n, val[_] = {0}, cho[_] = {0};   long long f[_];   vector<int> ans;   inline void gay(int x) {     if (val[x] <= 0 || val[x + 1] <= 0) return;     int dlt = min(val[x], val[x + 1]);     ans.push_back(x), val[x] -= dlt, val[x + 1] -= dlt;   }   int main() {     n = ty();     for (int i = 1; i <= n; i++) val[i] = ty();     for (int i = 1; i <= n; i++) {       long long a = f[max(i - 2, 0)] + val[i],                 b = f[max(i - 3, 0)] + max(val[i - 1], val[i]);       f[i] = min(a, b);       if (f[i] == b) cho[i] = 1;     }     for (int i = (min(f[n], f[n - 1]) == f[n]) ? (n) : (n - 1); i >= 1;          i -= 2 + cho[i]) {       gay(i - 1);       if (cho[i]) gay(i - 2);       gay(i);     }     printf( %lu n , ans.size());     for (auto i : ans) printf( %d n , i);     return 0;   }