malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[100005];   map<long long, int> ma;   int main() {     long long b1, q, m, l;     cin >> b1 >> q >> l >> m;     while (m--) {       long long x;       cin >> x;       ma[x] = 1;     }     int ans = 0, i;     for (i = 1; i < 100; i++) {       if (abs(b1) > l) break;       if (!ma[b1]) ans++;       b1 *= q;     }     if (ans < 49)       cout << ans << endl;     else       cout <<  inf  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int nuts, divis, maxsec, capacity, boxees = 0;     cin >> maxsec >> nuts >> divis >> capacity;     while (nuts > 0) {       boxees++;       nuts -= ((min(maxsec, divis + 1)) * capacity);       divis -= ((min(maxsec, divis + 1)) - 1);     }     cout << boxees << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int vis[100010], h[100100];   vector<int> res;   set<int> q, off;   int a[100100];   char s[100010][2];   int main() {     int i, j, z, T, d;     while (cin >> n >> m) {       q.clear();       res.clear();       off.clear();       memset(vis, 0, sizeof(vis));       for (i = 1; i <= m; i++) {         scanf( %s%d , s[i], &a[i]);         if (s[i][0] ==  -  && !vis[a[i]]) q.insert(a[i]);         if (s[i][0] ==  +  && !vis[a[i]]) off.insert(a[i]);         vis[a[i]]++;       }       memset(vis, 0, sizeof(vis));       if (q.size() != 0) {         set<int>::iterator it;         for (it = off.begin(); it != off.end(); it++) vis[*it]++;         off.clear();       }       for (i = 1; i <= m; i++) {         if (s[i][0] ==  +  && q.size() != 0) {           set<int>::iterator it;           for (it = off.begin(); it != off.end(); it++) vis[*it]++;           off.clear();         }         if (s[i][0] ==  - ) {           q.erase(a[i]);           off.insert(a[i]);         } else {           if (off.count(a[i]) != 0) off.erase(a[i]);           q.insert(a[i]);         }         if (q.size() != 0) {           set<int>::iterator it;           for (it = off.begin(); it != off.end(); it++) vis[*it]++;           off.clear();         }       }       for (i = 1; i <= n; i++) {         if (!vis[i]) res.push_back(i);       }       printf( %d n , res.size());       for (i = 0; i < res.size(); i++) {         if (i) printf(   );         printf( %d , res[i]);       }       if (res.size() != 0) puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long fac[N], infac[N];   int n, m;   long long poww(long long b, long long p) {     if (p == 0) return 1;     if (p & 1) return (b * poww(b, p - 1)) % m;     return poww((b * b) % m, p / 2);   }   long long npk(int n, int k) { return (fac[n] * infac[n - k]) % m; }   long long nck(int n, int k) {     return (((fac[n] * infac[n - k]) % m) * infac[n - k]) % m;   }   int main() {     cin >> n >> m;     fac[0] = infac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = (i * fac[i - 1]) % m;       infac[i] = poww(fac[i], m - 2);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long a = n - i + 1;       a = (a * fac[i]) % m;       ans = (ans + a * fac[n - i + 1]) % m;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int result;     string input;     cin >> input;     set<string> sinput;     sinput.insert(input);     for (int i = input.size() - 1; i >= 0; --i) {       input = input[input.size() - 1] + input;       input.pop_back();       sinput.insert(input);     }     result = sinput.size();     printf( %d n , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long n, m, A, cf, cm, maxForce = -1, minSkill, minIdx, i, a[N], b[N];   pair<long long, int> sum[N];   inline long long query(long long money, int limit) {     long long l = sum[1].first, r = A, mid;     if (limit <= 1) {       return A;     }     while (l < r) {       mid = (l + r + 1) / 2;       int x = upper_bound(b + 1, b + limit, mid) - b - 1;       if (mid * x - sum[x].first <= money)         l = mid;       else         r = mid - 1;     }     return r;   }   int main() {     cin >> n >> A >> cf >> cm >> m;     for (i = 1; i <= n; ++i) {       scanf( %d , a + i);       sum[i].first = a[i];       sum[i].second = i;     }     sort(sum + 1, sum + n + 1);     for (i = 1; i <= n; ++i) {       b[i] = sum[i].first;       sum[i].first += sum[i - 1].first;     }     b[n + 1] = A;     for (i = n + 1; i >= 1; --i) {       m -= A - b[i];       if (m < 0) {         break;       }       long long x = query(m, i);       long long force = cf * (n - i + 1) + cm * x;       if (maxForce < force) {         maxForce = force;         minIdx = i;         minSkill = x;       }     }     for (i = n; i >= minIdx; --i) {       a[sum[i].second] = A;     }     cout << maxForce << endl;     for (i = 1; i <= n; ++i) {       printf( %d  , max(a[i], minSkill));     }     return 0;   }
#include <bits/stdc++.h>        #define dumb ios_base::sync_with_stdio(false);cin.tie(NULL);           typedef  long long ll;        using namespace std;      #define modulo 1000000007;      bool isprime(long long n)   {       for(long long int i=2;i*i<=n;i++)       {           if(n%i==0)               return 0;       }       return 1;   }   long long gcd(long long int a, long long int b)   {     if (b == 0)       return a;     return gcd(b, a % b);   }      // Function to return LCM of two numbers   long long lcm(int a, int b)   {       return (a / gcd(a, b)) * b;   }         ll ncr(ll n,ll k)   {       ll res = 1;       if (k > n - k)           k = n - k;       for (ll i = 0; i < k; ++i) {           res *= (n - i);           res /= (i + 1);       }       return res;   }      map<int,int> m;      void solve()   {     int n;     cin>>n;        auto it=m.lower_bound(n);     if(it->first==n)     {       cout<<it->second<<endl;       return;     }     else     {       int diff=it->first-n;       if(diff==1)         cout<<it->second+1<<endl;       else         cout<<it->second<<endl;              return;     }      return;    }                     int main()   {     dumb;       int t=1;       cin>>t;       int i=1;       m[0]=0;       int sum=0;       while(1)       {         m[sum+i]=i;         if(sum+i>1000000)           break;         sum+=i;         i++;       }       while(t--)       {         //cout<< in ;          solve();        }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   void PRINT_ARRAY(const T (&a)[N], int n = -1) {     if (!n) n = N;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T, size_t N, size_t M>   void PRINT_ARRAY(const T (&a)[N][M], int n, int m) {     for (int i = 0; i < n; i++) PRINT_ARRAY(a[i], m);     cout <<   n ;   }   long long arr[3005], cost[3005], lessc, more, ans;   int n;   void solve() {     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) cin >> cost[i];     ans = (int)(1e9 + 7);     for (int i = 1; i < n - 1; i++) {       lessc = (int)(1e9 + 7);       more = (int)(1e9 + 7);       for (int j = 0; j < i; j++)         if (arr[i] > arr[j]) lessc = min(lessc, cost[j]);       for (int j = i + 1; j < n; j++)         if (arr[j] > arr[i]) more = min(more, cost[j]);       ans = min(ans, cost[i] + lessc + more);     }     cout << (ans == (int)(1e9 + 7) ? -1 : ans);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   bitset<2020> mat[2020];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &N, &M);       vector<pair<int, int> > E;       int deg[2020] = {};       for (int i = 1; i <= M; i++) {         int x, y;         scanf( %d%d , &x, &y);         deg[x]++;         deg[y]++;         E.push_back(pair<int, int>(x, y));       }       int ok = 1;       for (int i = 1; i <= N; i++)         if (deg[i] & 1) ok = 0;       if (ok) {         puts( 1 );         for (int i = 1; i <= N; i++) printf( 1  );         puts(  );       } else {         for (int i = 1; i <= N; i++) mat[i].reset();         for (int i = 1; i <= N; i++)           if (deg[i] & 1) mat[i][i] = 1;         for (pair<int, int> e : E) {           int x = e.first, y = e.second;           mat[x][y] = !mat[x][y];           mat[y][x] = !mat[y][x];         }         int V[2020] = {};         for (int i = 1; i <= N; i++) V[i] = (deg[i] & 1);         int now = 1;         int base[2020];         for (int i = 1; i <= N; i++) {           int f = -1;           for (int j = now; j <= N; j++)             if (mat[j][i]) {               f = j;               break;             }           if (f == -1) continue;           swap(mat[f], mat[now]);           swap(V[f], V[now]);           for (int j = now + 1; j <= N; j++) {             if (mat[j][i]) {               mat[j] ^= mat[now];               V[j] ^= V[now];             }           }           base[now] = i;           ++now;         }         --now;         int res[2020] = {};         for (int i = now; i; i--) {           int p = base[i];           res[p] = V[i];           if (res[p]) {             for (int j = 1; j < i; j++)               if (mat[j][p]) V[j] ^= 1;           }         }         puts( 2 );         for (int i = 1; i <= N; i++) printf( %d  , res[i] + 1);         puts(  );       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long MOD = 1000000007;   void solve_test() {     int n;     cin >> n;     vector<int> arr(n);     vector<int> ct(101);     for (int i = 0; i < n; i++) {       cin >> arr[i];       ct[arr[i]]++;     }     int max_val = -1;     int max_freq = -1;     for (int i = 1; i <= 100; i++) {       if (ct[i] > max_freq) {         max_freq = ct[i];         max_val = i;       }     }     unordered_map<int, int> um;     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (max_val == i) continue;       um.clear();       int st = 0;       um[0] = -1;       for (int j = 0; j < n; j++) {         if (arr[j] == i) {           st++;         } else if (arr[j] == max_val) {           st--;         }         if (um.find(st) == um.end()) {           um[st] = j;         } else {           ans = max(ans, j - um[st]);         }       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tests;     tests = 1;     while (tests--) {       solve_test();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, T;   char str[15], temp[15];   int main() {     int i, j, k;     scanf( %s%s , str, temp);     i = strlen(str);     sort(str, str + i);     if (str[0] ==  0 ) {       do {         if (str[0] !=  0 ) break;       } while (next_permutation(str, str + i));     }     if (strcmp(str, temp) == 0)       printf( OK n );     else       printf( WRONG_ANSWER n );     scanf(   );   }
#include <bits/stdc++.h>   using namespace std;   void init() {}   const int N = (int)1e6 + 34;   const long long INF = (long long)1e9 + 34;   int n, m;   int a[555][555];   int c[555], r[555];   int main() {     init();     int mxr = -N, mnr = N, mxc = -N, mnc = N;     cin >> n >> m;     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         sum += a[i][j];       }     }     if (n == 1) {       for (int j = 0; j < m; j++) {         c[j] = a[0][j];       }       r[0] = 0;     }     if (m == 1) {       for (int i = 0; i < n; i++) {         r[i] = a[i][0];       }       c[0] = 0;     }     if (max(n, m) > 1) {       c[0] = 0;       for (int i = 0; i < n; i++) r[i] = a[i][0];       for (int j = 1; j < m; j++)         for (int i = 0; i < n; i++) {           c[j] = a[i][j] - r[i];         }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] != r[i] + c[j]) {           cout <<  -1 n ;           return 0;         }       }     for (int i = 0; i < n; i++) {       mnr = min(mnr, r[i]);       mxr = max(mxr, r[i]);     }     for (int j = 0; j < m; j++) {       mxc = max(mxc, c[j]);       mnc = min(mnc, c[j]);     }     if (mnr + mnc < 0) {       cout <<  -1 n ;       return 0;     }     int dr = 0;     int dc = 0;     if (mnr < 0) {       dc = mnr;       dr = -dc;     } else if (mnc < 0) {       dr = mnc;       dc = -dr;     }     while (n > m && mnr + dr > 0) {       dr--;       dc++;     }     while (n < m && mnc + dc > 0) {       dr++;       dc--;     }     int num = 0;     for (int i = 0; i < n; i++) num += r[i] + dr;     for (int j = 0; j < m; j++) num += c[j] + dc;     cout << num <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < r[i] + dr; j++) cout <<  row   << i + 1 <<   n ;     }     for (int j = 0; j < m; j++) {       for (int i = 0; i < c[j] + dc; i++) cout <<  col   << j + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, v;     scanf( %d%d%d , &n, &m, &v);     int spec = 1;     if (m < n - 1 || m > (n - 1) * (n - 2) / 2 + 1) {       printf( -1 n );       return 0;     }     if (spec == v) spec++;     printf( %d %d n , v, spec);     m--;     for (int i = 1; i <= n; i++) {       if (i == spec) continue;       for (int j = i + 1; j <= n; j++) {         if (j == spec) continue;         printf( %d %d n , i, j);         m--;         if (m == 0) return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str[1005];   int tim[1005][1005];   int n, m, t;   int fx[] = {-1, +1, 0, 0};   int fy[] = {0, 0, -1, +1};   vector<pair<int, int> > cur;   bool okay(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }   void dfs(int x, int y, int curr) {     tim[x][y] = curr;     cur.push_back(make_pair(x, y));     for (int k = 0; k < 4; k++) {       int tx = x + fx[k];       int ty = y + fy[k];       if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != str[x][y])         continue;       dfs(tx, ty, curr);     }   }   char alt(char x) {     if (x ==  0 )       return  1 ;     else       return  0 ;   }   char query(int x, int y, long long curr) {     if (tim[x][y] == -1) return str[x][y];     long long diff = curr - 1LL * tim[x][y];     if (diff % 2LL == 1LL)       return alt(str[x][y]);     else       return str[x][y];   }   int main() {     scanf( %d %d %d , &n, &m, &t);     for (int i = 0; i < n; i++) {       cin >> str[i];     }     memset(tim, -1, sizeof tim);     vector<pair<int, int> > last;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) last.push_back(make_pair(i, j));     }     for (int curTim = 0; curTim <= n * m; curTim++) {       for (int i = 0; i < last.size(); i++) {         int x = last[i].first, y = last[i].second;         char col = query(x, y, curTim);         for (int k = 0; k < 4; k++) {           int tx = x + fx[k];           int ty = y + fy[k];           if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != col)             continue;           dfs(tx, ty, curTim);         }       }       last = cur;       cur.clear();       if (last.empty()) break;     }     while (t--) {       int x, y;       long long q;       scanf( %d %d %lld , &x, &y, &q);       x--, y--;       char ans = query(x, y, q);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 100005;   int a[3], d;   void Solve() {     cin >> a[0] >> a[1] >> a[2] >> d;     sort(a, a + 3);     long long res = 0;     if (a[2] < a[1] + d) res += a[1] + d - a[2];     if (a[0] > a[1] - d) res += a[0] - a[1] + d;     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     }     int test_case = 1;     while (test_case--) Solve();     return 0;   }
#include <bits/stdc++.h>   struct circle {     double r, x, y;     circle(void) : r(0), x(0), y(0) {}     bool contains(const circle& o) const {       double dx, dy;       dx = o.x - x;       dy = o.y - y;       return (dx * dx + dy * dy <= r * r) && o.r < r;     }   };   circle fences[1024];   circle control[1024];   int depth[1024];   int parent[11][1024];   int control_parent[1024];   int V, n;   int find_parent(const circle& c, const int& ignore) {     int best_j, best, j;     best_j = V;     best = -INT_MAX;     for (j = 0; j < V; ++j) {       if (j != ignore && fences[j].contains(c)) {         if (depth[j] > best) {           best = depth[j];           best_j = j;         }       }     }     return best_j;   }   void build_tree(void) {     int i, j;     for (i = 0; i < V; ++i) {       depth[i] = 1;       for (j = 0; j < V; ++j) {         if (i != j && fences[j].contains(fences[i])) {           ++depth[i];         }       }     }     for (i = 0; i < V; ++i) {       parent[0][i] = find_parent(fences[i], i);     }     for (i = 1; i <= n; ++i) {       control_parent[i] = find_parent(control[i], -1);     }   }   void build_lca(void) {     int lg2, i;     parent[0][V] = V;     for (lg2 = 1; lg2 < 11; ++lg2) {       for (i = 0; i < V; ++i) {         parent[lg2][i] = parent[lg2 - 1][parent[lg2 - 1][i]];       }     }   }   int get_lca(int a, int b) {     int step, lg2;     if (depth[a] < depth[b]) {       std::swap(a, b);     }     for (lg2 = 10, step = 1024; lg2 >= 0; --lg2, step >>= 1) {       if (depth[a] - step >= depth[b]) {         a = parent[lg2][a];       }     }     if (a == b) {       return a;     }     for (lg2 = 10, step = 1024; lg2 >= 0; --lg2, step >>= 1) {       if (parent[lg2][a] != parent[lg2][b]) {         a = parent[lg2][a];         b = parent[lg2][b];       }     }     return parent[0][a];   }   int main(void) {     int i, q;     int control_1, control_2, control_3;     std::cin.tie(0);     std::ios_base::sync_with_stdio(0);     std::cin >> n >> V >> q;     for (i = 1; i <= n; ++i) {       std::cin >> control[i].x >> control[i].y;     }     for (i = 0; i < V; ++i) {       std::cin >> fences[i].r >> fences[i].x >> fences[i].y;     }     build_tree();     build_lca();     for (i = 0; i < q; ++i) {       std::cin >> control_1 >> control_2;       control_1 = control_parent[control_1];       control_2 = control_parent[control_2];       control_3 = get_lca(control_1, control_2);       std::cout << (depth[control_1] + depth[control_2] - 2 * depth[control_3])                 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int logb(int base, int x) { return (log(x) / log(base)); }   int occurs(vector<long long> v, int n) {     auto it = lower_bound(((v)).begin(), ((v)).end(), (n));     auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n));     int x = it1 - it;     return x;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long powm(int a, int b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * 1LL * a) % mod;       b >>= 1;       a = (a * 1LL * a) % mod;     }     return res;   }   long long nCr(long long n, long long k) {     int fact[n];     long long res = (fact[n] * powm(fact[k], mod - 2)) % mod;     return (res * powm(fact[n - k], mod - 2)) % mod;   }   const int N = 1e5 + 5, inf = 1e9;   vector<int> g[N];   int n, m, d;   int mxin[N], mxout[N], marked[N];   void dfs_down(int v, int p) {     mxin[v] = -inf;     if (marked[v]) mxin[v] = 0;     for (auto u : g[v]) {       if (u == p) continue;       dfs_down(u, v);       mxin[v] = max(mxin[v], mxin[u] + 1);     }   }   void dfs_up(int v, int p) {     int max1 = -1 * inf, max2 = -1 * inf;     for (auto u : g[v]) {       if (u == p) continue;       if (mxin[u] >= max1)         max2 = max1, max1 = mxin[u];       else if (mxin[u] > max2)         max2 = mxin[u];     }     for (auto u : g[v]) {       if (u == p) continue;       int used = (mxin[u] == max1) ? max2 : max1;       mxout[u] = max(1 + mxout[v], 2 + used);       if (mxout[u] < 0 && marked[u]) mxout[u] = 0;       dfs_up(u, v);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     int x, y;     for (int(i) = 0; (i) < (m); ++(i)) {       cin >> x;       marked[x] = 1;     }     for (int(i) = 0; (i) < (n - 1); ++(i)) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs_down(1, 0);     mxout[1] = (marked[1] ? 0 : -inf);     dfs_up(1, 0);     int ans = 0;     for (int i = 1; i <= n; i++) ans += (mxin[i] <= d && mxout[i] <= d);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, V, A[64], B[64];   bool canCook(double x) {     double tot = 0.0;     for (int i = 0; i < n; i++)       if (A[i] * x > B[i])         return 0;       else         tot += A[i] * x;     return tot <= V;   }   double totalAmount(double x) {     double tot = 0.0;     for (int i = 0; i < n; i++) tot += A[i] * x;     return tot;   }   int main() {     scanf( %d%d , &n, &V);     for (int i = 0; i < n; i++) scanf( %d , &A[i]);     for (int i = 0; i < n; i++) scanf( %d , &B[i]);     double lo = 0.0, hi = double(2 * V), mid;     while (abs(hi - lo) >= 1e-6) {       mid = (hi + lo) / 2;       if (canCook(mid))         lo = mid;       else         hi = mid;     }     printf( %.6f n , totalAmount(lo));   }
#include <bits/stdc++.h>   using namespace std;   map<long long, int> mp;   long long n, k, i, v[500005], val[500005], x, sum[500005], fr[500005],       frec[500005], fr3[500005], nr, sum2[500005], bucket, val1, m, st, dr, s,       stcur, drcur, sol[500005], fr2[500005], val2, b[500005];   struct wow {     long long st, dr, poz;   } a[500005];   long long cautbin(long long x) {     long long st = 0, dr = n, mij, sol = 0;     while (st <= dr) {       mij = (st + dr) / 2;       if (sum2[mij] <= x) {         if (sum2[mij] == x) {           sol = mij;         }         st = mij + 1;       } else {         dr = mij - 1;       }     }     return sol;   }   bool compare(wow a, wow b) {     if (a.st / bucket != b.st / bucket) {       return a.st < b.st;     }     return a.dr < b.dr;   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> x;       if (x == 1) {         val[i] = 1;       } else {         val[i] = -1;       }     }     for (i = 1; i <= n; i++) {       cin >> x;       v[i] = x * val[i];     }     for (i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + v[i];     }     for (i = 0; i <= n; i++) {       mp[sum[i] - k] = mp[sum[i]] = mp[sum[i] + k] = 0;     }     nr = 0;     for (auto &a : mp) {       a.second = ++nr;     }     for (i = 0; i <= n; i++) {       fr[i] = mp[sum[i] - k];       fr2[i] = mp[sum[i]];       fr3[i] = mp[sum[i] + k];     }     cin >> m;     for (i = 1; i <= m; i++) {       cin >> a[i].st >> a[i].dr;       a[i].st--;       a[i].poz = i;     }     bucket = 300;     sort(a + 1, a + m + 1, compare);     st = 0;     dr = -1;     s = 0;     for (i = 1; i <= m; i++) {       stcur = a[i].st;       drcur = a[i].dr;       while (st > stcur) {         st--;         s = s + frec[fr3[st]];         frec[fr2[st]]++;       }       while (dr < drcur) {         dr++;         s = s + frec[fr[dr]];         frec[fr2[dr]]++;       }       while (st < stcur) {         frec[fr2[st]]--;         s = s - frec[fr3[st]];         st++;       }       while (dr > drcur) {         frec[fr2[dr]]--;         s = s - frec[fr[dr]];         dr--;       }       sol[a[i].poz] = s;     }     for (i = 1; i <= m; i++) {       cout << sol[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[200005], sum, cnt, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum += a[i];     }     for (int i = 1; i <= n; i += 2) cnt += a[i];     ans = cnt;     for (int i = 1; i < n; i++) {       cnt = sum - cnt + a[i];       ans = max(ans, cnt);     }     printf( %lld n , ans);   }