malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     map<int, long long> sale;     map<int, long long> buy;     for (int i = 0; i < n; i++) {       char c;       cin >> c;       if (c ==  B ) {         int price, num;         cin >> price >> num;         buy[price] += num;       } else {         int price, num;         cin >> price >> num;         sale[price] += num;       }     }     auto itb = sale.begin();     stack<pair<long long, long long>> answ;     for (int i = 0; i < min(int(sale.size()), s); i++) {       answ.push((*itb));       itb++;     }     while (!answ.empty()) {       cout <<  S             <<     << answ.top().first <<     << answ.top().second << endl;       answ.pop();     }     auto its = buy.end();     for (int i = 0; i < min(int(buy.size()), s); i++) {       its--;       cout <<  B  <<     << (*its).first <<     << (*its).second << endl;     }     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[1001];     int m[26];     while (gets(s)) {       memset(m, 0, sizeof(m));       int len = strlen(s);       int dan = 0, shuang = 0;       for (int i = 0; i < len; i++) m[s[i] -  a ]++;       for (int i = 0; i < 26; i++)         if (m[i]) {           if (m[i] % 2 == 0) shuang++;           if (m[i] % 2) dan++;         }       if ((dan == 0) || (dan % 2))         printf( First n );       else         printf( Second n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxi = 1e18;   long long prime[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};   long long dp[15][1005], mi[15][1005], ans;   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     for (int i = 1; i <= 10; i++) {       mi[i][0] = 1;       for (int j = 1; j <= 1000; j++) {         long long temp;         bool flag = __builtin_mul_overflow(mi[i][j - 1], prime[i], &temp);         if (!flag)           mi[i][j] = mi[i][j - 1] * prime[i];         else           mi[i][j] = maxi;       }     }     int n;     cin >> n;     for (int i = 1; i <= 10; i++) {       for (int j = 1; j <= n; j++) dp[i][j] = maxi;     }     for (int i = 1; i <= n; i++) dp[1][i] = mi[1][i - 1];     for (int i = 2; i <= 10; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= j; k++) {           if (j % k == 0) {             long long temp;             bool flag =                 __builtin_mul_overflow(dp[i - 1][j / k], mi[i][k - 1], &temp);             if (!flag) dp[i][j] = min(dp[i][j], dp[i - 1][j / k] * mi[i][k - 1]);           }         }       }     }     cout << dp[10][n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > white, black;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int c, s;       cin >> c >> s;       if (c) {         black.push_back(make_pair(s, i + 1));       } else {         white.push_back(make_pair(s, i + 1));       }     }     sort(black.begin(), black.end());     sort(white.begin(), white.end());     int p_b = 0, p_w = 0;     while (p_b < black.size() && p_w < white.size()) {       cout << black[p_b].second <<     << white[p_w].second <<    ;       if (black[p_b].first < white[p_w].first) {         cout << black[p_b].first << endl;         pair<int, int>& p = white[p_w];         p.first -= black[p_b].first;         p_b++;       } else {         cout << white[p_w].first << endl;         pair<int, int>& p = black[p_b];         p.first -= white[p_w].first;         p_w++;       }     }     if (p_b < black.size()) {       p_b++;       while (p_b < black.size()) {         cout << white[0].second <<     << black[p_b++].second <<   0  << endl;       }     }     if (p_w < white.size()) {       p_w++;       while (p_w < white.size()) {         cout << black[0].second <<     << white[p_w++].second <<   0  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1 << 61;   int main() {     long long n, m;     cin >> n >> m;     pair<long long, long long> first, last;     bool was = false;     vector<vector<char>> v(n, vector<char>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> v[i][j];         if (v[i][j] ==  B  && !was) {           first = {i, j};           was = true;         }         if (v[i][j] ==  B ) {           last = {i, j};         }       }     }     cout << (first.first + last.first) / 2 + 1 <<              << (first.second + last.second) / 2 + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum[200000 + 5];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , sum + i);       sum[i] += i;     }     sort(sum, sum + n);     for (int i = 1; i < n; ++i) {       if (sum[i] == sum[i - 1]) {         printf( :( n );         return 0;       }     }     for (int i = 0; i < n; ++i) {       printf( %d  , sum[i] - i);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-11;   int vex[4] = {1, 0, -1, 0};   int vey[4] = {0, 1, 0, -1};   long long int MOD = 1000000007;   const int MAX = 3000000;   string c[100005];   char s[MAX];   int main() {     int n;     cin >> n;     using p = pair<int, pair<int, int>>;     using po = pair<int, int>;     vector<p> d;     for (int i = 0; i < (MAX); i++) s[i] =  * ;     int last = 0;     int a, b;     for (int i = 0; i < (n); i++) {       cin >> c[i];       int t = c[i].size();       cin >> a;       for (int j = 0; j < (a); j++) {         cin >> b;         b--;         d.push_back(p(b, po(b + t, i)));       }     }     sort(d.begin(), d.end());     int in = d.size();     for (int j = 0; j < (in - 1); j++) {       auto l = d[j];       auto r = d[j + 1];       if (l.first == r.first) continue;       for (int k = max(l.first, last); k < l.second.first; k++) {         s[k] = c[l.second.second][k - l.first];       }       last = max(l.second.first, last);     }     auto l = d[in - 1];     for (int k = l.first; k < l.second.first; k++) {       s[k] = c[l.second.second][k - l.first];     }     string ans =   ;     int la = 0;     for (int i = (MAX)-1; i >= 0; i--) {       if (s[i] !=  * ) {         la = i;         break;       }     }     for (int i = 0; i < (la + 1); i++) {       if (s[i] ==  * )         cout <<  a ;       else         cout << s[i];     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int a, b, n;     vector<int> div;     cin >> a >> b >> n;     if (b > a) swap(a, b);     for (int d = 1; d * d <= b; d++) {       if (a % d == 0 and b % d == 0) div.push_back(d);       int d2 = -1;       if (b % d == 0 and b / d != d) d2 = b / d;       if (d2 != -1)         if (a % d2 == 0) div.push_back(d2);     }     sort(div.begin(), div.end());     while (n--) {       int l, r;       cin >> l >> r;       auto it = upper_bound(div.begin(), div.end(), r);       it--;       if (l <= *it and *it <= r)         cout << *it << endl;       else         cout <<  -1 n ;     }   }
#include <bits/stdc++.h>   using namespace std;   multiset<int> s;   multiset<int>::iterator itr;   int c[5], tot;   int get_ty(int x) {     if (c[2] >= x)       return 1;     else if (c[1] + c[2] >= x)       return 2;     else if (c[0] + c[1] + c[2] >= x)       return 3;     else       return 4;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < 3; i++) scanf( %d , &c[i]);     for (int i = 0; i < 3; i++) tot += c[i];     sort(c, c + 3);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       s.insert(t);     }     int res = 0;     bool isok = 0, flag = 0;     while (!s.empty()) {       int mm = *(--s.end());       if (!flag) {         int ty = get_ty(mm);         if (ty == 4) break;         if (ty == 3)           s.erase(--s.end());         else if (ty == 2) {           s.erase(--s.end());           int loc = 0;           for (int i = 0; i < 3; i++)             if (tot - c[i] >= mm) loc = i;           itr = s.upper_bound(c[loc]);           if (itr != s.begin()) s.erase(--itr);         } else if (ty == 1)           flag = 1;       }       if (flag) {         int loc = 0;         for (int i = 2; i >= 0; i--)           if (c[i] >= mm) loc = i;         s.erase(--s.end());         itr = s.upper_bound(c[loc == 0]);         bool dbk = 1;         if (itr == s.begin())           dbk = 0;         else {           int tt = *(--itr);           s.erase(itr);           itr = s.upper_bound(c[1 + (loc <= 1)]);           if (itr == s.begin()) {             s.insert(tt);             dbk = 0;           }         }         if (dbk)           s.erase(--itr);         else {           itr = s.upper_bound(tot - c[loc]);           if (itr != s.begin()) s.erase(--itr);         }       }       isok = 1;       res++;     }     if (!isok)       printf( -1 n );     else       printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ret[70];   long long qpow(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a;       a = a * a;       n >>= 1;     }     return ret;   }   void solve() {     ret[0] = 1;     for (long long i = 1; i < 64; i++) {       ret[i] = ret[i - 1] + qpow(2, i);     }   }   vector<long long> res;   void getans() {     for (long long i = 0; i < 64; i++) {       long long tmp = qpow(2, i);       for (long long j = i + 1; j < 64; j++) {         res.push_back(ret[j] - tmp);       }     }   }   int main() {     solve();     getans();     long long a, b;     cin >> a >> b;     sort(res.begin(), res.end());     long long pos1 = upper_bound(res.begin(), res.end(), a) - res.begin();     long long pos3 = lower_bound(res.begin(), res.end(), a) - res.begin();     long long pos2 = upper_bound(res.begin(), res.end(), b) - res.begin();     long long pos4 = lower_bound(res.begin(), res.end(), b) - res.begin();     long long ans = pos2 - pos1;     if (pos3 < pos1) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2501;   int dp[N][3], a[N << 1];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = dp[1][1] = 0;     for (int i = 2; i <= n; i++)       for (int j = i + 1 >> 1; j; j--) {         dp[j][0] = min(dp[j][0], dp[j][2]);         dp[j][2] = dp[j][1] + max(0, a[i] - a[i - 1] + 1);         dp[j][1] =             min(dp[j - 1][0] + max(0, a[i - 1] - a[i] + 1),                 dp[j - 1][2] + max(0, min(a[i - 1], a[i - 2] - 1) - a[i] + 1));       }     for (int j = 1; j <= n + 1 >> 1; j++)       cout << min(dp[j][0], min(dp[j][1], dp[j][2])) <<    ;   }
#include <bits/stdc++.h>   const long long mod = (long long)(1e9 + 7);   int n;   long long s, ans;   long long f[1000];   long long ksm(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y = y / 2;     }     return ans;   }   long long Lucas(long long n, long long m) {     if (n < mod && m < mod) {       if (n < m) return 0;       if (n == m) return 1;       if (m == 0) return 1;       long long nj = 1, mj = 1;       long long a = n - m, b = m;       if (a > b) std::swap(a, b);       long long i = b + 1;       while (i <= n) {         nj = (nj * i) % mod;         i++;       }       i = 2;       while (i <= a) {         mj = (mj * i) % mod;         i++;       }       return ksm(mj, mod - 2) * nj % mod;     }     return Lucas(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;   }   long long dle(long long x) { return (((1 & x) ^ 1) << 1) - 1; }   void dfs(int p, int l, long long sum) {     if (p == n + 1) {       ans = (ans + dle(l) * Lucas(s - sum + n - 1, n - 1)) % mod;       return;     }     dfs(p + 1, l, sum);     dfs(p + 1, l + 1, sum + f[p] + 1);     return;   }   int main() {     scanf( %d%I64d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %I64d , &f[i]);     ans = 0;     dfs(1, 0, 0);     printf( %I64d n , (ans % mod + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     int x, y, z, p = 0, i;     i = min(a, min(b, c));     i = n / i;     for (x = i; x >= 0; x--) {       for (y = 0; y <= i; y++) {         z = abs((n - (a * x + b * y)) / c);         if ((a * x + b * y + c * z) == n) {           p = max(p, x + y + z);         }       }     }     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long same(vector<pair<long long, int> > &x) {     int n = x.size();     return (x[n - 1].first + x[n - 2].first) - (x[0].first + x[1].first);   }   long long diff(vector<pair<long long, int> > &x, long long h) {     int n = x.size();     long long minx = min(x[0].first + x[1].first + h, x[1].first + x[2].first);     long long maxx =         max(x[n - 1].first + x[n - 2].first, x[0].first + x[n - 1].first + h);     return maxx - minx;   }   int main() {     int n, h;     cin >> n >> h;     vector<pair<long long, int> > a(n);     for (int i = 0; i < (int)(n); i++) {       long long tmp;       cin >> tmp;       a[i].first = tmp;       a[i].second = i;     }     sort(a.begin(), a.end());     long long h1 = same(a);     long long h2 = diff(a, h);     cout << min(h1, h2) << endl;     if (h1 < h2) {       for (int i = 0; i < (int)(n); i++) printf( %d  , 1);     } else {       int head = a[0].second;       for (int i = 0; i < (int)(n); i++) {         int ret = (i == head) ? 1 : 2;         printf( %d  , ret);       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string a, b;     cin >> a >> b;     vector<int> ans;     int l = 0, r = n - 1;     for (int i = 0; i < n; i++) {       if (!(i & 1)) {         if (a[l] == b[n - i - 1]) ans.push_back(1);         ans.push_back(max(l, r) - min(l, r) + 1);       } else {         if (a[l] != b[n - i - 1]) ans.push_back(1);         ans.push_back(max(l, r) - min(l, r) + 1);       }       swap(l, r);       if (r > l)         r--;       else         r++;     }     cout << ans.size() <<    ;     for (auto x : ans) cout << x <<    ;     cout <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int min1(long long int a) {     long long int mx = 0, mi = 10;     while (a) {       mx = max(mx, a % 10);       mi = min(mi, a % 10);       a /= 10;     }     return mi * mx;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int a, k;       cin >> a >> k;       long long int tem = min1(a);       while (--k && tem != 0) {         a = a + tem;         tem = min1(a);       }       cout << a << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long linf = LLONG_MAX;   const int MOD = 1000000007;   const int maxn = 1e5 + 10;   const int MAX = 2e4 + 10;   int _size[maxn], vis[maxn];   vector<int> sub;   vector<pair<int, int> > adj[maxn];   int n, k, a, b;   bool first(string second) {     string a = to_string(linf);     for (int i = 0; second[i]; i++) {       if (second[i] > a[i])         return 0;       else if (second[i] == a[i]) {         int j = i;         while (second[j] == a[j]) ++j;         if (second[j] > a[j]) return 0;         return 1;       }       return 1;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string str;     cin >> str;     if (str.size() == 19) {       if (first(str)) {         cout <<  long n ;         return 0;       } else {         cout <<  BigInteger n ;         return 0;       }     } else {       if (str.size() < 19) {         stringstream sin(str);         long long t = 0;         int h = 32767;         sin >> t;         if (t <= INT_MAX && t > h) {           cout <<  int n ;           return 0;         } else if (t > INT_MAX) {           cout <<  long n ;           return 0;         } else if (t <= h) {           int b = 127;           if (t <= b) {             cout <<  byte n ;             return 0;           } else {             cout <<  short n ;             return 0;           }         }       } else {         cout <<  BigInteger n ;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long OO = 1e9;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     map<int, int> mp;     vector<int> ans;     for (int i = 0; i < n; i++) {       if (mp[a[i]]) {         ans.push_back(i + 1);         mp.clear();       } else         mp[a[i]] = i + 1;     }     if (ans.size() == 0) {       cout << -1 << endl;       return 0;     }     printf( %d n , (int)ans.size());     int h = 1;     for (int i = 0; i < (int)ans.size(); i++) {       if (i + 1 == ans.size()) ans[i] = n;       printf( %d %d n , h, ans[i]);       h = ans[i] + 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     int res = 2e9;     for (int i = 0; i < m; i++) {       int r, l;       cin >> l >> r;       res = min(res, r - l + 1);     }     vector<int> vec(n, 0);     cout << res <<   n ;     for (int i = 0; i < n; i++) {       cout << i % res;       if (i != n - 1) cout <<    ;     }     return 0;   }
#include <bits/stdc++.h>   int i, j, n, m;   bool killed[200100], visited[200100];   int vlist[200100][3];   int ans[200100];   inline int myabs(int a) { return a < 0 ? -a : a; }   inline int sign(int a) { return a / myabs(a); }   struct G {     int ind[200100];     int last[200100 * 2], e[200100 * 2], e_num[200100 * 2];     int t;     void addE(int a, int b, int ee) {       t++;       last[t] = ind[a];       ind[a] = t;       e[t] = b;       e_num[t] = ee;     }   } g;   inline void gen_ans_for_i(int i, int j) {     if (vlist[i][0] == 1) {       ans[i] = vlist[i][1] > 0 ? 1 : 0;     } else {       if (myabs(vlist[i][1]) == j) {         ans[i] = vlist[i][1] > 0 ? 1 : 0;       } else {         ans[i] = vlist[i][2] > 0 ? 1 : 0;       }     }   }   bool dfs(int a, int fae) {     if (visited[a] || killed[a]) {       return true;     }     visited[a] = 1;     int i;     for (i = g.ind[a]; i; i = g.last[i]) {       if (g.e_num[i] != fae)         if (dfs(g.e[i], g.e_num[i])) {           if (!killed[a]) {             gen_ans_for_i(g.e_num[i], a);             killed[a] = true;           }         }     }     return killed[a];   }   void dfs2(int a, int fae) {     if (visited[a]) {       return;     }     visited[a] = 1;     int i;     for (i = g.ind[a]; i; i = g.last[i]) {       if (g.e_num[i] != fae)         if (!killed[g.e[i]]) {           killed[g.e[i]] = true;           gen_ans_for_i(g.e_num[i], g.e[i]);           dfs2(g.e[i], g.e_num[i]);         }     }     return;   }   int main() {     scanf( %d %d , &n, &m);     int a, b;     for (i = 1; i <= n; i++) {       scanf( %d , &j);       while (j--) {         scanf( %d , &a);         b = myabs(a);         vlist[b][0]++;         if (a < 0) {           vlist[b][vlist[b][0]] = -i;         } else {           vlist[b][vlist[b][0]] = i;         }       }     }     for (i = 1; i <= m; i++) {       if (vlist[i][0] == 1) {         killed[myabs(vlist[i][1])] = true;         if (vlist[i][1] < 0) {           ans[i] = 0;         } else {           ans[i] = 1;         }       } else if (vlist[i][0] == 2) {         a = myabs(vlist[i][1]);         b = myabs(vlist[i][2]);         if (sign(vlist[i][1]) * sign(vlist[i][2]) > 0) {           killed[a] = true;           killed[b] = true;           ans[i] = vlist[i][1] > 0 ? 1 : 0;         } else {           g.addE(a, b, i);           g.addE(b, a, i);         }       }     }     for (i = 1; i <= n; i++) {       if (!visited[i] && !killed[i]) {         dfs(i, 0);       }     }     memset(visited, 0, sizeof(visited));     for (i = 1; i <= n; i++) {       if (killed[i]) {         dfs2(i, 0);       }     }     for (i = 1; i <= n; i++) {       if (!killed[i]) {         printf( NO n );         return 0;       }     }     printf( YES n );     for (i = 1; i <= m; i++) {       printf( %d , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> str(1);   vector<int> ans(1);   int solve(const string& s) {     for (int len = 1; len <= 10; ++len) {       for (int opt = 0; opt < (1 << len); ++opt) {         bitset<10> bits(opt);         string tmpS(len,  0 );         for (int i = 0; i < len; ++i) {           tmpS[i] += bits[i];         }         if (s.find(tmpS) == string::npos) {           return len - 1;         }       }     }     return -1;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       char buff[256];       scanf( %s , buff);       str.push_back(buff);       ans.push_back(solve(str.back()));     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       str.push_back(str[a] + str[b]);       if (str.back().length() > 1000) {         str.back() = str.back().substr(0, 500) +                      str.back().substr(str.back().length() - 500, 500);       }       ans.push_back(max({solve(str.back()), ans[a], ans[b]}));       cout << ans.back() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   const int N = 300009;   const int INF = 1e9;   const long long INF64 = 1e18;   const double eps = 1e-9;   const int MOD = 1e9 + 7;   int n, q;   int a[N], f[N];   int sum(int pos) {     int res = 0;     for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res += f[i];     return res;   }   void upd(int pos, int d) {     for (int i = pos; i < n; i |= i + 1) f[i] += d;   }   int sum(int l, int r) { return sum(r) - sum(l - 1); }   int main() {     cin >> n >> q;     int l = 0, r = n - 1;     bool rev = false;     for (int i = 0; i < (int)(n); i++) {       a[i] = 1;       upd(i, 1);     }     for (int i = 0; i < (int)(q); i++) {       int type, p, nl, nr;       cin >> type;       if (type == 1) {         cin >> p;         int len = r - l + 1;         if (p * 2 <= len) {           if (rev) {             for (int i = r - p + 1, j = r - p; i <= r; ++i, --j) {               upd(j, a[i]);               upd(i, -a[i]);               a[j] += a[i];               a[i] = 0;             }             r -= p;           } else {             for (int i = l + p - 1, j = l + p; i >= l; --i, ++j) {               upd(j, a[i]);               upd(i, -a[i]);               a[j] += a[i];               a[i] = 0;             }             l += p;           }         } else {           if (rev) {             rev = false;             p = len - p;             for (int i = l + p - 1, j = l + p; i >= l; --i, ++j) {               upd(j, a[i]);               upd(i, -a[i]);               a[j] += a[i];               a[i] = 0;             }             l += p;           } else {             rev = true;             p = len - p;             for (int i = r - p + 1, j = r - p; i <= r; ++i, --j) {               upd(j, a[i]);               upd(i, -a[i]);               a[j] += a[i];               a[i] = 0;             }             r -= p;           }         }       } else {         cin >> nl >> nr;         --nr;         if (rev) {           int ee = nr;           nr = r - nl, nl = r - ee;           cout << sum(nl, nr) << endl;         } else {           nl = l + nl, nr = l + nr;           int xc = 0;           cout << sum(nl, nr) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 300005;   int n, c[MX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> c[i];     int res = 0, i = n - 1;     while (c[0] == c[i]) i--;     res = i;     i = 0;     while (c[i] == c[n - 1]) i++;     res = max(res, n - i - 1);     cout << res <<   n ;     return 0;   }