malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   const int oo = 1000000007;   int n, k, m, a[10], lik[10], head[10], adj[10];   long long res;   bool fre[10], ok;   void make(int u, int v) {     m++;     adj[m] = v;     lik[m] = head[u];     head[u] = m;   }   void dfs(int u) {     fre[u] = false;     int i = head[u];     while (i != 0) {       int v = adj[i];       if (fre[v]) dfs(v);       i = lik[i];     }   }   bool check() {     m = 0;     memset(lik, 0, sizeof(lik));     memset(head, 0, sizeof(head));     memset(fre, 1, sizeof(fre));     for (long long i = 1; i <= k; i++) make(a[i], i);     dfs(1);     for (long long i = 1; i <= k; i++)       if (fre[i]) return false;     return true;   }   void att(int i) {     if (i > k) {       if (!ok) return;       if (check()) res++;       return;     }     for (long long x = 1; x <= k; x++)       if ((x != i) || (i == 1)) {         bool z = ok;         if (x == 1) ok = true;         a[i] = x;         att(i + 1);         ok = z;       };   }   int main() {     cin >> n >> k;     long long sum = 1;     for (long long i = 1; i <= n - k; i++) sum = (sum * (n - k)) % oo;     att(1);     cout << (res * sum) % oo;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r = 0, c = 0;     string str;     cin >> str;     if (str.length() > 2) {       for (int i = 0; i < str.length() - 2; i++) {         if (str[i] ==  Q ) {           for (int j = i + 1; j < str.length() - 1; j++) {             if (str[j] ==  A ) r++;             if (r > 0) {               for (int k = j + 1; k < str.length(); k++) {                 if (str[k] ==  Q ) {                   c++;                 }                 r = 0;               }             }           }         }       }     }     printf( %d , c);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long ca;     cin >> ca;     while (ca--) {       long long n, i, j, k, l, r, m;       cin >> l >> r >> m;       for (i = l; i <= r; i++) {         long long x1, x2;         x1 = m / i;         if (m % i != 0)           x2 = m / i + 1;         else           x2 = m / i;         long long y1 = m - (x1 * i);         long long y2 = (x2 * i) - m;         long long lim = r - l;         if (y1 <= lim && x1 > 0) {           cout << i <<     << l + y1 <<     << l << endl;           break;         }         if (y2 <= lim && x2 > 0) {           cout << i <<     << l <<     << l + y2 << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   bool ck(int k) {     double ss = (double)k * m, cnt = 1;     double C = 1, A = k, B = 1;     for (long long lp = 1; cnt < n && ss > 0 && A >= 0; lp++) {       C = C * A / B;       A--;       B++;       double y = min(C, ss / lp);       cnt += y;       ss -= y * lp;     }     return cnt >= n;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       int l = 0, r = n;       while (l + 1 < r) {         int mid = (l + r) / 2;         if (ck(mid))           r = mid;         else           l = mid + 1;       }       if (ck(l))         printf( %d n , l);       else         printf( %d n , r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, sz[1005], lab[1005], cur = 1, cur2, f = 1;   vector<int> v[1005];   int getsz(int node, int p) {     sz[node] = 1;     for (int u : v[node]) {       if (u != p) sz[node] += getsz(u, node);     }     return sz[node];   }   int find(int node, int p) {     for (int u : v[node]) {       if (u != p && sz[u] > n / 2) return find(u, node);     }     return node;   }   void assign(int node, int p) {     if (f)       lab[node] = cur++;     else       lab[node] = (++cur2) * cur;     printf( %d %d %d n , node, p, lab[node] - lab[p]);     for (int u : v[node]) {       if (u != p) assign(u, node);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     getsz(1, 0);     int c = find(1, 0);     getsz(c, 0);     vector<pair<int, int> > ch;     for (int u : v[c]) ch.push_back({sz[u], u});     sort(ch.begin(), ch.end());     reverse(ch.begin(), ch.end());     for (auto p : ch) {       assign(p.second, c);       if (f && n <= 3 * cur && 3 * cur <= 2 * n) f = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   struct CHT {     vector<long long> m, c;     bool decSlope, askMin;     CHT(bool slopeType, bool queryType) {       decSlope = slopeType;       askMin = queryType;     }     bool throwLine(long long l1, long long l2, long long l3) {       if (decSlope) {         if (askMin)           return (double)(c[l2] - c[l1]) * (m[l1] - m[l3]) >=                  (double)(c[l3] - c[l1]) * (m[l1] - m[l2]);         else           return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);       } else {         if (!askMin)           return (c[l2] - c[l1]) * (m[l1] - m[l3]) >=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);         else           return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);       }     }     void add(long long M, long long C) {       m.push_back(M);       c.push_back(C);       while (((long long)m.size()) >= 3 &&              throwLine(((long long)m.size()) - 3, ((long long)m.size()) - 2,                        ((long long)m.size()) - 1)) {         m.erase(m.end() - 2);         c.erase(c.end() - 2);       }     }     long long f(long long i, long long x) { return m[i] * x + c[i]; }     long long query(long long x) {       long long l = 0, r = ((long long)m.size()) - 1, ret;       if (askMin)         ret = inf;       else         ret = -inf;       while (l <= r) {         long long m1 = l + (r - l) / 3;         long long m2 = r - (r - l) / 3;         if (f(m1, x) == f(m2, x)) {           ret = f(m1, x);           r = m2 - 1;           l = m1 + 1;         } else if (f(m1, x) < f(m2, x)) {           if (askMin) {             ret = f(m1, x);             r = m2 - 1;           } else {             ret = f(m2, x);             l = m1 + 1;           }         } else {           if (askMin) {             ret = f(m2, x);             l = m1 + 1;           } else {             ret = f(m1, x);             r = m2 - 1;           }         }       }       return ret;     }   };   const long long lim = 2e5 + 10;   long long a[lim];   long long s[lim];   long long p[lim];   int main() {     CHT machine(true, false);     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       p[i] = p[i - 1] + a[i];       s[i] = s[i - 1] + i * a[i];     }     long long ans = s[n], ans2 = s[n];     for (long long i = n; i; i--) {       machine.add(i, -p[i]);       long long tmp = machine.query(a[i]) + p[i] - i * a[i] + s[n];       ans = max(ans, tmp);     }     CHT machine2(false, false);     for (long long i = 1; i <= n; i++) {       machine2.add(i, -p[i - 1]);       long long tmp = machine2.query(a[i]) + p[i - 1] - i * a[i] + s[n];       ans2 = max(ans2, tmp);     }     cout << max(ans, ans2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int fp(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) (res *= a) %= (1000000000 + 7);       b /= 2;       (a *= a) %= (1000000000 + 7);     }     return res;   }   int n, k, cr, l, last;   long long int pref[1501][2], pw[1501][2], h, h1;   bool c[26];   string s, temp;   char c1;   queue<int> q;   set<pair<int, int>> ans;   void solve() {     s =    ;     cin >> temp;     s += temp;     for (long long int i = 0; i < 26; i++) {       cin >> c1;       c[i] = 1 - (c1 -  0 );     }     cin >> k;     n = s.length() - 1;     long long int exp = 1, exp1 = 1;     cr = 0;     q.push(0);     pref[0][0] = pref[0][1] = last = l = cr = 0;     for (int i = 1; i <= n;          i++, (exp *= 31) %= (1000000000 + 7), (exp1 *= 37) %= (1000000000 + 7)) {       pref[i][0] = (pref[i - 1][0] + (s[i] -  a  + 1) * exp) % (1000000000 + 7);       pref[i][1] = (pref[i - 1][1] + (s[i] -  a  + 1) * exp1) % (1000000000 + 7);     }     pw[n][0] = fp(31, (1000000000 + 7) - 2 - n);     pw[n][1] = fp(37, (1000000000 + 7) - 2 - n);     for (int i = n - 1; i >= 0; i--) {       pw[i][0] = (pw[i + 1][0] * 31) % (1000000000 + 7);       pw[i][1] = (pw[i + 1][1] * 37) % (1000000000 + 7);     }     for (int i = 1; i <= n; i++) {       if (c[s[i] -  a ]) {         cr++;         q.push(i);       }       if (cr == k + 1) {         cr--;         l = q.front();         q.pop();         for (int j = i - 1; j >= last; j--) {           for (int x = j; x > l; x--) {             h = (((pref[j][0] - pref[x - 1][0] + (1000000000 + 7)) %                   (1000000000 + 7)) *                      pw[x][0] +                  (1000000000 + 7)) %                 (1000000000 + 7);             h1 = (((pref[j][1] - pref[x - 1][1] + (1000000000 + 7)) %                    (1000000000 + 7)) *                       pw[x][1] +                   (1000000000 + 7)) %                  (1000000000 + 7);             ans.insert({h, h1});           }         }         last = i;       }     }     l = q.front();     q.pop();     for (int j = n; j >= last; j--) {       for (int x = j; x > l; x--) {         h = (((pref[j][0] - pref[x - 1][0] + (1000000000 + 7)) %               (1000000000 + 7)) *                  pw[x][0] +              (1000000000 + 7)) %             (1000000000 + 7);         h1 = (((pref[j][1] - pref[x - 1][1] + (1000000000 + 7)) %                (1000000000 + 7)) *                   pw[x][1] +               (1000000000 + 7)) %              (1000000000 + 7);         ans.insert({h, h1});       }     }     cout << int(ans.size());   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long mod = 998244353;   inline long long add(long long v1, long long v2) {     v1 += v2;     if (v1 >= mod) v1 -= mod;     if (v1 < 0) v1 += mod;     return v1;   }   inline long long mul(long long v1, long long v2) { return v1 * v2 % mod; }   inline long long mypow(long long v, long long t) {     long long res = 1;     while (t) {       if (t & 1) res = res * v % mod;       v = v * v % mod;       t >>= 1;     }     return res;   }   inline void bye() {     puts(  );     exit(0);   }   const int N = 303030;   int a[N];   long long cnt[N];   long long dp[8][N];   long long fac[N], ifac[N];   long long C(int v1, int v2) {     if (v1 < v2) return 0;     return mul(fac[v1], mul(ifac[v2], ifac[v1 - v2]));   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       cnt[a[i]]++;     }     fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = fac[i - 1] * i % mod;     }     ifac[N - 1] = mypow(fac[N - 1], mod - 2);     for (int i = N - 2; i >= 0; i--) {       ifac[i] = ifac[i + 1] * (i + 1) % mod;     }     for (int i = 1; i < N; i++) {       for (int j = i * 2; j < N; j += i) {         cnt[i] += cnt[j];       }     }     for (int i = 1; i < 8; i++) {       for (int j = N - 1; j >= 1; j--) {         dp[i][j] = C(cnt[j], i);         for (int k = j * 2; k < N; k += j) {           dp[i][j] = add(dp[i][j], -dp[i][k]);         }       }       if (dp[i][1]) {         printf( %d n , i);         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200000], t[200000];   int equi(int a, int b, int c, int d) {     bool x = 1;     for (int i = 0; i <= b - a; i++) {       x &= (s[i + a] == t[i + c]);     }     if (x) return 1;     if (b <= a) return 0;     int n = b - a + 1;     if (n % 2 == 1) return 0;     if (equi(a, a + n / 2 - 1, c, c + n / 2 - 1)) {       if (equi(a + n / 2, b, c + n / 2, d)) return 1;     }     if (equi(a, a + n / 2 - 1, c + n / 2, d)) {       if (equi(a + n / 2, b, c, c + n / 2 - 1)) return 1;     }     return 0;   }   int main() {     int n = 0;     scanf( %s , s);     scanf( %s , t);     while (s[n++] !=   0 )       ;     n--;     if (equi(0, n - 1, 0, n - 1))       printf( YES );     else       printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   vector<int> all;   vector<int> zu;   vector<int> de;   int main() {     string x;     cin >> x;     int y = x.size() / 2;     cout << x;     for (size_t i = 0; i < y; i++) {       swap(x[i], x[x.size() - i - 1]);     }     cout << x << endl;     return 0;   }
/*           ----@sagittarius_k2-----       Created by Ritesh Ranjan       ->       */       #define fio                                ios_base::sync_with_stdio(false);       cin.tie(NULL);                          cout.tie(NULL);       #include <bits/stdc++.h>   #include <iostream>   #include <set>   #include <algorithm>   #include <iterator>           using namespace std;       #define int long long int       #define M 1000000007       using namespace std;       signed main()   {       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           int a[n+1], b[n+1];           for(int i=1; i<=n; i++)           {               cin>>a[i];               b[i]=a[i];           }           sort(a+1, a+n+1);              int ans=-1, min_no=-1;           for(int i=1; i<=n; i++)           {               int c=0;               while(i<n && a[i]==a[i+1])               {                   i++;                   c++;               }               if(c==0)               {                   min_no=a[i];                   break;               }           }           for(int i=1; i<=n; i++)           {               if(b[i]==min_no)               {                   ans=i;                   break;               }           }           cout<<ans<<  n ;       }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 100010, INF = 0x3f3f3f3f;   int n, m, deg, s[MAXN], p[MAXN];   int main() {     scanf( %d , &n);     for (int a = 0; a < n; a++) {       scanf( %d , &s[a]);       p[s[a]] = a;     }     int ult = -1, cnt = 0, res = 0;     for (int a = 1; a <= n; a++) {       if (p[a] > ult) {         cnt++;         ult = p[a];         res = max(cnt, res);       } else {         cnt = 1;         ult = p[a];       }     }     printf( %d n , n - res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[4111];   int f[4111], v[4111][4111];   int main() {     int n, m;     cin >> n >> m;     while (m--) {       int a, b;       cin >> a >> b;       if (a > b) swap(a, b);       g[a].push_back(b);       f[a]++;       f[b]++;       v[a][b] = v[b][a] = 1;     }     int ans = -1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         for (int k = j + 1; k < g[i].size(); k++) {           int a = g[i][j], b = g[i][k];           int w = f[a] + f[b] + f[i] - 6;           if (v[a][b]) {             if (ans == -1)               ans = w;             else               ans = min(ans, w);           }         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   void smain();   int main() {     ios::sync_with_stdio(false);     smain();     return 0;   }   const int maxn = 300000 + 10;   int num[maxn];   int num1[maxn], num2[maxn];   int tot = 1;   int min1[maxn], min2[maxn];   int la1[maxn], la2[maxn];   int flo(int a, int b) {     int ans = a / b;     if (a % b != 0) ans++;     return ans;   }   const int INF = 2e9;   int a1[maxn], a2[maxn];   int flag[maxn];   bool cal(int n, int *Min, int *La, int *This, int *a1, int *a2) {     bool flagg = false;     int A1, A2;     for (int i = (2); i <= (n); ++i) {       if (Min[i - 1] == INF || This[i] == INF) continue;       if (Min[i - 1] + This[i] <= i) {         flagg = true;         A1 = La[i - 1];         A2 = i;         break;       }     }     if (!flagg) return false;     a1[0] = Min[A1];     a2[0] = This[A2];     int i = 1, j = 1;     for (j = 1; j < a1[0]; ++i) {       a1[j] = flag[i];       ++j;     }     a1[j] = flag[A1];     for (j = 1; j < a2[0]; ++i) {       if (i == A1) continue;       a2[j] = flag[i];       ++j;     }     a2[j] = flag[A2];     return true;   }   struct Node {     int o, flag;   } node[maxn];   bool cmp(Node a, Node b) { return a.o > b.o; }   void smain() {     int n, x1, x2;     cin >> n >> x1 >> x2;     for (int i = (1); i <= (n); ++i) cin >> num[i];     for (int i = (1); i <= (n); ++i) node[i].o = num[i], node[i].flag = i;     sort(node + 1, node + n + 1, cmp);     for (int i = (1); i <= (n); ++i) num[i] = node[i].o, flag[i] = node[i].flag;     int tmp;     for (int i = (1); i <= (n); ++i) {       tmp = flo(x1, num[i]);       if (tmp > i) tmp = INF;       min1[i] = num1[i] = tmp;       tmp = flo(x2, num[i]);       if (tmp > i) tmp = INF;       min2[i] = num2[i] = tmp;       la1[i] = la2[i] = i;     }     for (int i = (2); i <= (n); ++i) {       if (min1[i - 1] <= min1[i]) {         min1[i] = min1[i - 1];         la1[i] = la1[i - 1];       }       if (min2[i - 1] <= min2[i]) {         min2[i] = min2[i - 1];         la2[i] = la2[i - 1];       }     }     int ans1 = -1, ans2 = -1;     if (cal(n, min1, la1, num2, a1, a2)) {     } else if (cal(n, min2, la2, num1, a2, a1)) {     } else {       cout <<  No  << endl;       return;     }     cout <<  Yes  << endl;     cout << a1[0] <<     << a2[0] << endl;     for (int i = 1; a1[i] != 0; ++i) cout << a1[i] <<    ;     cout << endl;     for (int i = 1; a2[i] != 0; ++i) cout << a2[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};   int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   void fast() {     std::ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   string t;   bool solve(int m) { return t.substr(0, m) == t.substr(t.size() - m); }   int main() {     fast();     ;     int n, k;     cin >> n >> k;     cin >> t;     int idx = 1;     int mx = 0;     while (idx <= t.size() / 2) {       if (solve(idx)) {         mx = max(mx, idx);       }       idx++;     }     string s = t.substr(mx);     string a = t;     for (int i = 0; i < k - 1; i++) a += s;     mx = 0;     while (k) {       for (idx = 0; k; idx++) {         if (a.substr(idx, t.size()) == t) {           k--;           mx = idx + t.size();           if (k == 0) break;         }       }     }     cout << a.substr(0, mx) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int query(int x) {     printf( ? %d n , x);     int res;     fflush(stdout);     scanf( %d , &res);     return res;   }   int main() {     int n;     scanf( %d , &n);     int m = n / 2;     if (m % 2 == 1) {       printf( ! -1 n );       exit(0);     }     int d = query(1) - query(m + 1);     if (d == 0) {       printf( ! 1 n );       exit(0);     }     int l = 2, r = m;     while (l <= r) {       int mid = (l + r) / 2;       int t = query(mid) - query(mid + m);       if (!t) {         printf( ! %d n , mid);         exit(0);       }       if ((t < 0 && d < 0) || (t > 0 && d > 0))         l = mid + 1;       else         r = mid - 1;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n), b;     for (auto i = 0; i < (n); i++) {       cin >> a[i];     };     int cnt = 0, pos1 = 0, pos2 = 0;     for (auto i = 0; i < (n); i++)       if (a[i] != i + 1) {         b.push_back((i));         cnt++;       }     bool flag = true;     long long int x = b.size();     for (auto i = 0; i < (x - 1); i++) {       if (b[i + 1] - b[i] != 1) flag = false;     }     if (cnt == 0)       cout << 0;     else if (flag)       cout << 1;     else if (cnt == 2) {       cout << 2;     } else if (cnt == n)       cout << 1;     else if (cnt > 2)       cout << 2;   }   void template1() {     long long int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     template1();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sdf[30] = {4,   22,  27,  58,  85,  94,  121, 166, 202, 265,                  274, 319, 346, 355, 378, 382, 391, 438, 454, 483,                  517, 526, 535, 562, 576, 588, 627, 634, 636, 645};   long long int a[71720], b, c, d, n, m, i, j, k, sum, sumend;   bool cmp(int a, int b) { return a > b; }   int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   int gqt(int n) {     if (!n || n) return 0;     if (n == 2) return 1;     for (int i = 3; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     sum = a[n];     sort(a + 1, a + n + 1);     sumend = a[n];     cout << (sumend ^ sum) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int BASE = 27;   const int N = 200000 + 2;   const int LOGN = 20;   const long long oo = 1e18;   const double EPS = 1e-9;   int n, q, a[N], mn[N], mx[N], freq[N], dsu[N], bst[N], sum[N];   int find(int i) { return dsu[i] == i ? i : dsu[i] = find(dsu[i]); }   struct seg {     int l, r, val;     seg(int _l, int _r, int _val) { l = _l, r = _r, val = _val; }     bool operator<(const seg& sg) const { return l < sg.l; }   };   vector<seg> cln;   vector<seg> sg;   int main() {     memset(mn, -1, sizeof mn);     cin >> n >> q;     for (int i = 1; i <= 200000; ++i) dsu[i] = i;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       freq[a[i]]++;       if (mn[a[i]] == -1) {         mn[a[i]] = mx[a[i]] = i;       }       mx[a[i]] = max(mx[a[i]], i);       mn[a[i]] = min(mn[a[i]], i);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       sg.push_back(seg(mn[i], mx[i], i));     }     sort(sg.begin(), sg.end());     for (int i = 0; i < sg.size(); ++i) {       if (cln.size() && cln.back().r >= sg[i].l) {         dsu[find(cln.back().val)] = find(sg[i].val);         cln.back().r = max(cln.back().r, sg[i].r);         continue;       }       cln.push_back(sg[i]);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       bst[find(i)] = max(bst[find(i)], freq[i]);       sum[find(i)] += freq[i];     }     int ans = 0;     for (int i = 1; i <= 200000; ++i) {       if (find(i) == i) {         ans += sum[i] - bst[i];       }     }     cout << ans << endl;     return 0;   }