malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mod = 998244353;   long long power(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = z * x;       x = x * x;       y /= 2;     }     return z;   }   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   void solve() {     string s;     cin >> s;     vector<long long> v;     long long n = s.size(), cnt = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) v.push_back(i);     }     if (v.empty()) {       cout << 0 << endl;       return;     }     for (long long i = v[0]; i < v[v.size() - 1]; i++) {       if (s[i] ==  0 ) cnt++;     }     cout << cnt << endl;   }   int main() {     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   inline int lb(int a) { return a & (-a); }   long long a[100100], bit[7][15][100100];   int n, m, t;   inline void adj(int z, int zm, int pos, long long val) {     for (int i = pos; i <= n; i += lb(i)) bit[z][zm][i] += val;   }   inline long long qry(int z, int zm, int pos) {     if (pos <= 0) return 0;     long long rt = 0;     for (int i = pos; i > 0; i -= lb(i)) rt += bit[z][zm][i];     return rt;   }   inline long long sum(int z, int zm, int l, int r) {     int z2 = z * 2 - 2;     int lb = l + zm - 1, rb = r;     if (lb > r) return 0;     while (rb % z2 != lb % z2) rb--;     lb -= z2;     if (rb < l) return 0;     return qry(z, rb % z2, rb) - qry(z, lb % z2, lb);   }   inline int s(int z, int i) {     int mod = i % (2 * z - 2);     if (mod == 0)       return 2;     else if (mod <= z)       return mod;     else       return 2 * z - mod;   }   inline void update(int p, int v) {     for (int z = 2; z <= 6; z++) {       int z2 = z * 2 - 2;       adj(z, p % z2, p, v - a[p]);     }     a[p] = v;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int in;       scanf( %d , &in);       update(i, in);     }     scanf( %d , &m);     while (m-- > 0) {       scanf( %d , &t);       if (t == 1) {         int p, v;         scanf( %d%d , &p, &v);         update(p, v);       } else {         int l, r, z;         scanf( %d%d%d , &l, &r, &z);         long long ans = 0;         int z2 = z * 2 - 2;         for (int i = 1; i <= z2; i++) {           ans += s(z, i) * sum(z, i, l, r);         }         printf( %I64d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long MAX = 1e6 + 5;   bool cmp(const pair<long long, long long> &a,            const pair<long long, long long> &b) {     if (a.first < b.first)       return true;     else if (a.first == b.first) {       if (b.second > a.second) return true;       return false;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tc = 1, i, j;     while (tc--) {       long long n;       cin >> n;       long long a, b, c, d, e, f;       cin >> a >> b >> c;       cin >> d >> e >> f;       long long mi, ma;       mi = max(0LL, max(c - f - e, max(b - d - e, a - d - f)));       ma = min(a, e) + min(b, f) + min(c, d);       cout << mi <<     << ma <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int n, fa[200005][2], sz[200005][2];   long long ans;   int find(int x, int c) {     return fa[x][c] == x ? x : (fa[x][c] = find(fa[x][c], c));   }   void merge(int x, int y, int c) {     x = find(x, c), y = find(y, c);     if (x == y) return;     fa[y][c] = fa[x][c], sz[x][c] += sz[y][c];   }   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i)       fa[i][0] = fa[i][1] = i, sz[i][0] = sz[i][1] = 1;     for (register int i = 1, u, v, w; i < n; ++i)       scanf( %d%d%d , &u, &v, &w), merge(u, v, w);     for (register int i = 1; i <= n; ++i)       ans += 1ll * sz[find(i, 0)][0] * sz[find(i, 1)][1] - 1;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   double dot(complex<double> a, complex<double> b) {     return (conj(a) * b).real();   }   double cross(complex<double> a, complex<double> b) {     return (conj(a) * b).imag();   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long double x, y, minangle = 600;     int n, s, e;     cin >> n;     vector<pair<long double, int>> v;     for (int i = 1; i <= n; i++) {       cin >> x >> y;       v.push_back({atan2(x, y) * 180.0 / 3.14159265359, i});       while (v.back().first < 0) v.back().first += 360.0;       while (v.back().first > 360.0) v.back().first -= 360.0;     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       if (min(abs(v[i].first - v[(i + 1) % n].first),               360.0 - abs(v[i].first - v[(i + 1) % n].first)) -               minangle <=           -1e-20) {         minangle = min(abs(v[i].first - v[(i + 1) % n].first),                        360.0 - abs(v[i].first - v[(i + 1) % n].first));         s = v[i].second;         e = v[(i + 1) % n].second;       }     }     cout << s <<     << e;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const signed long long Infinity = 1000000001;   const long double Epsilon = 1e-9;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& V) {     os <<  [ ;     for (__typeof(V.begin()) i = V.begin(); i != V.end(); ++i)       os << *i << (i - V.begin() + 1 == ((int)V.size()) ?    :  , );     os <<  ] n ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& S) {     os <<  ( ;     for (__typeof(S.begin()) i = S.begin(); i != S.end(); ++i)       os << *i << (*i == *S.rbegin() ?    :  , );     os <<  ) n ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& M) {     os <<  { ;     for (__typeof(M.begin()) i = M.begin(); i != M.end(); ++i)       os << *i << (i->first == M.rbegin()->first ?    :  , );     os <<  } n ;     return os;   }   int N, K;   void read_data() { scanf( %d %d , &N, &K); }   void solve() {     if (N == K) {       printf( -1 n );     } else {       for (int(i) = (1); (i) <= (N - K - 1); (i)++) printf( %d  , i + 1);       printf( 1  );       for (int(i) = (N - K + 1); (i) <= (N); (i)++) printf( %d  , i);     }   }   int main() {     read_data();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   char S[500050];   int Aint[4 * 500050];   int pa, pb, pv;   long long A[500050];   void update(int k, int st, int dr) {     if (pa <= st && dr <= pb) {       Aint[k] += pv;       return;     }     int m = (st + dr) / 2;     if (pa <= m) {       update(2 * k, st, m);     }     if (pb > m) {       update(2 * k + 1, m + 1, dr);     }   }   void goUpdates(int p) {     int a = p + 1;     int b = N - p;     if (a > b) {       swap(a, b);     }     pa = 1;     pb = a;     pv = 1;     update(1, 1, N);     if (b + 1 <= N) {       pa = b + 1;       pb = N;       pv = -1;       update(1, 1, N);     }   }   void go(int k, int st, int dr, long long sum) {     sum += Aint[k];     if (st == dr) {       A[st] = sum;       return;     }     int m = (st + dr) / 2;     go(2 * k, st, m, sum);     go(2 * k + 1, m + 1, dr, sum);   }   int main() {     cin.sync_with_stdio(false);     fgets(S, sizeof(S), stdin);     N = 0;     for (int i = 0; S[i] !=   n  && S[i] !=   0 ; i++, N++)       ;     for (int i = 0; i < N; i++) {       if (S[i] ==  I  || S[i] ==  E  || S[i] ==  A  || S[i] ==  O  ||           S[i] ==  U  || S[i] ==  Y ) {         goUpdates(i);       }     }     go(1, 1, N, 0);     double ans = 0.0;     for (int i = 1; i <= N; i++) {       A[i] += A[i - 1];       ans += (double)A[i] / i;     }     cout << fixed << setprecision(10) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300009;   map<short, int> f[maxn];   int a[maxn], n, K, p, q, d;   int sum[maxn], i, j, k;   int main() {     scanf( %d%d , &n, &K);     d = n / K;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     for (i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i] - a[i - 1];     f[0][0] = 0;     for (i = 1; i <= n; i++) {       for (k = 0; k <= 1; k++) {         if (i >= d)           for (map<short, int>::iterator j = f[i - d].begin();                j != f[i - d].end(); j++)             if (j->first + k <= n % K) {               if (!f[i].count(j->first + k))                 f[i][j->first + k] = j->second + sum[i] - sum[i - d + 1];               else                 f[i][j->first + k] =                     min(f[i][j->first + k], j->second + sum[i] - sum[i - d + 1]);             }         d++;       }       if (i >= d) f[i - d].clear();       d -= 2;     }     printf( %d , f[n][n % K]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long abs(long long, long long);   double dis(long long x1, long long y1, long long x2, long long y2) {     double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     d = sqrt(d * 1.0);     return d;   }   void solve() {     long long w, h;     cin >> w >> h;     long long u1, d1, u2, d2;     cin >> u1 >> d1 >> u2 >> d2;     long long a = w;     for (long long i = h; i > 0; i--) {       a += i;       if (i == d1) {         a -= u1;         if (a < 0) a = 0;       }       if (i == d2) {         a -= u2;         if (a < 0) a = 0;       }     }     cout << a;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }   long long abs(long long a, long long b) {     if (a > b)       return a - b;     else       return b - a;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, t, m, y, z, k;     cin >> t;     while (t--) {       cin >> n >> m;       vector<vector<long long> > a(n, vector<long long>(m));       string s;       for (int i = 0; i < n; i++) {         cin >> s;         for (int j = 0; j < m; j++) {           a[i][j] = s[j] -  0 ;         }       }       vector<vector<long long> > ans;       auto f = [&](int i, int j) { a[i][j] ^= 1; };       for (int i = 0; i < n - 2; i++) {         for (int j = 0; j < m - 1; j++) {           if (a[i][j]) {             ans.push_back({i, j, i + 1, j, i, j + 1});             f(i, j);             f(i + 1, j);             f(i, j + 1);           }         }         if (a[i][m - 1]) {           ans.push_back({i, m - 1, i + 1, m - 1, i + 1, m - 2});           f(i, m - 1);           f(i + 1, m - 1);           f(i + 1, m - 2);         }       }       for (int j = 0; j < m - 2; j++) {         if (a[n - 2][j] && a[n - 1][j]) {           ans.push_back({n - 2, j, n - 1, j, n - 2, j + 1});           f(n - 2, j);           f(n - 1, j);           f(n - 2, j + 1);         } else if (a[n - 2][j]) {           ans.push_back({n - 2, j, n - 1, j + 1, n - 2, j + 1});           f(n - 2, j);           f(n - 1, j + 1);           f(n - 2, j + 1);         } else if (a[n - 1][j]) {           ans.push_back({n - 1, j, n - 1, j + 1, n - 2, j + 1});           f(n - 1, j);           f(n - 1, j + 1);           f(n - 2, j + 1);         }       }       for (int k = 0; k < 4; k++) {         vector<long long> move;         auto choose = [&](pair<long long, long long> o) {           move.push_back(o.first);           move.push_back(o.second);           a[o.first][o.second] ^= 1;         };         vector<pair<long long, long long> > b, g;         for (int i = n - 2; i < n; i++) {           for (int j = m - 2; j < m; j++) {             if (a[i][j])               b.push_back({i, j});             else               g.push_back({i, j});           }         }         if (b.size() == 0) break;         if (b.size() == 4) {           choose(b[0]);           choose(b[1]);           choose(b[2]);         } else if (b.size() == 1) {           choose(b[0]);           choose(g[0]);           choose(g[1]);         } else if (b.size() == 2) {           choose(b[0]);           choose(g[0]);           choose(g[1]);         } else if (b.size() == 3) {           choose(b[0]);           choose(b[1]);           choose(b[2]);         }         ans.push_back(move);       }       cout << ans.size() <<   n ;       for (auto &it : ans) {         for (int j : it) {           cout << j + 1 <<    ;         }         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     long long n, d, m, l, i, le, ri, step;     while (~scanf( %I64d%I64d%I64d%I64d , &n, &d, &m, &l)) {       for (i = 0; i < n; i++) {         le = i * m + l;         ri = (i + 1) * m;         step = (le + d) / d;         if (step * d < ri) break;       }       printf( %I64d n , step * d);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x[1000009], y[1000009], id[1000009];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , x + i, y + i), id[i] = i;     sort(id + 1, id + 1 + n, [](int a, int b) {       if (x[a] / 1000 != x[b] / 1000) return x[a] / 1000 < x[b] / 1000;       if (x[a] / 1000 % 2) return y[a] > y[b];       return y[a] < y[b];     });     for (int i = 1; i <= n; i++) printf( %d  , id[i]);   }
#include <bits/stdc++.h>   using namespace std;   int q, n;   long long k;   long long len[100004];   string s1 =  What are you doing while sending  ,          s2 =  ? Are you busy? Will you send  , s3 =  ? ,          f0 =               What are you doing at the end of the world? Are you busy? Will you                 save us? ;   int ge;   void pre() {     s1 +=    ;     s2 =     + s2 +    ;     s3 =     + s3;     len[0] = 75;     for (int i = 1; i <= 100000; i++) {       len[i] = len[i - 1] * 2 + 33 + 30 + 1 + 1 + 2 + 1;       if (len[i] > 1000000000000000000LL) {         ge = i;         return;       }     }   }   int dfs(int x) {     if (x <= ge && k > len[x]) return printf( . );     if (!x) return printf( %c , f0[k - 1]);     if (k <= 34) return printf( %c , s1[k - 1]), 0;     k -= 34;     if (x > ge || k <= len[x - 1]) return dfs(x - 1);     k -= len[x - 1];     if (k <= 32) return printf( %c , s2[k - 1]), 0;     k -= 32;     if (k <= len[x - 1]) return dfs(x - 1);     k -= len[x - 1];     return printf( %c , s3[k - 1]);   }   int main() {     scanf( %d , &q);     pre();     while (q--) {       scanf( %d%I64d , &n, &k);       dfs(n);     }     return 0;   }
#include <bits/stdc++.h>   using uint64 = unsigned long long;   const int N = 100, seed = 65537;   char s[N];   std::unordered_map<uint64, int> words;   std::unordered_set<uint64> mark;   int dfs(int d, uint64 hs) {     if (s[d] == 0) {       if (mark.count(hs)) return 0;       mark.insert(hs);       auto it = words.find(hs);       if (it == words.end())         return 0;       else         return it->second;     }     int ret = 0;     if (s[d] ==  ? ) {       ret += dfs(d + 1, hs);       for (char c =  a ; c <=  e ; ++c) {         ret += dfs(d + 1, hs * seed + c);       }     } else {       ret += dfs(d + 1, hs * seed + s[d]);     }     return ret;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       uint64 hs = 0;       for (int j = 0; s[j]; ++j) {         hs = hs * seed + s[j];       }       words[hs] += 1;     }     for (int i = 0; i < m; ++i) {       scanf( %s , s);       mark.clear();       printf( %d n , dfs(0, 0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dq[4040];   int st = 0;   int dr = 0;   int m[3030][3030];   int mn[3030][3030];   int N, M, K, L, X, Y, Z;   long long ret = 0;   void make() {     for (int i = 1; i <= N; ++i) {       int ind = 0;       st = dr = 0;       for (int j = 1; j <= M; ++j) {         while (dr - st > 0 && m[i][dq[dr - 1]] > m[i][j]) {           --dr;         }         dq[dr++] = j;         while (dq[st] <= j - L) {           ++st;         }         if (j - L >= 0) {           mn[i][j - L + 1] = m[i][dq[st]];         }       }     }     for (int j = 1; j <= M - L + 1; ++j) {       st = dr = 0;       for (int i = 1; i <= N; ++i) {         while (dr - st > 0 && mn[dq[dr - 1]][j] > mn[i][j]) --dr;         dq[dr++] = i;         while (dq[st] <= i - K) ++st;         if (i - K >= 0) {           ret += mn[dq[st]][j];         }       }     }   }   int G[3030 * 3030];   int main() {     cin.sync_with_stdio(false);     cin >> N >> M >> K >> L;     cin >> G[0] >> X >> Y >> Z;     for (int i = 1; i <= N * M + 100; ++i) {       G[i] = (1LL * G[i - 1] * X + Y) % Z;     }     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= M; ++j) {         m[i][j] = G[(i - 1) * M + j - 1];       }     }     make();     cout << ret << endl;   }
#include <bits/stdc++.h>   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-9;   using namespace std;   int main() {     for (int i = 0; i < 9; i++) printf( %d ? ?<>%d n , i, i + 1);     printf( 9 ? ?>> ? ?0 n ? ?<>1 n );     for (int i = 0; i <= 9; i++) printf(  ?%d>>%d ? n , i, i);     printf(  ?>> ? ? n>> ? n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long w, m, k;   long long comp;   long long getpre(long long a) {     long long tmp = 1, ct = 0;     while (a >= tmp) tmp *= 10, ++ct;     tmp /= 10;     long long t = 1;     long long ans = 0;     for (long long i = 1; i < ct; ++i) ans += i * 9 * t, t *= 10;     ans += (a - tmp + 1) * ct;     return ans;   }   bool judge(long long len) {     long long tl = m - 1;     long long tr = m + len - 1;     if (getpre(tr) - getpre(tl) <= comp) return true;     return false;   }   int main() {     cin >> w >> m >> k;     long long l = 0, r = w / k + 1, ans = 0;     comp = r - 1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (judge(mid))         l = mid + 1, ans = mid;       else         r = mid - 1;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       if (k % 2 == 0)         k = 2;       else         k = 1;       while (k--) {         long long m = -10000000000;         for (int i = 0; i < n; i++) {           m = max(m, a[i]);         }         for (int i = 0; i < n; i++) {           a[i] = m - a[i];         }       }       for (int i = 0; i < n; i++) cout << a[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[500005];   int main() {     string s;     cin >> s;     for (int i = 1; i <= s.size(); i++)       f[i] = (s[i - 1] ==  I  || s[i - 1] ==  O  || s[i - 1] ==  E  ||               s[i - 1] ==  A  || s[i - 1] ==  U  || s[i - 1] ==  Y );     for (int i = 1; i <= s.size(); i++) f[i] = f[i - 1] + f[i];     long long cur = 0;     long double ans = 0;     for (int i = 1; i <= s.size(); i++)       cur += (f[s.size() - i + 1] - f[i - 1]),           ans += (long double)cur / (long double)i;     printf( %.10Lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     long long t;     cin >> n >> t;     vector<long long> a, b;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       x += t;       a.push_back(x);     }     vector<int> breaks;     bool poss = true;     long long cur = 0;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       b.push_back(x);       if (x < i) poss = false;       if (x < cur) poss = false;       if (x != cur && i != (cur + 1)) poss = false;       if (x != cur) {         breaks.push_back(1);       } else {         breaks.push_back(0);       }       cur = x;     }     for (int i = 1; i < n; i++) {       if (breaks[i] && !breaks[i - 1] && a[i - 1] + 1 == a[i]) poss = false;     }     if (!poss) {       cout <<  No  << endl;       return 0;     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) {       if (b[i] == n) {         cout << a[n - 1] + i + 1 <<    ;       } else {         cout << a[b[i]] - (b[i] - i) <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int a[n + 1];     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int f = 0;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         if (j != i) {           for (long long int k = 1; k <= n; k++) {             if (k != j) {               if (a[i] == a[j] + a[k]) {                 f = 1;                 cout << i <<     << j <<     << k << endl;                 break;               }             }           }           if (f) {             break;           }         }       }       if (f) {         break;       }     }     if (f == 0) {       cout << -1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, j = 0;     cin >> n;     vector<int> ai(n);     if (n == 4) {       cout << 4 <<   n ;       cout << 3 <<     << 1 <<     << 4 <<     << 2 <<   n ;       return 0;     }     for (int i = 1; i <= n; i += 2) {       ai[j] = i;       j++;     }     for (int k = 2; k <= n; k += 2) {       if (abs(ai[j - 1] - k) != 1) {         ai[j] = k;         j++;       }     }     cout << j <<   n ;     for (int i = 0; i < j; i++) cout << ai[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, v[105], frec[105];   vector<int> ans;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++)       if (!frec[v[i]]) {         frec[v[i]] = 1;         ans.push_back(i);         if (ans.size() == k) break;       }     if (ans.size() == k) {       cout <<  YES  <<   n ;       for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       cout <<   n ;     } else       cout <<  NO  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int lg = 22;   const long long int N = 2e5 + 5;   const long long int INF = 1e18;   const long long int mod = 1e9 + 7;   const double PI = 3.14159265358979323846;   template <typename T>   T power(T x, T y, long long int m) {     T ans = 1;     while (y > 0) {       if (y & 1LL) ans = (ans * x) % m;       y >>= 1LL;       x = (x * x) % m;     }     return ans % m;   }   inline long long int mul(long long int a, long long int b, long long int p) {     return (a * 1ll * b) % p;   }   inline long long int sub(long long int a, long long int b, long long int p) {     long long int c = a - b;     if (c < 0) c += p;     return c;   }   inline long long int add(long long int a, long long int b, long long int p) {     long long int c = a + b;     if (c > p) c -= p;     return c;   }   long long int mark[N];   long long int n, q, a[N], minidx[N], maxidx[N];   int main() {     long long int ans = 0;     cin >> n >> q;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];       if (minidx[a[i]] == 0) {         minidx[a[i]] = i;       }       maxidx[a[i]] = i;     }     for (long long int i = 1; i <= n; i++) {       long long int maxcnt = 0, cnt = 0;       long long int maxi = maxidx[a[i]];       if (mark[i]) {         continue;       }       map<long long int, long long int> xfreq;       for (long long int j = i; j <= maxi; j++) {         cnt++;         mark[j] = 1;         xfreq[a[j]]++;         maxcnt = max(maxcnt, xfreq[a[j]]);         maxi = max(maxi, maxidx[a[j]]);       }       ans += (cnt - maxcnt);     }     cout << ans << endl;   }