malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 15;   struct tree {     int l, r, sum;     tree *left, *right;     tree(int L, int R, int val) {       l = L, r = R, sum = val;       left = right = NULL;     }   };   tree *pq[N], *db[N];   tree *update(tree *cur, int l, int r, int ind, int add) {     tree *ret = new tree(l, r, 0);     ret->sum += cur->sum + add;     if (l == r) {       ret->sum = cur->sum;       ret->sum += add;       return ret;     }     int mid = (l + r) / 2;     if (ind <= mid) {       if (!cur->left) {         cur->left = new tree(l, mid, 0);       }       ret->right = cur->right;       ret->left = update(cur->left, l, mid, ind, add);     } else {       if (!cur->right) {         cur->right = new tree(mid + 1, r, 0);       }       ret->right = update(cur->right, mid + 1, r, ind, add);       ret->left = cur->left;     }     return ret;   }   int getval(tree *cur, int l, int r, int ind) {     if (l == r) {       return cur->sum;     }     int mid = (l + r) / 2;     if (ind <= mid) {       if (!cur->left) return 0;       return getval(cur->left, l, mid, ind);     } else {       if (!cur->right) return 0;       return getval(cur->right, mid + 1, r, ind);     }   }   int count(tree *cur, int l, int r, int ind) {     if (cur == NULL) return 0;     if (ind < l) {       return 0;     }     if (r <= ind) {       return cur->sum;     }     int mid = (l + r) / 2;     int ret = 0;     if (cur->left) ret = count(cur->left, l, mid, ind);     if (cur->right) ret += count(cur->right, mid + 1, r, ind);     return ret;   }   map<string, int> Hash;   int main() {     int q, i;     string s, name;     int pos = 1;     int x;     cin >> q;     int n = 1e5;     int m = 1e9;     int C = 0, v;     pq[C] = new tree(1, n, -1);     db[C] = new tree(1, m, 0);     while (q--) {       cin >> s;       if (s[0] ==  u ) {         scanf( %d , &x);         pq[C + 1] = pq[C - x];         db[C + 1] = db[C - x];       } else {         cin >> name;         if (!Hash.count(name)) {           Hash[name] = pos++;         }         int id = Hash[name];         if (s[0] ==  s ) {           scanf( %d , &x);           v = getval(pq[C], 1, n, id);           if (v != 0) {             pq[C + 1] = update(pq[C], 1, n, id, -v + x);             db[C + 1] = update(db[C], 1, m, v, -1);             db[C + 1] = update(db[C + 1], 1, m, x, 1);           } else {             pq[C + 1] = pq[C], db[C + 1] = db[C];             pq[C + 1] = update(pq[C + 1], 1, n, id, x);             db[C + 1] = update(db[C + 1], 1, m, x, 1);           }         } else if (s[0] ==  q ) {           pq[C + 1] = pq[C];           db[C + 1] = db[C];           v = getval(pq[C + 1], 1, n, id);           if (v != 0) {             printf( %d n , count(db[C + 1], 1, m, v - 1));           } else             printf( -1 n );         } else {           pq[C + 1] = pq[C];           db[C + 1] = db[C];           v = getval(pq[C + 1], 1, n, id);           if (v != 0) {             pq[C + 1] = update(pq[C + 1], 1, n, id, -v);             db[C + 1] = update(db[C + 1], 1, m, v, -1);           }         }       }       ++C;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b;     cin >> a >> b;     vector<long long int> m;     vector<long long int> n;     set<long long int> s;     m.push_back(1);     n.push_back(1);     if (a == 1) s.insert(1);     for (long long int i = 1; i <= b;) {       i = i * 2;       m.push_back(i);       if (i >= a && i <= b) s.insert(i);     }     for (long long int i = 1; i <= b;) {       i = i * 3;       n.push_back(i);       if (i >= a && i <= b) s.insert(i);     }     for (int i = 0; i < m.size(); i++) {       for (int j = 0; j < n.size(); j++) {         long long int x = m[i] * n[j];         if (x >= a && x <= b) {           s.insert(x);         }       }     }     cout << s.size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   void rd(int &x) {     x = 0;     int f = 1;     char ch = (getchar());     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = (getchar());     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = (getchar());     x *= f;   }   const int N = 5e5 + 5;   int n, m;   int a[N], c[N], tmp[N];   priority_queue<int, vector<int>, greater<int> > Q;   int main() {     rd(n);     long long ans = 0;     for (int i = 1; i <= n; ++i) rd(a[i]), ans += a[i];     sort(a + 1, a + n + 1, greater<int>());     for (int i = 1; i <= n; ++i) {       int j = i;       a[++m] = a[i];       while (j <= n && a[j + 1] == a[i]) ++j;       c[m] = j - i + 1, i = j;     }     n = m;     int cnt = 0, tmp0 = 0;     for (int i = 1; i <= n; ++i) {       int res = min(cnt - 2 * (int)Q.size(), c[i]),           ok = min(c[i] - res, cnt - res);       tmp0 = 0;       for (int j = 1; j <= res; ++j) tmp[++tmp0] = a[i];       for (int j = 1; j <= ok; j += 2) {         int val = Q.top();         Q.pop();         if (val < a[i]) {           tmp[++tmp0] = a[i];           if (ok - j) tmp[++tmp0] = a[i];         } else {           tmp[++tmp0] = val;           if (ok - j && 2 * a[i] - val > 0) tmp[++tmp0] = 2 * a[i] - val;         }       }       for (int j = 1; j <= tmp0; ++j) Q.push(tmp[j]);       cnt += c[i];     }     while (!Q.empty()) ans -= Q.top(), Q.pop();     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, A[105], B[105], w, ans, tmp;   int main() {     scanf( %d , &n);     n *= 2;     for (int i = (0); i < (n); i++) scanf( %d , &A[i]);     sort(A, A + n);     ans = 123412345;     for (int i = (0); i < (n); i++)       for (int j = (i + 1); j < (n); j++) {         w = 0;         for (int k = (0); k < (n); k++) {           if (k == i || k == j) continue;           B[w++] = A[k];         }         tmp = 0;         for (int k = 0; k < w; k += 2) tmp += B[k + 1] - B[k];         ans = min(ans, tmp);       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   vector<int> g[maxn];   int father[maxn];   int a[maxn];   int findfather(int x) {     int a = x;     while (x != father[x]) x = father[x];     while (a != father[a]) {       int z = a;       a = father[a];       father[z] = x;     }     return x;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       g[a[i]].push_back(i);     }     int wjm = n;     for (int i = 1; i <= m; i++) father[i] = i;     for (int i = 2; i <= n; i++)       if (a[i - 1] == a[i]) wjm--;     printf( %d n , wjm - 1);     for (int i = 1; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       int faX = findfather(x);       int faY = findfather(y);       if (g[faX].size() > g[faY].size()) swap(faX, faY);       for (int j : g[faX]) {         if (j + 1 <= n && a[j + 1] == faY) wjm--;         if (j - 1 >= 1 && a[j - 1] == faY) wjm--;         g[faY].push_back(j);       }       for (int j : g[faX]) a[j] = faY;       father[faX] = faY;       printf( %d n , wjm - 1);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5, INF = 0x3f3f3f3f;   int a[maxn];   int last[maxn];   int main() {     int n;     while (cin >> n) {       memset(last, INF, sizeof(last));       for (int i = 0; i < n; i++) {         cin >> a[i];         last[a[i]] = i;       }       sort(last, last + maxn);       cout << a[last[0]] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char seat[10][1005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int mark = 2000;     int flag;     for (int i = 0; i < n; i++) {       cin >> seat[0][i] >> seat[1][i] >> seat[2][i] >> seat[3][i] >> seat[4][i];       if (seat[0][i] ==  O  && seat[1][i] ==  O ) {         mark = i;         flag = 0;       }       if (seat[3][i] ==  O  && seat[4][i] ==  O ) {         mark = i;         flag = 3;       }     }     if (mark == 2000)       cout <<  NO  << endl;     else {       seat[flag][mark] =  + ;       seat[flag + 1][mark] =  + ;       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         cout << seat[0][i] << seat[1][i] << seat[2][i] << seat[3][i] << seat[4][i]              << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> dp[2001][26];   int q[2000];   pair<int, int> ans[2001][2001];   int nxt[2001][26];   pair<int, int> jump(pair<int, int> p, char c) {     if (p.first < m) {       p.second = dp[q[p.first]][c -  a ][p.second];       if (p.second == -1) {         p.first = nxt[p.first + 1][c -  a ];         if (p.first < m) p.second = dp[q[p.first]][c -  a ][0];       }     }     return p;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < 26; ++j) {         dp[i][j].resize(s.size() + 1);         dp[i][j][s.size()] = -1;         for (int k = s.size() - 1; k >= 0; --k)           dp[i][j][k] = s[k] == j +  a  ? k + 1 : dp[i][j][k + 1];       }     }     cin >> m;     for (int i = 0; i < m; ++i) cin >> q[i], q[i]--;     for (int i = 0; i < 26; ++i) {       nxt[m][i] = m;       for (int j = m - 1; j >= 0; --j)         nxt[j][i] = dp[q[j]][i][0] == -1 ? nxt[j + 1][i] : j;     }     string s;     cin >> s;     for (int i = 0; i <= s.size(); ++i)       for (int j = 0; j <= s.size(); ++j) ans[i][j] = make_pair(1e9, 1e9);     ans[0][0] = make_pair(0, 0);     for (int i = 1; i <= s.size(); ++i)       for (int j = 0; j <= i; ++j) {         ans[i][j] = min(ans[i][j], ans[i - 1][j]);         if (j) ans[i][j] = min(ans[i][j], jump(ans[i - 1][j - 1], s[i - 1]));       }     for (int i = s.size(); i >= 0; --i)       if (ans[s.size()][i].first < m) {         cout << i <<   n ;         break;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, a, ans, i, b[10000000];   string s, s1;   int main() {     cin >> n >> s;     s1 =  0 ;     s1 += s;     s1 +=  0 ;     s = s1;     a = s.find( 11 );     if (a < 10000) return cout <<  No , 0;     a = s.find( 000 );     if (a < 10000) return cout <<  No , 0;     cout <<  Yes ;   }
#include <bits/stdc++.h>   const long double eps = 1e-9;   const double pi = acos(-1.0);   const long long inf = 1e18;   using namespace std;   int a[33], b[33], p[33], k[33], n, r, u, tt[33], z[33], back[33];   int cnt = 0;   long long ans = -inf;   void update(int step) {     int left = (u - step) % 2;     long long now = 0;     if (left == 0)       for (int i = 1; i <= n; i++) now += 1ll * k[i] * a[i];     if (left == 1)       for (int i = 1; i <= n; i++) now += 1ll * k[i] * (a[i] ^ b[i]);     ans = max(ans, now);   }   void rec(int pos) {     if (pos == u + 1) return;     for (int i = ((z[pos - 1] + 1) & 1); i < 2; i++) {       z[pos] = i;       if (i == 0) {         for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i];       }       if (i == 1) {         for (int i = 1; i <= n; i++) tt[i] = a[p[i]];         for (int i = 1; i <= n; i++) a[i] = tt[i] + r;       }       update(pos);       rec(pos + 1);       if (i == 0) {         for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i];       }       if (i == 1) {         for (int i = 1; i <= n; i++) tt[i] = a[back[i]];         for (int i = 1; i <= n; i++) a[i] = tt[i] - r;       }     }   }   int main(int argc, const char* argv[]) {     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) back[p[i]] = i;     z[0] = 1;     rec(1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   void file(bool opt) {     if (opt && fopen( in.txt ,  r ))       freopen( in.txt ,  r , stdin), freopen( out.txt ,  w , stdout);   }   struct node {     double x, y;   } point[100000 + 5], tu[100000 + 5];   int tot = 0;   int n;   double multi(node p0, node p1, node p2) {     return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);   }   double dis(node a, node b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   bool cmp(node a, node b) {     double x = multi(a, b, point[1]);     if (x > 0 || (x == 0 && dis(a, point[1]) < dis(b, point[1]))) return 1;     return 0;   }   void Graham() {     int k = 1;     for (int i = 1; i <= n; i++)       if (point[i].y < point[k].y ||           (point[i].y == point[k].y && point[i].x < point[k].x))         k = i;     swap(point[1], point[k]);     sort(point + 2, point + 1 + n, cmp);     tot = 2, tu[1] = point[1], tu[2] = point[2];     for (int i = 3; i <= n; i++) {       while (tot >= 1 && multi(tu[tot], tu[tot - 1], point[i]) >= 0) tot--;       tu[++tot] = point[i];     }   }   int main() {     file(1);     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf%lf , &point[i].x, &point[i].y);       point[i].y = point[i].y - point[i].x * point[i].x;     }     if (n == 1) {       puts( 0 );       return 0;     }     Graham();     int ans = 0;     for (int i = 1; i <= tot; i++) {       node a = tu[i], b = tu[(i + 1) > tot ? 1 : (i + 1)],            c = {0, (long long)1e15};       if (a.x != b.x) {         double x = multi(a, b, c);         if (x < 0) ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace Work {   const int kMaxN = 100010;   multiset<int> set;   int n;   int a[kMaxN], b[kMaxN];   int pos[kMaxN];   void solve(FILE* fin, FILE* fout) {     fscanf(fin,  %d , &n);     for (int i = 1; i <= n; i++) {       fscanf(fin,  %d , a + i);       pos[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       fscanf(fin,  %d , b + i);       set.insert(i - pos[b[i]]);     }     multiset<int>::iterator it = set.lower_bound(0);     int x = *it, y = x;     if (it != set.begin()) {       it--;       y = *it;     }     fprintf(fout,  %d n , min(abs(x), abs(y)));     for (int dt = 1; dt < n; dt++) {       set.erase(set.find(dt - pos[b[dt]]));       set.insert(n - pos[b[dt]] + dt);       it = set.lower_bound(dt);       x = *it, y = x;       if (it != set.begin()) {         it--;         y = *it;       }       fprintf(fout,  %d n , min(abs(x - dt), abs(y - dt)));     }     return;   }   }  // namespace Work   int main() {     Work::solve(stdin, stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     int sum = atoi(x.c_str()) + atoi(y.c_str());     int p = 0, now = 1;     for (; sum; sum /= 10) {       if (sum % 10 != 0) {         p += (sum % 10) * now;         now *= 10;       }     }     x.erase(remove(x.begin(), x.end(),  0 ), x.end());     y.erase(remove(y.begin(), y.end(),  0 ), y.end());     int X = atoi(x.c_str()), Y = atoi(y.c_str());     if (X + Y == p)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > vec(n);     vector<int> x(n);     vector<int> y(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       vec[i].first = x[i];       vec[i].second = y[i];     }     long long ans = 0;     sort(x.begin(), x.end());     long long count = 1;     for (int i = 1; i < n; i++) {       if (x[i] != x[i - 1]) {         ans += (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans += (count * (count - 1)) / 2;     sort(y.begin(), y.end());     count = 1;     for (int i = 1; i < n; i++) {       if (y[i] != y[i - 1]) {         ans += (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans += (count * (count - 1)) / 2;     sort(vec.begin(), vec.end());     count = 1;     for (int i = 1; i < n; i++) {       if (vec[i].first != vec[i - 1].first ||           vec[i].second != vec[i - 1].second) {         ans -= (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans -= (count * (count - 1)) / 2;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         int a;         cin >> a;         if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += a;       }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   int check(int x, int l) { return x >= 0 && x < l; }   int solve(vector<string> board, string per, string comm) {     int startx, starty, endx, endy;     int r, c;     r = board.size();     c = board[0].size();     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (board[i][j] ==  S ) {           startx = i;           starty = j;         } else if (board[i][j] ==  E ) {           endx = i;           endy = j;         }       }     }     int cx, cy;     cx = startx;     cy = starty;     int i = 0;     while (check(cx, r) && check(cy, c)) {       int t = comm[i] -  0 ;       i++;       if (i > comm.length()) return 0;       if (per[t] ==  U )         cy--;       else if (per[t] ==  D )         cy++;       else if (per[t] ==  L )         cx--;       else if (per[t] ==  R )         cx++;       if (!check(cx, r) || !check(cy, c)) return 0;       if (board[cx][cy] ==  E ) return 1;       if (board[cx][cy] ==  # ) return 0;     }     return 0;   }   int main() {     int n, m;     cin >> n >> m;     vector<string> board;     string comm;     for (int i = 0; i < n; i++) {       string temp;       cin >> temp;       board.push_back(temp);     }     cin >> comm;     string per =  DLRU ;     int ans = 0;     while (1) {       ans += solve(board, per, comm);       bool x = next_permutation(per.begin(), per.end());       if (!x) break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e16;   template <class P>   P gcd(P a, P b) {     return b ? gcd(b, a % b) : a;   };   long long read() {     char c = getchar();     long long d = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; d = d * 10 + c - 48, c = getchar())       ;     return d * f;   }   const int N = 100001;   const int M = 400001;   const int mod = 1e9 + 7;   int n, m, cnt, cyc_amount, head[N];   long long cyc_tot, ans, qz[N], _m2[201], record[62], f[62][2];   bool exist[N];   struct xint {     int to, next;     long long s;   } e[M];   inline void addedge(int x, int y, long long s) {     e[++cnt].to = y;     e[cnt].next = head[x];     e[cnt].s = s;     head[x] = cnt;   }   inline void dfs(int fa, int x, long long s) {     exist[x] = 1;     for (int i = 0; i <= 61; i++) f[i][s >> i & 1]++;     qz[x] = s;     for (int i = head[x]; i; i = e[i].next) {       int y = e[i].to;       if (y == fa) continue;       if (!exist[y])         dfs(x, y, s ^ e[i].s);       else {         long long t = qz[x] ^ qz[y] ^ e[i].s;         cyc_tot |= t;         for (int i = 61; i >= 0; i--) {           if ((t & (1LL << i)) && !record[i]) {             record[i] = t;             cyc_amount++;             break;           }           t = min(t, t ^ record[i]);         }       }     }   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) exist[i] = 1;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       long long s = read();       exist[x] = exist[y] = 0;       addedge(x, y, s);       addedge(y, x, s);     }     _m2[0] = 1;     for (int i = 1; i <= 200; i++) _m2[i] = _m2[i - 1] * 2 % mod;     for (int i = 1; i <= n; i++)       if (!exist[i]) {         cyc_amount = cyc_tot = 0;         for (int j = 0; j <= 61; j++) f[j][0] = f[j][1] = record[j] = 0;         memset(qz, 0, sizeof qz);         dfs(0, i, 0);         for (int j = 0; j <= 61; j++)           if (cyc_tot & (1LL << j))             ans = (ans + (f[j][0] + f[j][1]) * (f[j][0] + f[j][1] - 1) / 2 % mod *                              _m2[j + cyc_amount - 1] % mod) %                   mod;           else             ans =                 (ans + f[j][0] * f[j][1] % mod * _m2[j + cyc_amount] % mod) % mod;       }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxRounds = 200000;   double p[110], ans, pw[110][maxRounds + 10];   int times[110], n;   int main() {     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 1; i <= n; ++i) {       int first;       cin >> first;       p[i] = first / 100.0;     }     double initProd = 1;     for (int i = 1; i <= n; ++i) {       initProd *= p[i];       pw[i][0] = 1;       times[i] = 1;       for (int j = 1; j <= maxRounds; ++j) {         pw[i][j] = pw[i][j - 1] * (1 - p[i]);       }     }     ans += initProd * n;     for (int round = n + 1; round <= maxRounds; ++round) {       double best = 0;       int besti = 1;       double prod = 1;       for (int j = 1; j <= n; ++j) prod *= (1 - pw[j][times[j]]);       for (int j = 1; j <= n; ++j) {         double current = prod / (1 - pw[j][times[j]]) * pw[j][times[j]] * p[j];         if (current > best) {           besti = j;           best = current;         }       }       ans += best * round;       times[besti]++;     }     cout << fixed << setprecision(8) << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, maxx = 2, s = 1, k = 1;     cin >> n;     vector<int> a(n);     for (i = 0; i < n; i++) cin >> a[i];     a.push_back(0);     for (i = 0; i < n; i++) {       if (i > 0 && s > 1 && a[i] == 1 && a[i - 1] == 2) s = 1;       if (i > 0 && k > 1 && a[i] == 2 && a[i - 1] == 1) k = 1;       if (a[i] == 1 && a[i + 1] == 1)         s += 1;       else if (min(k, s) * 2 > maxx)         maxx = min(k, s) * 2;       if (a[i] == 2 && a[i + 1] == 2)         k += 1;       else if (min(k, s) * 2 > maxx)         maxx = min(k, s) * 2;     }     cout << maxx;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, f, k;     scanf( %lld %lld %lld %lld , &a, &b, &f, &k);     long long ans = 0;     long long cfuel = b;     for (int i = 0; i < k - 1; i++) {       if (i % 2 == 0) {         if (cfuel >= 2 * a - f) {           cfuel -= a;         } else if (cfuel >= f && b >= a - f) {           ans++;           cfuel = b - (a - f);         } else {           printf( -1 n );           return 0;         }       } else {         if (cfuel >= a + f) {           cfuel -= a;         } else if (cfuel >= a - f && b >= f) {           ans++;           cfuel = b - f;         } else {           printf( -1 n );           return 0;         }       }     }     if (k % 2) {       if (cfuel >= a) {       } else if (cfuel >= f && b >= a - f) {         ans++;       } else {         printf( -1 n );         return 0;       }     } else {       if (cfuel >= a) {       } else if (cfuel >= a - f && b >= f) {         ans++;       } else {         printf( -1 n );         return 0;       }     }     printf( %lld n , ans);   }