malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     string res =   ;     if (s.find( . ) == string::npos) {       s +=  . ;     }     int d = s.find( . );     int i = d - 1;     int c = 0;     while (i >= 0) {       if (s[i] !=  - ) res = s[i] + res;       c++;       if (c == 3 && i > 0) {         if (i - 1 >= 0 && s[i - 1] !=  - ) res =  ,  + res;         c = 0;       }       i--;     }     res +=  . ;     int dc = s.length() - 1 - d;     if (dc == 0) {       res +=  00 ;     } else if (dc == 1) {       res += s[d + 1];       res +=  0 ;     } else if (dc >= 2) {       res += s[d + 1];       res += s[d + 2];     }     res =  $  + res;     if (s[0] ==  - ) res =  (  + res +  ) ;     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int dp[505][505], dp2[505];   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (auto &i : a) cin >> i;     memset(dp, 0, sizeof(dp));     for (int i = 0; i < n; i++) dp[i][i] = a[i];     for (int i = 1; i < n; i++) {       for (int j = i - 1; j >= 0; j--) {         for (int k = i; k > j; k--) {           if (dp[k][i] and dp[k][i] == dp[j][k - 1]) dp[j][i] = dp[k][i] + 1;         }       }     }     memset(dp2, INT_MAX, sizeof(dp2));     for (int i = 0; i <= n; i++) dp2[i] = i + 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i; j++) {         if (dp[j][i]) {           if (j == 0)             dp2[i] = 1;           else             dp2[i] = min(dp2[i], dp2[j - 1] + 1);         }       }     }     cout << dp2[n - 1];   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MAXN = (int)1e5 + 5;   long long n;   const int bs = 350;   int a[MAXN];   int mp[600][MAXN];   vector<int> ls[1000];   void swp(int l, int r) {     int size = 0, i = 0;     vector<int> tmp1, tmp2;     for (i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > r) {         break;       }       size += ls[i].size();     }     long long sayi = 0;     for (int j = 0; j < ls[i].size(); j++) {       mp[i][ls[i][j]] = 0;       if (j + size == r) {         sayi = ls[i][j];         continue;       }       tmp1.push_back(ls[i][j]);     }     ls[i].clear();     for (int j : tmp1) {       ls[i].push_back(j);       mp[i][j]++;     }     size = 0;     i = 0;     for (i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > l) {         break;       }       size += ls[i].size();     }     if (l == n - 1) {       ls[(l / bs)].push_back(sayi);       mp[l / bs][sayi]++;       return;     }     for (int j = 0; j < ls[i].size(); j++) {       mp[i][ls[i][j]] = 0;       if (j + size == l) {         tmp2.push_back(sayi);       }       tmp2.push_back(ls[i][j]);     }     ls[i].clear();     for (int j : tmp2) {       ls[i].push_back(j);       mp[i][j]++;     }   }   long long get(long long ind, long long k) {     if (ind < 0) return 0;     long long ans = 0;     int size = 0;     int yer;     for (int i = 0; i <= (n - 1) / bs; i++) {       if (size + ls[i].size() > ind) {         yer = i;         break;       }       size += ls[i].size();       ans += mp[i][k];     }     for (int i = 0; i + size <= ind; i++) {       ans += (ls[yer][i] == k);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       ls[i / bs].push_back(a[i]);       mp[i / bs][a[i]]++;     }     int lastans = 0;     int q;     cin >> q;     for (int i = 0; i < q; i++) {       if (i % bs == 0) {         vector<int> tmp;         for (int i = 0; i <= (n - 1) / bs; i++) {           for (auto j = ls[i].begin(); j < ls[i].end(); j++) {             tmp.push_back(*j);             mp[i][*j] = 0;           }         }         for (int j = 0; j < n; j++) {           if (j % bs == 0) {             ls[j / bs].clear();           }           mp[j / bs][tmp[j]]++;           ls[j / bs].push_back(tmp[j]);         }       }       int a;       cin >> a;       if (a == 1) {         int l, r;         cin >> l >> r;         l = (l + lastans - 1 + n) % n;         r = (r + lastans - 1 + n) % n;         if (l > r) swap(l, r);         swp(l, r);       } else {         int l, r, k;         cin >> l >> r >> k;         l = (l + lastans - 1 + n) % n;         r = (r + lastans - 1 + n) % n;         k = 1 + (k + lastans - 1 + n) % n;         if (l > r) swap(l, r);         lastans = get(r, k) - get(l - 1, k);         cout << lastans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string name;     int counter = 0;     cin >> name;     for (int i = 0; i < name.length() / 2; i++) {       if (name[i] != name[name.length() - 1 - i]) counter++;     }     if (name.length() % 2 == 0) {       if (counter == 1)         cout <<  YES n ;       else         cout <<  NO n ;     } else {       if (counter == 1 || counter == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b,                    long long mod = (long long)(1e9 + 7)) {     if (!b) return 1;     a %= mod;     return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxn = 1100;   char string1[mxn];   char string2[mxn];   int xt1[mxn], xt2[mxn], xt3[mxn];   int bound[mxn];   int n, m;   void solution() {     long long answer = 0;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) {       scanf( %s , string2);       long long composite = 0;       for (int j = 0; j < m; j++) {         if (string2[j] != string1[j]) {           xt1[j] = xt2[j];           xt2[j] = xt3[j];           xt3[j] = 1;         } else {           xt3[j]++;         }         if (j > 0) {           if (string2[j] == string2[j - 1])             bound[j]++;           else             bound[j] = 0;         }         if (xt1[j] >= xt2[j] && xt2[j] == xt3[j]) {           composite++;           if (bound[j] < xt3[j] * 3) composite = 1;         } else           composite = 0;         string1[j] = string2[j];         answer += composite;       }     }     cout << answer << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solution();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7)         cout <<  1  << endl;       else if (n % 7 == 1)         cout << ((n - 1) / 7) + 1 << endl;       else         cout << (n / 7) + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e5 + 5;   struct edge {     int u, v;     ll w;     edge(int u, int v, ll w) : u(u), v(v), w(w) {}   };   int n, m, k, closestP[N], par[N];   ll d[N], res;   bool is1portal;   vector<int> portal;   vector<edge> adj[N], edges;   int root(int v) { return (par[v] < 0) ? v : (par[v] = root(par[v])); }   void join(int x, int y) {     if ((x = root(x)) == (y = root(y))) return;     if (par[x] > par[y]) swap(x, y);     par[x] += par[y];     par[y] = x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       adj[u].emplace_back(u, v, w);       adj[v].emplace_back(v, u, w);     }     cin >> k;     for (int i = 1; i <= k; ++i) {       int p;       cin >> p;       portal.emplace_back(p);       if (p == 1) is1portal = true;     }     priority_queue<pair<ll, pair<int, int>>> q;     for (int i = 1; i <= n; ++i) d[i] = 1e18;     for (int p : portal) q.push({d[p] = 0, {p, p}});     while (!q.empty()) {       int u = q.top().second.first;       int p = q.top().second.second;       q.pop();       if (closestP[u]) continue;       closestP[u] = p;       for (edge e : adj[u]) {         if (d[e.v] > d[u] + e.w) {           d[e.v] = d[u] + e.w;           q.push({-d[e.v], {e.v, p}});         }       }     }     for (int u = 1; u <= n; ++u) {       for (edge e : adj[u]) {         edges.emplace_back(closestP[u], closestP[e.v], d[u] + d[e.v] + e.w);       }     }     sort(edges.begin(), edges.end(),          [](const edge &x, const edge &y) { return x.w < y.w; });     for (int i = 1; i <= n; ++i) par[i] = -1;     for (edge e : edges) {       if (root(e.u) != root(e.v)) {         join(e.u, e.v);         res += e.w;       }     }     if (!is1portal) res += d[1];     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<long long> a(n);     long long sums = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sums += a[i];     }     if (sums % 2 == 0) {       long long maxs = -1;       for (long long i = 0; i < n; i++) {         if (a[i] > maxs) maxs = a[i];       }       if (maxs > sums - maxs) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     } else {       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   string t;   map<string, int> mp;   int solve(int l, int r) {     int val = 0;     for (int i = r - 1; i >= l; i--) {       if (t[i] ==  ( ) val++;       if (t[i] ==  ) ) val--;       if (!val && (t[i] ==  +  || t[i] ==  - )) {         int L = solve(l, i);         int R = solve(i + 1, r);         if (L && R && (t[i] ==  +  || R > 1))           return 1;         else           return 0;       }     }     for (int i = r - 1; i >= l; i--) {       if (t[i] ==  ( ) val++;       if (t[i] ==  ) ) val--;       if (!val && (t[i] ==  *  || t[i] ==  / )) {         int L = solve(l, i);         int R = solve(i + 1, r);         if (L > 1 && R > 1 && (t[i] ==  *  || R > 2))           return 2;         else           return 0;       }     }     string x = t.substr(l, r - l);     if (t[l] ==  ( ) {       if (solve(l + 1, r - 1)) return 3;       return 0;     }     if (mp.count(x)) return mp[x];     return 3;   }   int Get() {     string tmp;     getline(cin, tmp);     int len = tmp.length();     t =   ;     for (int i = 0; i < len; i++)       if (tmp[i] !=    ) t += tmp[i];     return solve(0, t.length());   }   int main() {     scanf( %d , &n);     string s;     for (int i = 1; i <= n; i++) {       scanf(  #%*s );       cin >> s;       mp[s] = Get();     }     if (Get())       puts( OK );     else       puts( Suspicious );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   template <class T, class Comp = less<T> >   struct monoqueue {     deque<pair<T, int> > dq;     Comp comp;     int left, right;     bool one_index;     monoqueue(bool ind1)         : dq(), comp(), left(ind1), right(ind1), one_index(ind1) {}     void push(T t) {       while (!dq.empty() && comp(t, dq.back().first)) {         dq.pop_back();       }       dq.push_back(make_pair(t, right++));     }     template <class Iterator>     void push(Iterator i, Iterator j) {       for (; i != j; i++) {         push(*i);       }     }     void pop() {       assert(!empty());       if (dq.front().second == left) {         dq.pop_front();       }       left++;     }     T get() {       assert(!empty());       return dq.front().first;     }     int getind() {       assert(!empty());       return dq.front().second;     }     int size() { return right - left; }     bool empty() { return left == right; }     void clear() {       dq.clear();       left = right = 0;     }   };   int N, S, L;   int arr[MAXN];   int upto[MAXN];   monoqueue<int> dqmin(true);   monoqueue<int, greater<int> > dqmax(true);   int dp[MAXN];   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios_base::sync_with_stdio(false);     cin >> N >> S >> L;     for (int i = 1; i <= N; i++) {       cin >> arr[i];     }     for (int i = 1; i <= N; i++) {       dqmin.push(arr[i]);       dqmax.push(arr[i]);       while (!dqmin.empty() && dqmax.get() - dqmin.get() > S) {         dqmin.pop();         dqmax.pop();       }       int m = dqmin.left;       if (m >= i - L + 2) {         m = i - L + 2;       }       upto[i] = m;     }     fill_n(dp + 1, N, MAXN);     dqmin.clear();     for (int i = L; i <= N; i++) {       dqmin.push(dp[i - L]);       while (dqmin.left < upto[i] - 1) {         dqmin.pop();       }       if (dqmin.empty() || dqmin.get() == MAXN) {         dp[i] = MAXN;       } else {         dp[i] = dqmin.get() + 1;       }     }     int ans = dp[N];     cout << (ans == MAXN ? -1 : ans) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   bool good[N], need[N];   int n;   void ask(vector<int> &v) {     printf( %d , (int)v.size());     for (int i = 0; i < (int)v.size(); i++) {       printf(  %d , v[i]);       good[v[i]] = true;     }     puts(  );     fflush(stdout);     int idx;     scanf( %d , &idx);     for (int i = 0; i < (int)v.size(); i++) {       good[idx] = false;       idx++;       if (idx > n) idx = 1;     }   }   int main() {     scanf( %d , &n);     if (n <= 3) {       puts( 0 );       fflush(stdout);       return 0;     }     int cur, best = 0, k;     for (int sz = 1; sz < n; sz++) {       cur = ((n + sz) / (sz + 1));       cur = n - cur - sz;       if (cur > best) {         best = cur;         k = sz;       }     }     for (int i = 1; i < n; i += k + 1) {       for (int j = i; j < min(n, i + k); j++) need[j] = true;     }     vector<int> v;     while (true) {       cur = 0;       for (int l = 1; l <= n; l++)         if (good[l]) cur++;       if (cur >= best) break;       v.clear();       for (int i = 1; i <= n; i++) {         if (need[i] && !good[i]) v.push_back(i);       }       ask(v);     }     puts( 0 );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a1, a2, b1, b2, c1, c2;   struct Point {     long long x, y;     Point(long long x = 0, long long y = 0) : x(x), y(y) {}   };   int exgcd(int a, int b, int& x, int& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     int d = exgcd(b, a % b, x, y);     int t = x;     x = y;     y = t - a / b * y;     return d;   }   int dcmp(int x) {     if (x == 0) return 0;     return x < 0 ? -1 : 1;   }   Point operator+(const Point& a, const Point& b) {     return Point(a.x + b.x, a.y + b.y);   }   Point ans[5];   int main() {     scanf( %lld %lld %lld %lld %lld %lld , &a1, &a2, &b1, &b2, &c1, &c2);     ans[1] = Point(b1 - a1, b2 - a2);     ans[2] = Point(b1 - a2, b2 + a1);     ans[3] = Point(b1 + a1, b2 + a2);     ans[4] = Point(b1 + a2, b2 - a1);     if (c1 == 0 && c2 == 0) {       for (int i = 1; i <= 4; i++)         if (ans[i].x == 0 && ans[i].y == 0) {           printf( YES n );           return 0;         }       printf( NO n );       return 0;     }     for (int i = 1; i <= 4; i++) {       long long t1, t2;       if ((c1 * ans[i].x + c2 * ans[i].y) % (c1 * c1 + c2 * c2) != 0) continue;       t1 = (c1 * ans[i].x + c2 * ans[i].y) / (c1 * c1 + c2 * c2);       if ((c2 * ans[i].x - c1 * ans[i].y) % (c1 * c1 + c2 * c2) != 0) continue;       t2 = (c2 * ans[i].x - c1 * ans[i].y) / (c1 * c1 + c2 * c2);       printf( YES n );       return 0;     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n, ans, x = 201, y = 201, u[405][405];   int main() {     scanf( %d , &n);     cin >> s;     for (int i = 0; i < n; ++i) {       ans += u[x][y];       ++u[x][y];       if (s[i] ==  U ) ++x;       if (s[i] ==  D ) --x;       if (s[i] ==  R ) ++y;       if (s[i] ==  L ) --y;     }     ans += u[x][y];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, const T& b) {     return a > b ? a = b, true : false;   }   template <class T>   bool umax(T& a, const T& b) {     return a < b ? a = b, true : false;   }   template <long long sz>   using tut = array<long long, sz>;   void usaco(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 2e5 + 5;   const long long mod = (119 << 23) + 1;   const long long inf = LLONG_MAX;   const long double Pi = acos(-1);   void add(long long& a, long long b, long long mod = ::mod) {     a = (a + b) % mod;   }   void sub(long long& a, long long b, long long mod = ::mod) {     a = ((a - b) % mod + mod) % mod;   }   void mul(long long& a, long long b, long long mod = ::mod) {     a = (a * 1ll * b) % mod;   }   long long n, m, k, t, q, ans, res, a[N];   long long rr[N];   void solve(long long t_case) {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     auto check2 = [&](long long b, long long a) -> long long {       return (a - 3ll * b * b - 1);     };     auto check = [&](long long mm) -> bool {       long long cnt = 0;       for (long long i = 1; i <= n; i++) {         long long l = 0, r = a[i];         while (l < r) {           long long m = (l + r + 1) >> 1;           if (check2(m, a[i]) >= mm)             l = m;           else             r = m - 1;         }         rr[i] = l;         cnt += l;       }       return (cnt >= k);     };     long long l = -inf, r = inf;     while (l < r) {       long long m = (l + r + 1) >> 1;       if (check(m))         l = m;       else         r = m - 1;     }     check(l);     long long cnt = 0;     for (long long i = 1; i <= n; i++) cnt += rr[i];     cnt -= k;     for (long long i = 1; i <= n && cnt; i++) {       if (rr[i] && check2(rr[i], a[i]) == l) cnt--, rr[i]--;     }     for (long long i = 1; i <= n; i++) cout << rr[i] <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (0) {       long long t;       cin >> t;       for (long long t_case = 1; t_case <= t; t_case++) solve(t_case);     } else       solve(1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, val, sum = 0;     cin >> n;     vector<long long> v, q;     for (long long i = 0; i < n; i++) {       cin >> val;       v.push_back(val);       sum += val;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     cin >> m;     for (long long i = 0; i < m; i++) {       cin >> val;       cout << sum - v[val - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct vt {     int p;     int a;     int b;   };   int main() {     int n, index;     cin >> n;     int a[n + 5], b[200005];     for (int i = 1; i < 200005; i++) {       b[i] = 0;     }     int maxd = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]]++;     }     for (int i = n; i >= 1; i--) {       if (maxd < b[a[i]]) {         maxd = b[a[i]];         index = i;       }     }     if (maxd == n)       cout <<  0 ;     else if (maxd == 1) {       int u = 0;       vt x[n + 5];       for (int i = 2; i <= n; i++) {         if (a[i] == a[i - 1]) continue;         if (a[i] > a[i - 1]) {           x[u].p = 2;           x[u].a = i;           x[u].b = i - 1;           u++;           a[i] = a[i - 1];         } else if (a[i] < a[i - 1]) {           x[u].p = 1;           x[u].a = i;           x[u].b = i - 1;           u++;           a[i] = a[i - 1];         }       }       cout << u << endl;       for (int i = 0; i < u; i++) {         cout << x[i].p <<     << x[i].a <<     << x[i].b << endl;       }     } else {       int u = 0;       vt x[n + 5];       for (int i = index - 1; i >= 1; i--) {         if (a[i] == a[i + 1]) continue;         if (a[i] > a[i + 1]) {           x[u].p = 2;           x[u].a = i;           x[u].b = i + 1;           u++;           a[i] = a[i + 1];         } else if (a[i] < a[i + 1]) {           x[u].p = 1;           x[u].a = i;           x[u].b = i + 1;           u++;           a[i] = a[i + 1];         }       }       for (int i = index + 1; i <= n; i++) {         if (a[i] == a[i - 1]) continue;         if (a[i] > a[i - 1]) {           x[u].p = 2;           x[u].a = i;           x[u].b = i - 1;           u++;           a[i] = a[i - 1];         } else if (a[i] < a[i - 1]) {           x[u].p = 1;           x[u].a = i;           x[u].b = i - 1;           u++;           a[i] = a[i - 1];         }       }       cout << u << endl;       for (int i = 0; i < u; i++) {         cout << x[i].p <<     << x[i].a <<     << x[i].b << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   bitset<300000010> su;   int main() {     su[1] = 1;     int l, r, ans = 0;     cin >> l >> r;     if (l < 3 && r > 1) ans++;     for (int i = 3; i * i <= r; i += 2)       if (!su[i])         for (long long j = 1LL * i * i; j <= r; j += i << 1) su[j] = 1;     while (l % 4 != 1) l++;     for (int i = l; i <= r; i += 4)       if (!su[i]) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int power(long long x, unsigned int y, int p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     long long n, p;     cin >> n >> p;     cout << (power(3, n, p) * 1ll + p * 1ll - 1ll) % p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   string s1, s2;   int n, m;   long long dp[maxn][3][3];   int p1[maxn], p2[maxn];   int f(char a) { return a ==  G  ? 0 : (a ==  R  ? 1 : 2); }   void init(const string s, int n, const string t, int m, int p[]) {     p[0] = 0;     while (p[0] < m && s[0] != t[p[0]]) p[0]++;     p[0] = min(p[0], m - 1);     for (int i = 1; i < n; i++) {       p[i] = p[i - 1] + 1;       while (p[i] < m && s[i] != t[p[i]]) p[i]++;       p[i] = min(p[i], m - 1);     }   }   int main() {     cin >> s1;     cin >> s2;     n = s1.size();     m = s2.size();     init(s1, n, s2, m, p1);     init(s2, m, s1, n, p2);     memset(dp, 0ll, sizeof(dp));     for (int i = 1; i < m; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           if (f(s2[i - 1]) == j && f(s2[i]) == k)             dp[i][j][k] = dp[i - 1][j][k] + 1;           else             dp[i][j][k] = dp[i - 1][j][k];         }       }     }     long long ret = 0;     int l = 0, r;     for (int i = 0; i < n; i++) {       r = p1[i];       while (l < m && p2[l] < i) l++;       ret += max(r - l + 1, 0);       if (i && l <= r) {         int j = f(s1[i - 1]), k = f(s1[i]);         if (j != k) {           ret -= dp[r][k][j];           if (l - 1 >= 0) ret += dp[l - 1][k][j];         }       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int house[300010];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a, b, c, d;     for (int i = 0; i < n; ++i) cin >> house[i];     a = house[0];     d = house[n - 1];     if (a != d) {       cout << n - 1 << endl;       return 0;     }     int i = 0;     while (house[++i] == a)       ;     int j = n;     while (house[--j] == d)       ;     cout << max(n - i - 1, j + 1 - 1) << endl;   }