malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long> sp;   vector<pair<long long, long long>> bases;   int main() {     int s, b;     cin >> s >> b;     long long num, num2;     for (int i = 0; i < s; i++) {       cin >> num;       sp.push_back(num);     }     for (int i = 0; i < b; i++) {       cin >> num >> num2;       bases.push_back({num, num2});     }     sort(bases.begin(), bases.end());     long long sum[b + 5];     for (int i = 0; i < b; i++) {       sum[i] = bases[i].second;       if (i > 0) sum[i] += sum[i - 1];     }     for (int i = 0; i < s; i++) {       long long bas = 0;       long long start = 0, end = b, mid, idx = -1;       while (start <= end) {         mid = (start + end) / 2;         if (bases[mid].first <= sp[i]) {           idx = mid;           start = mid + 1;         } else {           end = mid - 1;         }       }       if (idx == b) idx--;       if (idx == -1)         cout <<  0  ;       else         cout << sum[idx] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const double pie = 3.14159265358979323846;   const char nl =   n ;   template <typename Type>   istream &operator>>(istream &in, vector<Type> &v) {     long long int n = v.size();     for (int i = 0; i < n; i++) in >> v[i];     return in;   }   template <typename Type>   ostream &operator<<(ostream &out, vector<Type> &v) {     for (auto value : v) out << value <<    ;     out << endl;     return out;   }   void solve() {     long long int n;     cin >> n;     vector<long long int> a(4 * n);     cin >> a;     sort(a.begin(), a.end());     long long int area = a[0] * a.back();     long long int c = 1, j = 4 * n - 1;     for (long long int i = 0; c <= n;) {       if (a[i] != a[i + 1] or a[j] != a[j - 1] or a[i] * a[j] != area) {         cout <<  No n ;         return;       }       ++c;       i += 2;       j -= 2;     }     cout <<  Yes n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N], fa[N], head[N], p, deep[N];   long long Chuan1[N], Chuan2[N], Ans;   queue<int> q;   struct wfh {     int to, last;   } d[N << 1];   inline void add(int a, int b) { d[++p] = (wfh){b, head[a]}, head[a] = p; }   inline long long max(long long A, long long B) { return A > B ? A : B; }   inline long long min(long long A, long long B) { return A < B ? A : B; }   void dfs(int u, int fa) {     for (int i = head[u], v; i; i = d[i].last) {       v = d[i].to;       if (v == fa) continue;       dfs(v, u);       Chuan1[u] = max(Chuan1[u], Chuan1[v]);       Chuan2[u] = max(Chuan2[u], Chuan2[v]);     }     a[u] += Chuan2[u] - Chuan1[u];     if (a[u] >= 0)       Chuan1[u] += a[u];     else       Chuan2[u] -= a[u];   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     dfs(1, -1);     printf( %lld n , Chuan1[1] + Chuan2[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111111];   int b[111111];   int main() {     int n, m, c;     scanf( %d%d%d , &n, &m, &c);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     for (int i = 1; i < m; i++) {       b[i] = (b[i] + b[i - 1]) % c;     }     for (int i = 0; i < n; i++) {       int f = max(0, m - (n - i));       int t = min(i, m - 1);       int s = b[t] - (f == 0 ? 0 : b[f - 1]);       s = (s % c + c) % c;       a[i] = (a[i] + s) % c;       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[22][1 << 18], b[22][1 << 18], c[1 << 18], ans[1 << 18];   int M1, M2, M3, M4, N1, N2;   int add(int x, int y) { return (x + y) & M1; }   int mult(int x, int y) {     int z = 0;     int xx = x & N1;     xx |= xx << 1;     z = xx & y;     xx = x & N2;     xx |= xx >> 1;     z ^= (xx & y) << 1;     return z & M1;   }   int zeta(int* a) {     int i, j, k;     for (i = 0; i < n; i++) {       if (i < 3) {         for (j = 0; j < (1 << max(n - 3, 0)); j++) {           if (i == 0)             a[j] = add(a[j], (a[j] & M2) << 4);           else if (i == 1)             a[j] = add(a[j], (a[j] & M3) << 8);           else             a[j] = add(a[j], (a[j] & M4) << 16);         }       } else {         for (j = 0; j < (1 << (n - 3)); j += (1 << (i - 2))) {           for (k = 0; k < (1 << (i - 3)); k++)             a[j ^ k ^ (1 << (i - 3))] = add(a[j ^ k ^ (1 << (i - 3))], a[j ^ k]);         }       }     }     return 0;   }   int main() {     int i;     scanf( %d n , &n);     for (i = 0; i < (1 << n); i++)       a[__builtin_popcount(i)][i >> 3] |= ((getchar() -  0 ) << ((i & 7) << 2));     getchar();     for (i = 0; i < (1 << n); i++)       b[__builtin_popcount(i)][i >> 3] |= ((getchar() -  0 ) << ((i & 7) << 2));     int j, k;     for (i = 0; i < 32; i++) {       if ((i & 3) < 2) M1 |= (1 << i);       if ((i & 7) < 4) M2 |= (1 << i);       if ((i & 15) < 8) M3 |= (1 << i);       if ((i & 31) < 16) M4 |= (1 << i);       if ((i & 3) == 0) N1 |= (1 << i);       if ((i & 3) == 1) N2 |= (1 << i);     }     for (i = 0; i <= n; i++) zeta(a[i]), zeta(b[i]);     for (i = 0; i <= n; i++) {       memset(c, 0, sizeof(c));       for (j = 0; j <= i; j++) {         for (k = 0; k < (1 << max(n - 3, 0)); k++)           c[k] = add(c[k], mult(a[j][k], b[i - j][k]));       }       for (j = 0; j < (1 << n); j++) {         if (__builtin_popcount(j) & 1) {           if (c[j >> 3] & (1 << ((j & 7) << 2)))             c[j >> 3] ^= (2 << ((j & 7) << 2));         }       }       zeta(c);       for (j = 0; j < (1 << n); j++) {         if (__builtin_popcount(j) & 1) {           if (c[j >> 3] & (1 << ((j & 7) << 2)))             c[j >> 3] ^= (2 << ((j & 7) << 2));         }         if (__builtin_popcount(j) == i)           ans[j >> 3] ^= c[j >> 3] & (3 << ((j & 7) << 2));       }     }     for (i = 0; i < (1 << n); i++)       printf( %d , (ans[i >> 3] >> ((i & 7) << 2)) & 3);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long score(long long a, long long b) {     if (a == b)       return 0;     else if ((a == 3 && b == 2) || (a == 2 && b == 1) || (a == 1 && b == 3))       return 1;     else       return 0;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long k, a, b, ca, cb, ncl, cl, csa, csb, pa, pb;     long long d[4][4][4] = {};     long long ch[4][4][4];     long long sc[100][2] = {};     cin >> k >> a >> b;     for (long long k = 1; k <= 2; k++)       for (long long i = 1; i <= 3; i++)         for (long long j = 1; j <= 3; j++) cin >> ch[i][j][k];     d[a][b][0] = 1;     d[a][b][1] = score(a, b);     d[a][b][2] = score(b, a);     sc[1][0] = score(a, b);     sc[1][1] = score(b, a);     ca = a;     cb = b;     while (true) {       long long na, nb;       na = ch[ca][cb][1];       nb = ch[ca][cb][2];       if (d[na][nb][0] == 0) {         d[na][nb][0] = d[ca][cb][0] + 1;         d[na][nb][1] = d[ca][cb][1] + score(na, nb);         d[na][nb][2] = d[ca][cb][2] + score(nb, na);         sc[d[na][nb][0]][0] = d[na][nb][1];         sc[d[na][nb][0]][1] = d[na][nb][2];         ca = na;         cb = nb;       } else {         ncl = d[na][nb][0] - 1;         cl = d[ca][cb][0] - d[na][nb][0] + 1;         csa = d[ca][cb][1] - d[na][nb][1] + score(na, nb);         csb = d[ca][cb][2] - d[na][nb][2] + score(nb, na);         break;       }     }     if (k <= ncl) {       pa = sc[k][0];       pb = sc[k][1];     } else {       long long km = (k - ncl) % cl;       pa = sc[ncl + km][0] + ((k - ncl) / cl) * csa;       pb = sc[ncl + km][1] + ((k - ncl) / cl) * csb;     }     cout << pa <<     << pb << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortin(const pair<long long int, long long int> &e,               const pair<long long int, long long int> &f) {     return (e.first < f.first);   }   long long int i, j, k, l, m, n, c, p, q, ts, mn = 10e17;   long long int a[200002], b[200002], x[200002];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     cin >> n;     cin >> m;     l = n - m;     string s, t, u, v;     cin >> s;     cin >> t;     v = s;     for (long long int i = 0; i <= n - 1; i++) u +=  a ;     for (long long int i = 0; i <= n - 1; i++) {       if (!l) break;       if (s[i] == t[i])         u[i] = s[i], v[i] =  . , l--;       else         u[i] =  a ;     }     if (l) {       for (long long int i = 0; i <= n - 1; i++) {         if (v[i] ==  . ) continue;         if (c % 2)           u[i] = s[i], v[i] =  . ;         else           u[i] = t[i], v[i] =  . ;         c++;         if (c % 2 == 0) l--;         if (!l) break;       }     }     if (l) {       cout << -1;       return 0;     }     for (long long int i = 0; i <= n - 1; i++) {       if (v[i] ==  . ) {         if (s[i] != u[i]) p++;         if (t[i] != u[i]) q++;         continue;       }       if (s[i] ==  a ) {         u[i] =  b ;         if (t[i] ==  b ) u[i] =  c ;       } else if (t[i] ==  a ) {         u[i] =  b ;         if (s[i] ==  b ) u[i] =  c ;       }       if (s[i] != u[i]) p++;       if (t[i] != u[i]) q++;     }     if (p != m || q != m) {       cout << -1;       return 0;     }     cout << u;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100000 + 10;   long long n, K, a[N], b[N];   struct Node {     long long v, id;   } p[N];   bool cmp(Node x, Node y) { return x.v > y.v; }   long long get(long long x, long long v) { return -3ll * (x * x + x) + v + 1; }   long long func(long long v, long long y) {     long long l = 0, r = v, mid, ret = 0;     while (l <= r) {       mid = (l + r) >> 1ll;       if (get(mid, v) >= y)         ret = mid, l = mid + 1;       else         r = mid - 1;     }     return ret;   }   long long calc(long long y) {     long long sum = 0;     for (long long i = 1; i <= n; ++i) sum += func(a[i], y);     return sum;   }   long long ans, sum;   void solve() {     long long l = -4e18, r = 1e18, mid;     while (l <= r) {       mid = (l + r) >> 1ll;       if (calc(mid) <= K)         ans = mid, r = mid - 1;       else         l = mid + 1;     }   }   signed main() {     scanf( %lld%lld , &n, &K);     for (long long i = 1; i <= n; ++i) scanf( %lld , &a[i]);     solve();     sum = 0;     for (long long i = 1; i <= n; ++i) {       b[i] = func(a[i], ans);       sum += b[i];       p[i].v = get(b[i], a[i]);       p[i].id = i;     }     sort(p + 1, p + n + 1, cmp);     for (long long i = 1; i <= n; ++i)       if (sum < K && a[p[i].id] > b[p[i].id]) sum++, b[p[i].id]++;     for (long long i = 1; i <= n; ++i) printf( %lld  , b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[6];   int main() {     for (int i = 0; i < 6; ++i) {       cin >> arr[i];     }     long long res = 0;     for (int i = 0; i < 3; ++i) {       res += arr[i];     }     res *= res;     for (int i = 0; i < 6; i += 2) {       res -= arr[i] * arr[i];     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   signed solve();   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int tests = 1;     while (tests--) solve();     return 0;   }   signed solve() {     int n, k;     cin >> n >> k;     if (n <= 1ll * k * (k - 1)) {       cout <<  YES n ;       for (int i = 0; i < n; ++i) {         cout << (i % k) + 1 <<     << (i / k + i % k + 1) % k + 1 <<   n ;       }     } else {       cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     os <<  { ;     string sep;     for (const T &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   const int MAX_N = 1e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e9;   const long double EPS = 1e-9;   void solve() {     string str;     cin >> str;     int len = ((int)str.size());     if (len & 1)       cout <<  NO  << endl;     else {       for (int i = 0; i < len / 2; ++i) {         if (str[i] != str[i + len / 2]) {           cout <<  NO  << endl;           return;         }       }       cout <<  YES  << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     cin >> tc;     for (int t = 1; t <= tc; t++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[123456];     int avg[123456];     for (int i = 0; i < n; i++) cin >> a[i];     long long count = 0;     for (int i = 0; i < n; i++) count += a[i];     int Max = count / n;     int rem = count % n;     long long c = 0;     for (int i = 0; i < n; i++) avg[i] = Max;     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       if (!rem) continue;       avg[i]++;       rem--;     }     for (int i = 0; i < n; i++)       if (a[i] > avg[i]) c += a[i] - avg[i];     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using std::min;   const int MAXL = 3000000 + 9, MAXM = 5000 + 9, M = 4194304;   int tr[M + M];   int ask(int k) {     int i;     for (i = 1; i < M;)       if (k > tr[i + i]) {         k -= tr[i + i];         i += i + 1;       } else         i += i;     return i - M;   }   void change(int u, int v) {     for (u += M; u; u >>= 1) tr[u] += v;   }   int l[MAXM], r[MAXM];   int fa[MAXL];   char s[MAXL], ans[MAXL];   int main() {     int k, m, i, j, t, tot;     int ll, rr, ori;     char *p;     scanf( %s%d%d , s + 1, &k, &m);     for (i = 1; i <= m; ++i) scanf( %d%d , l + i, r + i);     for (i = 1; i <= k; ++i) change(i, 1);     tot = k;     for (i = m; i; --i) {       if (r[i] + 1 > tot) continue;       ll = r[i] - l[i] + 1;       rr = min(tot, r[i] + ll);       for (j = 1; j <= rr - r[i]; ++j) {         m = ll >> 1;         ori = j <= m ? l[i] - 1 + j + j : l[i] - 2 + 2 * (j - m);         fa[t = ask(r[i] + 1)] = ask(ori);         change(t, -1);       }       tot -= rr - r[i];     }     p = s;     for (i = 1; i <= k; ++i) ans[i] = fa[i] ? ans[fa[i]] : *++p;     puts(ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int sn() {     int n = 0;     int ch = getchar();     while (ch < 48) ch = getchar();     while (ch > 47) n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     return n;   }   double dp[2005][2005];   int main() {     int i, j, n, t;     double p;     scanf( %d %lf %d , &n, &p, &t);     dp[0][0] = 1;     for (i = 1; i <= t; i++) {       dp[i][0] = pow(1 - p, i);       dp[i][n] = dp[i - 1][n] + dp[i - 1][n - 1] * p;       for (j = 1; j <= n - 1; j++) {         dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p;       }     }     double ans = 0;     for (i = 1; i <= n; i++) {       ans = ans + i * dp[t][i];     }     printf( %0.6lf  , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 3e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   long long dis[N];   vector<pair<long long, long long> > G[N];   int n, s, q;   void make(int C, int s, int e) {     if (s == e) {       G[C + n].push_back(make_pair(s, 0));       G[s].push_back(make_pair(C + n + 6 * n, 0));       return;     }     int m = (s + e) >> 1;     make(C * 2, s, m);     make(C * 2 + 1, m + 1, e);     G[C + n].push_back(make_pair(C * 2 + n, 0));     G[C + n].push_back(make_pair(C * 2 + 1 + n, 0));     G[C * 2 + n + 6 * n].push_back(make_pair(C + n + 6 * n, 0));     G[C * 2 + 1 + n + 6 * n].push_back(make_pair(C + n + 6 * n, 0));   }   void upd1(int C, int S, int E, int s, int e, int v, int w) {     if (s > E || e < S) return;     if (s <= S && E <= e) {       G[v].push_back(make_pair(C + n, w));       return;     }     int m = (S + E) >> 1;     upd1(C * 2, S, m, s, e, v, w);     upd1(C * 2 + 1, m + 1, E, s, e, v, w);   }   void upd2(int C, int S, int E, int s, int e, int v, int w) {     if (s > E || e < S) return;     if (s <= S && E <= e) {       G[C + n + 6 * n].push_back(make_pair(v, w));       return;     }     int m = (S + E) >> 1;     upd2(C * 2, S, m, s, e, v, w);     upd2(C * 2 + 1, m + 1, E, s, e, v, w);   }   priority_queue<pair<long long, long long> > P;   int main() {     scanf( %d%d%d , &n, &q, &s);     s--;     make(1, 0, n - 1);     for (int i = 0; i < q; ++i) {       int c;       scanf( %d , &c);       if (c == 1) {         int v, u, w;         scanf( %d%d%d , &v, &u, &w);         v--;         u--;         G[v].push_back(make_pair(u, w));       } else if (c == 2) {         int v, l, r, w;         scanf( %d%d%d%d , &v, &l, &r, &w);         v--;         l--;         r--;         upd1(1, 0, n - 1, l, r, v, w);       } else {         int v, l, r, w;         scanf( %d%d%d%d , &v, &l, &r, &w);         v--;         l--;         r--;         upd2(1, 0, n - 1, l, r, v, w);       }     }     for (int i = 0; i < N; ++i) dis[i] = INF;     dis[s] = 0;     P.push(make_pair(0, s));     while (!P.empty()) {       pair<long long, long long> nx = P.top();       P.pop();       nx.first = -nx.first;       if (dis[nx.second] < nx.first) continue;       for (int i = 0; i < G[nx.second].size(); ++i) {         long long cst = nx.first + G[nx.second][i].second;         int v = G[nx.second][i].first;         if (dis[v] > cst) {           dis[v] = cst;           P.push(make_pair(-cst, v));         }       }     }     for (int i = 0; i < n; ++i) {       if (dis[i] >= INF) dis[i] = -1;       printf( %lld%c , dis[i], (i + 1 == n) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e6;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, h;       cin >> h >> n;       long long arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       long long ans = 0, cp = h;       for (int i = 1; i < n; i++) {         if (cp == 0) break;         if (cp == (arr[i] + 1)) {           if ((i + 1) < n && cp == (arr[i + 1] + 2)) {             cp = arr[i + 1];             ++i;           } else {             if ((i + 1) < n) {               cp = arr[i + 1] + 1;               ++ans;             } else if (i == n - 1) {               if (cp == 2)                 continue;               else                 ++ans;             }           }         } else {           cp = arr[i] + 1;           --i;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 220000;   const int MAXM = 2 * MAXN;   const int MAXS = 26;   struct SAM {     struct Node {       int nxt[MAXS], par;       int len, siz;     } st[MAXM];     int m, root, lst;     inline int newNode(int l) {       int x = ++m;       memset(st[x].nxt, 0, sizeof st[x].nxt);       st[x].par = 0;       st[x].len = l;       st[x].siz = 0;       return x;     }     void extend(char c, bool k) {       int x = c -  a ;       int p = lst, np = newNode(st[p].len + 1);       lst = np;       st[np].siz = k;       while (p && !st[p].nxt[x]) st[p].nxt[x] = np, p = st[p].par;       if (!p) {         st[np].par = root;         return;       }       int q = st[p].nxt[x];       if (st[q].len == st[p].len + 1) {         st[np].par = q;         return;       }       int nq = newNode(st[p].len + 1);       memcpy(st[nq].nxt, st[q].nxt, sizeof st[q].nxt);       st[nq].par = st[q].par;       st[np].par = st[q].par = nq;       while (p && st[p].nxt[x] == q) st[p].nxt[x] = nq, p = st[p].par;     }     void build(int n, char* s, char* t) {       static int c[MAXN], d[MAXM];       m = 0;       lst = root = newNode(0);       for (int i = 0; i < n; i++) extend(s[i], t[i] ^  1 );       memset(c, 0, sizeof c);       for (int i = 1; i <= m; i++) c[st[i].len]++;       for (int i = 1; i <= n; i++) c[i] += c[i - 1];       for (int i = 1; i <= m; i++) d[c[st[i].len]--] = i;       for (int i = m; i >= 2; i--) st[st[d[i]].par].siz += st[d[i]].siz;     }     long long query() {       long long r = 0;       for (int i = 1; i <= m; i++) r = max(r, 1ll * st[i].len * st[i].siz);       return r;     }   } sam;   char s[MAXN], t[MAXN];   int main() {     int n;     scanf( %d , &n);     scanf( %s%s , s, t);     sam.build(n, s, t);     printf( %lld n , sam.query());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e6 + 100;   const long long inf = 0x3f3f3f3f;   const long long iinf = 1 << 30;   const long long linf = 2e18;   const long long mod = 998244353;   const double eps = 1e-7;   template <class T = long long>   T chmin(T &a, T b) {     return a = min(a, b);   }   template <class T = long long>   T chmax(T &a, T b) {     return a = max(a, b);   }   template <class T = long long>   inline void red(T &x) {     x -= mod, x += x >> 31 & mod;   }   template <class T = long long>   T read() {     T f = 1, a = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       a = (a << 3) + (a << 1) + ch -  0 ;       ch = getchar();     }     return a * f;   }   long long n, sqrt_n = 300;   long long ans, val;   long long a[maxn], cnt[maxn], sum[maxn], t[maxn], cnt1[maxn], cnt2[maxn];   vector<long long> pos;   void modify(long long x, long long pos) {     cnt2[cnt1[x]]--;     cnt1[x] += pos;     cnt2[cnt1[x]]++;   }   signed main() {     n = read();     for (long long i = (1); i <= (n); ++i) a[i] = read(), cnt[a[i]]++;     long long maxx = 0, tot = 0, val = 0;     for (long long i = (1); i <= (n); ++i) {       if (cnt[i] == maxx) tot++;       if (cnt[i] > maxx) tot = 1, maxx = cnt[i], val = i;     }     if (tot > 1) {       printf( %lld n , n);       return 0;     }     for (long long i = (1); i <= (n); ++i)       if (cnt[i] > sqrt_n && i != val) pos.push_back(i);     for (long long i : pos) {       for (long long j = (1); j <= (n); ++j)         sum[j] = sum[j - 1] + (a[j] == i ? -1 : (a[j] == val ? 1 : 0));       for (long long j = (-n); j <= (n); ++j) t[j + n] = linf;       t[n] = 0;       for (long long j = (1); j <= (n); ++j) {         if (t[sum[j] + n] != linf)           chmax(ans, j - t[sum[j] + n]);         else           t[sum[j] + n] = j;       }     }     for (long long i = (1); i <= (sqrt_n); ++i) {       for (long long j = (1); j <= (n); ++j) cnt1[j] = cnt2[j] = 0;       long long l = 1, r = 0;       while (r < n) {         modify(a[++r], 1);         while (cnt1[a[r]] > i) modify(a[l++], -1);         if (cnt2[i] >= 2) chmax(ans, r - l + 1);       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005], l = -1000000000, r = 1000000000;   string b;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     cin >> b;     for (int i = 4; i < n; ++i) {       if (b[i] ==  0  && b[i - 1] ==  1 ) {         int minim = a[i];         for (int j = i - 4; j < i; ++j) minim = min(minim, a[j]);         r = min(r, minim - 1);       } else if (b[i] ==  1  && b[i - 1] ==  0 ) {         int maxim = a[i];         for (int j = i - 4; j < i; ++j) maxim = max(maxim, a[j]);         l = max(l, maxim + 1);       }     }     cout << l <<     << r <<   n ;     return 0;   }