malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXn = 1e5 + 10, MAXlg = 20;   long long dp[MAXn][MAXlg], h[MAXn], dp2[MAXn], n, m, dp3[MAXn], dp4[MAXn];   vector<int> v[MAXn];   bool flag[MAXn], flag2[MAXn];   int make_tree(int a) {     flag[a] = true;     int ans = 1;     h[a] = h[dp[a][0]] + 1;     if (v[a].size() == 1 && a != 1) {       dp2[a] = 1;       return ans;     }     for (int i = 0; i < v[a].size(); i++)       if (!flag[v[a][i]]) {         dp[v[a][i]][0] = a;         ans += make_tree(v[a][i]);         dp3[a] += dp3[v[a][i]];       }     dp3[a] += ans - 1;     dp2[a] = ans;     return ans;   }   void make_dp(int a) {     flag2[a] = true;     for (int i = 0; i < v[a].size(); i++)       if (!flag2[v[a][i]]) {         dp4[v[a][i]] = dp4[a] + (n - dp2[a]) + dp3[a] + (dp2[a] - dp2[v[a][i]]) -                        (dp3[v[a][i]] + dp2[v[a][i]]);         make_dp(v[a][i]);       }   }   void make_lca() {     for (int i = 1; i < MAXlg; i++)       for (int j = 1; j <= n; j++) dp[j][i] = dp[dp[j][i - 1]][i - 1];   }   long double get_lca(int a, int b) {     if (h[a] > h[b]) swap(a, b);     int aa = a, bb = b, cc = b;     long long dis = h[b] - h[a];     for (int i = 0; i < MAXlg; i++)       if ((dis >> i) & 1) b = dp[b][i];     if (a == b) {       long double ans = 0;       dis--;       for (int i = 0; i < MAXlg; i++)         if ((dis >> i) & 1) bb = dp[bb][i];       ans += (long double)(dp4[a] + dp3[a] - dp3[bb] - dp2[bb]) * dp2[cc];       ans += (long double)(dp3[cc]) * (n - dp2[bb]);       ans += (long double)(dis + 2) * (dp2[1] - dp2[bb]) * dp2[cc];       ans /= (long double)(dp2[1] - dp2[bb]) * dp2[cc];       return ans;     }     for (int i = MAXlg - 1; i >= 0; i--)       if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];       }     int lca = dp[a][0];     long double ans = 0;     ans += (long double)dp3[aa] * dp2[bb] + dp3[bb] * dp2[aa] +            (long double)((long double)-2 * h[lca] + h[aa] + h[bb] + 1) * dp2[aa] *                dp2[bb];     ans /= (long double)dp2[aa] * dp2[bb];     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     make_tree(1);     make_lca();     make_dp(1);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       cout << fixed << setprecision(10) << get_lca(a, b) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   void print(vector<long long> vvv) {     for (auto it : vvv) cout << it <<    ;     cout <<   n ;   }   long long mod = 1e9 + 7;   long long qpow(long long base, long long p) {     if (p == 0) return 1;     if (p == 1) return base % mod;     long long r = qpow(base, p / 2);     if (p % 2 == 0) return (r * r) % mod;     return (((r * r) % mod) * base) % mod;   }   long long inv(long long a, long long b) {     return (((a) % mod) * qpow(b, mod - 2)) % mod;   }   long long mand(pair<long long, long long> a, pair<long long, long long> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   char invc(char a, char b, char c) {     if (a == b) return c;     return b;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(0);     long long n;     cin >> n;     vector<long long> v, ans;     vector<pair<long long, long long> > v2;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       ans.push_back(0);       v2.push_back({x, i});     }     sort(v2.begin(), v2.end());     for (long long i = 0; i < n; i++) {       if (i != n - 1) {         ans[v2[i].second] = v2[i + 1].first;       } else {         ans[v2[i].second] = v2[0].first;       }     }     print(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long inf = 1e18;   int ntest;   int n, m, k;   string s;   int cnt[55];   bool ok[maxn];   void read_input() {     cin >> n >> m >> k;     cin >> s;   }   void solve() {     fill(cnt, cnt + 26, 0);     for (int i = 0; i < k; ++i) ++cnt[s[i] -  A ];     long long ans = inf;     for (int i = 0; i < 26; ++i) {       fill(ok + 1, ok + k + 1, false);       ok[0] = true;       for (int j = 0; j < 26; ++j)         if (j != i) {           for (int sum = k - cnt[i]; sum >= 0; --sum)             if (ok[sum]) ok[sum + cnt[j]] = true;         }       for (int sum = 0; sum <= n; ++sum) {         if (!ok[sum]) continue;         int xn = n - sum;         int xm = max(0, m - (k - cnt[i] - sum));         if (xn + xm > cnt[i]) continue;         ans = min(ans, xn * 1LL * xm);       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> ntest;     while (ntest--) {       read_input();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   mt19937 mt(time(0));   long long n, k;   long long a[123456];   const long long inf = (int)(1e9);   int cnt = 0;   long long mas[123456];   long long solve() {     long long md;     for (int i = mt() % 123456 + (int)(1e9);; i++) {       bool ok = false;       for (int j = 2; j * j <= i; j++) {         if (i % j == 0) {           ok = true;           break;         }       }       if (!ok) {         md = i;         break;       }     }     long long tmp = 1;     for (int i = 0; i <= n; i++) {       mas[i] = tmp;       tmp *= k;       tmp %= md;     }     long long sum = 0;     for (int i = 0; i <= n; i++) {       long long t = (a[i] * mas[i]) % md;       sum += t;       sum %= md;     }     return sum;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 0; i <= n; i++) {       string s;       cin >> s;       if (s ==  ? )         a[i] = inf;       else {         istringstream iss(s);         iss >> a[i];         cnt++;       }     }     if (cnt < n + 1) {       if (k == 0 && a[0] != 0 && a[0] != inf) {         cout <<  No  << endl;         exit(0);       }       if (n % 2 == 1) {         if (k == 0 && a[0] == inf && cnt % 2 == 0)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       } else {         if ((k == 0 && a[0] == 0) || (k == 0 && a[0] == inf && cnt % 2 == 1))           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }       exit(0);     }     long long attempt1 = solve();     long long attempt2 = solve();     long long attempt3 = solve();     if (attempt1 == 0 && attempt2 == 0 && attempt3 == 0)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       string s, s1;       cin >> s;       long long int a[27] = {0}, c = 0, d = 0;       for (long long int i = 0; i < n; i++) {         if (a[s[i] -  a ] == 0) d++;         a[s[i] -  a ]++;       }       s1 = s;       sort(s1.begin(), s1.end());       if (k == 1)         cout << s1 << endl;       else {         long long int c1 = 0, c2 = 0;         for (long long int i = 0; i < n; i++) {           if (s1[i] == s1[0])             c1++;           else             break;         }         if (c1 < k) {           cout << s1[k - 1] << endl;         } else if (c1 == k) {           if (d == 1)             cout << s1[0] << endl;           else if (d == 2) {             long long int c2 = n - c1;             if (c2 % k == 0)               c2 = c2 / k;             else               c2 = (c2 / k) + 1;             cout << s1[0] <<   ;             for (long long int i = 0; i < c2; i++) cout << s1[c1] <<   ;             cout << endl;           } else {             cout << s1[0] <<   ;             for (long long int i = c1; i < n; i++) {               cout << s1[i] <<   ;             }             cout << endl;           }         } else {           if (d == 1) {             cout << s1[0] <<   ;             long long int c2 = c1 - k;             if (c2 % k == 0)               c2 = c2 / k;             else               c2 = (c2 / k) + 1;             for (long long int i = 0; i < c2; i++) cout << s1[0] <<   ;             cout << endl;           } else {             for (long long int i = k - 1; i < n; i++) cout << s1[i] <<   ;             cout << endl;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct target {     long double x;     long double y;     long long t;     long double p;     bool operator<(const target &b) const;   };   bool target::operator<(const target &b) const { return t < b.t; }   int main() {     cout.precision(30);     vector<target> v;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       target t;       cin >> t.x >> t.y >> t.t >> t.p;       v.push_back(t);     }     sort(v.begin(), v.end());     long double score[1010];     for (long long i = n - 1; i >= 0; i--) {       long double baseScore = v[i].p;       score[i] = v[i].p;       for (long long i2 = i + 1; i2 < n; i2++) {         long double dist = sqrt((v[i].x - v[i2].x) * (v[i].x - v[i2].x) +                                 (v[i].y - v[i2].y) * (v[i].y - v[i2].y));         if (dist <= v[i2].t - v[i].t) {           if (baseScore + score[i2] > score[i]) {             score[i] = baseScore + score[i2];           }         }       }     }     long double maxScore = score[0];     for (int i = 1; i < n; i++) {       if (score[i] > maxScore) {         maxScore = score[i];       }     }     cout << maxScore << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x, n, m, temp = 0;       cin >> x >> n >> m;       for (int i = 0; i <= n; i++) {         if (x <= 10 * m) {           temp = 1;           break;         } else           x = x / 2 + 10;       }       if (temp == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-6;   int ROUND(double x) { return (int)(x + 0.5); }   bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }   bool ISEQUAL(double x, double y) {     return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));   }   double SQSUM(double x, double y) { return x * x + y * y; }   template <class T>   bool INRANGE(T x, T a, T b) {     return a <= x && x <= b;   }   void split1(const string& str, vector<string>& out) {     string::size_type st = 0;     string::size_type next = 0;     int word_num = 0;     string tmp = str;     do {       next = tmp.find(   , st);       string word = tmp.substr(st, next - st);       if (word.length() >= 1) {         out.push_back(word);       }       st = next + 1;     } while (next != string::npos);   }   int main() {     int n;     scanf( %d  , &n);     vector<string> team_names;     for (int i = 0; i < n; i++) {       char str[256];       scanf( %s  , str);       team_names.push_back(string(str));     }     map<string, pair<int, pair<int, int> > > mp;     for (int i = 0; i < n * (n - 1) / 2; i++) {       char str[256];       char str2[256];       scanf( %s %s  , str, str2);       for (int k = 0; k < 256; k++) {         if (str[k] ==  -  || str[k] ==  : ) {           str[k] =    ;         }         if (str2[k] ==  -  || str2[k] ==  : ) {           str2[k] =    ;         }       }       vector<string> vs;       split1(string(str), vs);       vector<string> vs2;       split1(string(str2), vs2);       string team1, team2;       int goal1, goal2;       team1 = vs[0];       team2 = vs[1];       goal1 = atoi(vs2[0].c_str());       goal2 = atoi(vs2[1].c_str());       mp[team1].first += goal1 > goal2 ? 3 : goal1 == goal2 ? 1 : 0;       mp[team1].second.first += goal1 - goal2;       mp[team1].second.second += goal1;       mp[team2].first += goal2 > goal1 ? 3 : goal2 == goal1 ? 1 : 0;       mp[team2].second.first += goal2 - goal1;       mp[team2].second.second += goal2;     }     map<pair<int, pair<int, int> >, string> inv_mp;     {       map<string, pair<int, pair<int, int> > >::iterator it;       for (it = mp.begin(); it != mp.end(); it++) {         inv_mp[it->second] = it->first;       }     }     vector<string> winners;     {       map<pair<int, pair<int, int> >, string>::reverse_iterator inv_it =           inv_mp.rbegin();       for (int i = 0; i < n / 2; inv_it++, i++) {         winners.push_back(inv_it->second);       }     }     sort(winners.begin(), winners.end());     for (int i = 0; i < ((int)winners.size()); i++) {       printf( %s n , winners[i].c_str());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b % 2 == 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   bool comp(long long int a, long long int b) { return a < b; }   long long int binary(long long int *a, long long int l, long long int r,                        long long int key) {     long long int mid;     while (l <= r) {       mid = (l + r) / 2;       if (a[mid] == key) {         return mid;       } else if (a[mid] < key) {         l = mid + 1;       } else {         r = mid - 1;       }     }     return -1;   }   bool isprime(long long int n) {     if (n <= 1) {       return false;     }     int i;     for (i = 2; i <= ceil(sqrt((double)n)); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   bool isPalindrome(long long int n) {     long long int rev = 0, temp = n, rem;     while (temp) {       rem = temp % 10;       rev = rev * 10 + rem;       temp /= 10;     }     if (n == rev) return true;     return false;   }   long long int mulmod(long long int a, long long int b, long long int m) {     long long int res = 0;     a = a % m;     while (b > 0) {       if (b % 2 == 1) {         res = (res + a) % m;       }       a = (a * 2) % m;       b /= 2;     }     return (res % m);   }   bool isLeapYear(int year) {     if (year % 400 == 0) return true;     if (year % 100 == 0) return false;     if (year % 4 == 0) return true;     return false;   }   int ones(long long int n) {     int ans = 0;     while (n) {       ans++;       n &= (n - 1);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, pro = 1, n, m, temp, k, i, l, r, mid, j, x, y, z, ind,                      mx = LONG_LONG_MIN, mn = LONG_LONG_MAX, ans = 0, cnt = 0,                      curr = 0, prev, sum = 0, flag = 0, i1 = -1, i2 = -1;     cin >> n;     long long int a[n];     for (i = 0; i <= n - 1; i++) {       cin >> a[i];       mn = min(mn, a[i]);     }     vector<long long int> v;     for (i = 0; i <= n - 1; i++) {       if (a[i] == mn) {         v.push_back(i);       }     }     ans = LONG_LONG_MAX;     for (i = 0; i <= v.size() - 2; i++) {       ans = min(ans, v[i + 1] - v[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const long long INF = 2e18;   const double EPS = 1e-9;   using namespace std;   void WEZaa() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     WEZaa();     unsigned long long n, k;     cin >> n >> k;     vector<unsigned long long> a(n), b(n);     for (auto& i : a) cin >> i;     for (auto& i : b) cin >> i;     unsigned long long l = 0, r = 1e10, ans = 0, md;     while (l <= r) {       md = (l + r) / 2;       unsigned long long sum = 0;       for (int i = 0; i < n; i++) {         unsigned long long st = a[i] * md;         if (b[i] < st) sum += st - b[i];       }       if (sum <= k)         l = md + 1, ans = md;       else         r = md - 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans1, ans2, nr, x;   vector<int> v;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> nr;       for (int j = 1; j <= nr; ++j) {         cin >> x;         if (nr % 2 == 1 && j == (nr + 1) / 2) {           v.push_back(-x);           continue;         }         if (j <= nr / 2)           ans1 += x;         else           ans2 += x;       }     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); ++i) {       if (i % 2 == 0)         ans1 -= v[i];       else         ans2 -= v[i];     }     cout << ans1 <<     << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, ans = INT_MAX;     cin >> n >> k;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       if (k % x == 0) {         ans = min(ans, k / x);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   template <class T>   T SQR(T N) {     return (T)N * N;   }   template <class T>   double DIST(T a, T b) {     return 1.0 * sqrt(SQR(double(a)) + SQR(double(b)));   }   template <class T>   bool CROSS(pair<T, T> a, pair<T, T> b, pair<T, T> c) {     return (b.first - a.first) * (c.second - b.second) >=            (b.second - a.second) * (c.first - b.first);   }   template <class ll>   ll POW(ll a, ll b, ll mod) {     ll res = 1 % mod, x = a % mod;     while (b) {       if (b & 1) res = (res * x) % mod;       b /= 2, x = (x * a) % mod;     }     return res;   }   int px[] = {0, 1, -1, 0, -1, -1, 1, 1};   int py[] = {1, 0, 0, -1, -1, 1, -1, 1};   double EPS = 1e-9;   double PI = acos(-1);   double GR = 1.6180339887498948;   int F[7];   inline void Fail(string str) {     string s = str;     reverse(s.begin(), s.end());     s = s +  #  + str;     int len = s.length();     for (int i = 1; i < len; ++i) {       int j = F[i - 1];       while (j > 0 and s[i] != s[j]) j = F[j - 1];       if (s[i] == s[j]) ++j;       F[i] = j;     }   }   int main() {     int n, m, c, d, a, b, k;     int test;     scanf( %d%d%d , &n, &m, &d);     bool flag = 0;     b = c = 0;     for (int i = 0; i < n; ++i)       scanf( %d , &a), (a % d and !flag) ? flag = 1, b = i : flag;     flag = 0;     for (int i = 0; i < m; ++i)       scanf( %d , &a), (a % d and !flag) ? flag = 1, c = i : flag;     printf( %d n , b + c);   }
#include <bits/stdc++.h>   using namespace std;   long long derangements(long long n) {     if (n == 0) return 1;     if (n == 1) return 0;     if (n == 2) return 1;     return (n - 1) * (derangements(n - 1) + derangements(n - 2));   }   long long nCr(long long n, long long r) {     long long res = 1;     if (r == 0) return res;     for (long long i = 0; i < r; i++) res *= (n - i);     for (long long i = 2; i <= r; i++) res /= i;     return res;   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, k, ans = 0;     cin >> n >> k;     for (long long i = 0; i <= k; i++) ans += (nCr(n, i) * derangements(i));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const long long N = 1e5 + 5;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n), b;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1) {         b.push_back(i);       } else {         a[i] = a[i] / 2;       }     }     long long k = 0;     for (long long i = 0; i < (long long)b.size(); i++) {       if (a[b[i]] >= 0) {         if (!k) {           a[b[i]] = (a[b[i]] + 1) / 2;         } else {           a[b[i]] = a[b[i]] / 2;         }       } else {         if (k) {           a[b[i]] = (a[b[i]] - 1) / 2;         } else {           a[b[i]] = a[b[i]] / 2;         }       }       k ^= 1;     }     for (long long i = 0; i < n; i++) {       cout << a[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K, X;     cin >> N >> K >> X;     vector<int> Balls[100];     for (int i = 0; i < N; i++) {       int color;       cin >> color;       Balls[0].push_back(color);     }     for (int i = 1; i < 100; i++) {       Balls[i] = Balls[0];     }     int result = 0;     for (int i = 0; i < N; i++) {       Balls[i].insert(Balls[i].begin() + i, X);       for (int j = 0; j < (int)Balls[i].size() - 2; j++) {         if (Balls[i][j] == Balls[i][j + 1] && Balls[i][j] == Balls[i][j + 2]) {           int color = Balls[i][j];           while (j != (int)Balls[i].size() && Balls[i][j] == color) {             Balls[i].erase(Balls[i].begin() + j);           }           j = -1;         }       }       result = max(result, N - (int)Balls[i].size());     }     cout << result;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   int p, lmt;   int n, cnt[200010], a[200010], sum[200010];   int exs[200010], exs1[200010], ans, first[400010];   vector<int> loc;   map<int, int> used;   inline bool check() {     int mx = 0, tot = 0;     for (int i = 1; i <= n; i++) {       if (cnt[i] > mx) mx = cnt[i], tot = 0, p = i;       if (cnt[i] == mx) tot++;     }     return tot > 1;   }   int main() {     n = read();     lmt = 400;     for (int i = 1; i <= n; i++) {       a[i] = read();       cnt[a[i]]++;     }     if (check()) {       printf( %d n , n);       return 0;     }     for (int i = 1; i <= n; i++)       if (a[i] == p) loc.push_back(i);     for (int u = 1; u <= n; u++)       if (cnt[u] > lmt && u != p) {         for (int i = 0; i <= 2 * n; i++) first[i] = n + 1;         first[n] = 0, sum[0] = n;         for (int i = 1; i <= n; i++) {           sum[i] = sum[i - 1] + (a[i] == u) - (a[i] == p);           if (first[sum[i]] <= n)             ans = max(ans, i - first[sum[i]]);           else             first[sum[i]] = i;         }       }     vector<pair<int, int> > seg;     for (int len = 1; len <= lmt + 1; len++) {       seg.clear();       for (int i = 0; i < loc.size(); i++) {         int j = i + len - 1;         if (j >= loc.size()) break;         int l = (i == 0 ? 1 : loc[i - 1] + 1),             r = (j == loc.size() - 1 ? n : loc[j + 1] - 1);         seg.push_back(make_pair(l, r));       }       int l = 1, r = 0, mx = 0;       memset(exs, 0, sizeof(exs));       memset(exs1, 0, sizeof(exs1));       for (int i = 0; i < seg.size(); i++) {         while (r < seg[i].second) {           mx += 2;           r++;           if (a[r] != p) {             exs1[exs[a[r]]]--;             exs[a[r]]++;             exs1[exs[a[r]]]++;           }           while (!exs1[mx] && mx) mx--;         }         while (l < seg[i].first) {           mx += 2;           if (a[l] != p) {             exs1[exs[a[l]]]--;             exs[a[l]]--;             exs1[exs[a[l]]]++;           }           l++;           while (!exs1[mx] && mx) mx--;         }         if (mx >= len) ans = max(ans, r - l + 1);       }     }     cout << ans;     return 0;   }