malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int maxn = 100000 + 1;   LL h[maxn], p[maxn], up[maxn], sz[maxn];   int par[maxn];   vector<int> G[maxn], order;   void DFS(int u) {     sz[u] = p[u];     for (int v : G[u])       if (v != par[u]) {         par[v] = u;         DFS(v);         sz[u] += sz[v];       }     h[u] = sz[u] - h[u];     order.push_back(u);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     for (cin >> t; t; t -= 1) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i += 1) cin >> p[i];       for (int i = 1; i <= n; i += 1) cin >> h[i];       for (int i = 1; i <= n; i += 1) G[i].clear();       for (int i = 1; i <= n; i += 1) up[i] = 0;       for (int i = 1, x, y; i < n; i += 1) {         cin >> x >> y;         G[x].push_back(y);         G[y].push_back(x);       }       order.clear();       DFS(1);       int ans = 1;       for (int u : order)         if (h[u] < 0 or (h[u] & 1))           ans = 0;         else if (h[u] / 2 > up[u] + p[u])           ans = 0;         else           up[par[u]] += h[u] / 2;       cout << (ans ?  YES n  :  NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   bool check(int x, long long y) {     if (n * 2 / x < x + y) return true;     if (n * 2 / x > x + y) return false;     return n * 2 <= x * (x + y);   }   long long calc(long long y) {     int l = 1, r = 2e9, mid;     while (l < r) {       mid = (l >> 1) + (r >> 1) + (l & r & 1);       if (check(mid, y - 3))         r = mid;       else         l = mid + 1;     }     if ((r + y - 3) * r != 2 * n || 0 == (r & 1)) return -1;     return r * y / 2;   }   int main() {     bool ok = false;     cin >> n;     for (int i = 1; i <= 62; ++i) {       long long res = calc(1LL << i);       if (~res) {         ok = true;         printf( %I64d n , res);       }     }     if (!ok) puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   pair<int, int> p[maxn], q[maxn];   int t[maxn];   int tot;   int n, k;   int dp[maxn][2];   void solve() {     memset(dp, 0x3f3f3f3f, sizeof(dp));     int e = 0;     for (int i = 1; i <= tot; i++) {       dp[i][e] = min(dp[i - 1][e], q[i].second - q[i].first);     }     e ^= 1;     for (int ki = 2; ki <= k; ki++, e ^= 1) {       dp[1][e] = 0x3f3f3f3f;       for (int i = 2; i <= tot; i++) {         bool last = q[i - 1].second == q[i].first;         dp[i][e] =             min(dp[i - 1 - last][e ^ 1] + q[i].second - q[i].first, dp[i - 1][e]);       }     }     cout << dp[tot][e ^ 1] << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> k >> n;     for (int i = 0; i < n; i++) cin >> t[i];     sort(t, t + n);     for (int i = 1; i < n; i++) {       p[i] = make_pair(t[i - 1], t[i]);     }     sort(p + 1, p + n, [](const pair<int, int> &x, const pair<int, int> &y) {       return (x.second - x.first) < (y.second - y.first);     });     tot = min(3 * k, n - 1);     for (int i = 1; i <= tot; i++) {       q[i] = p[i];     }     sort(q + 1, q + tot + 1,          [](const pair<int, int> &x, const pair<int, int> &y) {            return x.first < y.first;          });     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100;   const int V = 100 * 50;   bool edge[V][V], nf[V];   int ans, cnt_v, n;   int from[V], start_v[N], value[V];   void ri() {     int a, i, j, m, x1, x2;     memset(from, 0xff, sizeof(from));     memset(edge, false, sizeof(edge));     cin >> n >> m;     for (i = 0; i < n; i++) {       start_v[i] = cnt_v;       cin >> a;       j = 2;       while (a > 1) {         for (; j * j <= a && a % j != 0; j++)           ;         if (a % j != 0) j = a;         value[cnt_v++] = j;         a /= j;       }     }     start_v[n] = cnt_v;     while (m--) {       cin >> x1 >> x2;       x1--;       x2--;       for (i = start_v[x1]; i < start_v[x1 + 1]; i++)         for (j = start_v[x2]; j < start_v[x2 + 1]; j++) {           edge[i][j] = value[i] == value[j];           edge[j][i] = value[i] == value[j];         }     }   }   bool ok(int v1) {     int temp, v2;     nf[v1] = false;     for (v2 = 0; v2 < cnt_v; v2++)       if (edge[v1][v2] && nf[v2]) {         nf[v2] = false;         temp = from[v2];         from[v2] = v1;         if (temp == -1 || ok(temp)) return true;         from[v2] = temp;       }     return false;   }   void solve() {     int i, j;     for (i = 0; i < n; i++) {       if (i & 1) continue;       for (j = start_v[i]; j < start_v[i + 1]; j++) {         memset(nf, true, sizeof(nf));         if (ok(j)) ans++;       }     }   }   void print() { cout << ans << endl; }   int main() {     ri();     solve();     print();     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 4e5 + 10;   const double eps = 1e-8;   const long long inf = 1e18 + 7;   using namespace std;   struct edge {     int t, v;     edge *next;   } e[MAXN << 1], *h[MAXN], *o = e;   void add(int x, int y, int w) {     o->t = y;     o->v = w;     o->next = h[x];     h[x] = o++;   }   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int n, a[MAXN];   long long dp[MAXN];   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     if (n == 1)       return 0 * printf( %d n , a[1]);     else if (n == 3) {       int minn = 1e9 + 7;       long long sum = 0;       for (int i = 1; i <= n; i++) minn = min(minn, a[i]), sum += a[i];       return 0 * printf( %lld n , sum - minn);     }     for (int i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];     for (int i = 2 * n; i >= 1; i--) dp[i] = a[i] + dp[i + 2];     long long maxx = 0;     for (int i = 1; i <= n; i++) {       maxx = max(maxx, a[i] + a[i + 1] + dp[i + 3] - dp[i + n]);     }     printf( %lld n , maxx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k = 0, dem = 0, s;   char c[1000001];   int e[100001];   deque<int> pq;   int main() {     cin >> n;     ;     for (int i = 1; i <= n; ++i) {       cin >> c[i];       if (c[i] ==  8 ) {         pq.push_back(i);         dem++;       }     }     s = n - 11;     s /= 2;     for (int i = 1; i <= n; i++) {       if (s == 0 || dem == 0) break;       if (c[i] ==  8 ) {         pq.pop_front();         dem--;         s--;       }     }     if (dem == 0 || pq.front() > n - 10)       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> p, rk;   int getp(int v) {     if (v == p[v]) return v;     return p[v] = getp(p[v]);   }   long long res;   long long get(int cnt) { return cnt * 1ll * (cnt - 1) / 2; }   void merge(int u, int v) {     u = getp(u);     v = getp(v);     if (rk[u] < rk[v]) swap(u, v);     res -= get(rk[u]);     res -= get(rk[v]);     rk[u] += rk[v];     res += get(rk[u]);     p[v] = u;   }   int main() {     int n, m;     cin >> n >> m;     res = 0;     p = rk = vector<int>(n, 1);     iota(p.begin(), p.end(), 0);     vector<pair<int, pair<int, int>>> e(n - 1);     for (int i = 0; i < n - 1; ++i) {       cin >> e[i].second.first >> e[i].second.second >> e[i].first;       --e[i].second.first;       --e[i].second.second;     }     vector<pair<int, int>> q(m);     vector<long long> ans(m);     for (int i = 0; i < m; ++i) {       cin >> q[i].first;       q[i].second = i;     }     sort(e.begin(), e.end());     sort(q.begin(), q.end());     int pos = 0;     for (int i = 0; i < m; ++i) {       while (pos < n - 1 && e[pos].first <= q[i].first) {         int u = e[pos].second.first;         int v = e[pos].second.second;         merge(u, v);         ++pos;       }       ans[q[i].second] = res;     }     for (int i = 0; i < m; ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, a[200005], n, x = 0;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       a[i] += x;       x = max(x, a[i]);     }     for (i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;   }
#include  bits/stdc++.h    #define FI first.first   #define SE first.second   #define TH second   #define fi first   #define se second   #define th second      using namespace std;      string to_string(const string& str) {     return str;   }      template<typename T>   string to_string(const set<T>& mys) {     if(mys.empty()) return  {} ;     string ret =  { ;     for(auto el: mys) ret += to_string(el) +  ,  ;     ret.pop_back(), ret.pop_back(); // Remove last space and comma     ret +=  } ;     return ret;   }      template<typename T>   string to_string(const pair<T, T>& pr) {     return  (  + to_string(pr.fi) +  ,  + to_string(pr.se) +  ) ;   }      template<typename T>   string to_string(const vector<T>& vc, int w) {     if(vc.empty()) return   ;     if(w + 1 == vc.size()) return to_string(vc[w]);     return to_string(vc[w]) +  ,  + to_string(vc, w + 1);   }      template<typename T>   string to_string(const vector<T>& vc) {     return  {  + to_string(vc, 0) +  } ;   }      void debug_out() { cerr << endl; }       template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }       #ifdef DEBUG   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      class DebugStream {}LOG;   template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }   #ifdef DEBUG   #define LOG clog   #endif      typedef long long ll;   typedef pair<ll, ll> ii;   typedef long double ld;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());      const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 43;      int n, k, dp[maxN][bs], tmp[bs];   vector<int> adj[maxN];      void apply(int* toad, int* used) {     for(int i = 0; i < k; i++)       toad[(i + 1) % k] ^= used[i];   }      void botUp(int nd, int an) {     for(auto sn: adj[nd]) {       if(sn == an) continue;       botUp(sn, nd);       apply(dp[nd], dp[sn]);     }   }      void topDown(int nd, int an) {     for(auto sn: adj[nd]) {       if(sn == an) continue;       memcpy(tmp, dp[sn], sizeof tmp);       apply(dp[nd], tmp);       apply(dp[sn], dp[nd]);       apply(dp[nd], tmp);       topDown(sn, nd);     }   }      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     #ifdef DEBUG     freopen( input.txt ,  r , stdin);     #endif        cin >> n >> k;     k *= 2;     for(int i = 1, u, v; i < n; i++) {       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     for(int i = 0; i < n; i++) cin >> dp[i][0];     botUp(0, -1);     topDown(0, -1);     for(int i = 0; i < n; i++) {       int rsp = 0;       for(int j = k / 2; j < k; j++) rsp ^= dp[i][j];       cout << (rsp? 1: 0) <<    ;      }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int luck_number[105], tot;   int dp[10005][7];   bool is_luck(int x) {     while (x) {       int y = x % 10;       x = x / 10;       if (y > 0 && y < 4) return false;       if (y > 4 && y < 7) return false;       if (y > 7) return false;     }     return true;   }   void init() {     tot = 0;     for (int i = 0; i <= 10000; i++) {       if (is_luck(i)) luck_number[tot++] = i;     }   }   void pre10000() {     for (int i = 0; i <= 10000; i++)       for (int j = 0; j <= 6; j++) dp[i][j] = -1;     for (int i = 0; i <= 6; i++) {       dp[0][i] = 0;     }     for (int i = 1; i <= 6; i++) {       for (int j = 0; j < tot; j++) {         int x = luck_number[j];         for (int k = x; k <= 10000; k++) {           if (dp[k - x][i - 1] != -1) {             dp[k][i] = x;           }         }       }     }   }   int main() {     init();     pre10000();     int cas;     scanf( %d , &cas);     while (cas--) {       long long N;       cin >> N;       if (N < 10000LL) {         int n = (int)(N);         if (dp[n][6] != -1) {           for (int i = 6; i > 0; i--) {             printf( %d  , dp[n][i]);             n -= dp[n][i];           }           puts(  );         } else           printf( -1 n );       } else {         int n1 = (int)(N % 4000LL);         if (dp[n1][6] == -1) n1 += 4000, N -= 4000;         long long res[7];         for (int i = 6; i > 0; i--) {           res[i] = (long long)(dp[n1][i]);           n1 -= dp[n1][i];         }         long long n2 = N - n1;         long long p = n2 / 4000LL, base = 1000LL;         while (p) {           int d = (int)(p % 10LL);           if (d <= 6) {             for (int i = 1; i <= d; i++) {               res[i] += base * 4;             }           } else {             for (int i = 1; i <= d - 7; i++) {               res[i] += base * 4;             }             for (int i = 6; i >= 3; i--) {               res[i] += base * 7;             }           }           base *= 10LL;           p /= 10LL;         }         for (int i = 1; i <= 6; i++) cout << res[i] <<    ;         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   const long long md = 998244353;   const int Inf = 1e9;   const long long Inf64 = 1e18;   const long long MaxN = 2e5 + 10;   const long long MaxM = 11;   const long double eps = 1e-15;   const long long dx[4] = {0, 1, 0, -1};   const long long dy[4] = {1, 0, -1, 0};   const long long ddx[4] = {1, 1, -1, -1};   const long long ddy[4] = {1, -1, 1, -1};   const long double Pi = acos(-1);   using namespace std;   long long gcd(long long a, long long b) {     while (a) {       b %= a;       swap(a, b);     }     return b;   }   long long gcdex(long long a, long long mod = md) {     long long g = mod, r = a, x = 0, y = 1;     while (r != 0) {       long long q = g / r;       g %= r;       swap(g, r);       x -= q * y;       swap(x, y);     }     return x < 0 ? x + mod : x;   }   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) {         res *= a;         res %= md;       }       a *= a;       a %= md;       n >>= 1;     }     return res % md;   }   bitset<MaxN> A;   bitset<MaxN> B;   long long dst(pair<long long, long long> a, pair<long long, long long> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   long long Mt[MaxN];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     cout << fixed, cout.precision(10);     long long N;     cin >> N;     map<long long, vector<pair<long long, long long> > > Mp;     for (int i = 0; i < N; i++) {       long long a, b;       cin >> a >> b;       Mp[max(a, b)].push_back({a, b});     }     Mp[0].push_back({0, -0});     for (auto& a : Mp) {       sort(a.second.begin(), a.second.end(),            [=](pair<long long, long long> a, pair<long long, long long> b) {              return a.first < b.first ||                     (a.first == b.first && a.second > b.second);            });     }     vector<vector<long long> > dp(Mp.size() + 1, vector<long long>(2, Inf64));     dp[0][1] = dp[0][0] = 0;     long long lvl = 0;     long long v = 0;     for (auto& it : Mp) {       lvl++;       pair<long long, long long> l = it.second[0];       pair<long long, long long> r = it.second.back();       pair<long long, long long> lstl = Mp[v][0];       pair<long long, long long> lstr = Mp[v].back();       dp[lvl][0] = min(dp[lvl][0], dp[lvl - 1][0] + dst(lstl, r) + dst(l, r));       dp[lvl][0] = min(dp[lvl][0], dp[lvl - 1][1] + dst(lstr, r) + dst(l, r));       dp[lvl][1] = min(dp[lvl][1], dp[lvl - 1][0] + dst(lstl, l) + dst(l, r));       dp[lvl][1] = min(dp[lvl][1], dp[lvl - 1][1] + dst(lstr, l) + dst(l, r));       v = it.first;     }     cout << min(dp[lvl][0], dp[lvl][1]) <<   n ;     cerr <<   n           <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 9;   const int inf = 1e9 + 9;   const int N = 2e5 + 9;   int n, q, l[N], r[N], a[N], wh[N];   long long bit[N], ans[N];   vector<int> h[N];   vector<pair<int, int> > Q[N];   void update(int t) {     t++;     while (t <= n + 1) {       bit[t]++;       t += (t & -t);     }   }   long long query(int t) {     long long sum = 0;     t++;     while (t > 0) {       sum += bit[t];       t -= (t & -t);     }     return sum;   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       wh[a[i]] = i;     }     for (int i = 1; i <= q; i++) {       scanf( %d %d , &l[i], &r[i]);       Q[r[i]].push_back(make_pair(l[i], i));     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j += i) {         h[j].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < h[a[i]].size(); j++) {         if (wh[h[a[i]][j]] <= i) {           update(wh[h[a[i]][j]]);         }       }       for (int j = a[i] * 2; j <= n; j += a[i]) {         if (wh[j] < i) {           update(wh[j]);         }       }       for (int j = 0; j < Q[i].size(); j++) {         ans[Q[i][j].second] += query(i) - query(Q[i][j].first - 1);       }     }     for (int i = 1; i <= q; i++) {       printf( %lld n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     cin.tie(nullptr)->sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       long long n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       vector<vector<long long>> adj(n + 1);       for (long long i = 0; i < n - 1; i++) {         long long x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       if (true) {         vector<bool> vis(n + 1);         vector<long long> dis(n + 1);         queue<long long> q;         q.push(a);         vis[a] = true;         while (!q.empty()) {           long long cur = q.front();           q.pop();           for (long long nxt : adj[cur]) {             if (!vis[nxt]) {               vis[nxt] = true;               dis[nxt] = dis[cur] + 1;               q.push(nxt);             }           }         }         if (dis[b] <= da) {           cout <<  Alice n ;           continue;         }       }       if (true) {         long long start = 0;         if (true) {           vector<bool> vis(n + 1);           vector<long long> dis(n + 1);           queue<long long> q;           q.push(a);           vis[a] = true;           while (!q.empty()) {             long long cur = q.front();             q.pop();             for (long long nxt : adj[cur]) {               if (!vis[nxt]) {                 vis[nxt] = true;                 dis[nxt] = dis[cur] + 1;                 q.push(nxt);               }             }           }           long long mx = 0;           for (long long i = 1; i <= n; i++) {             if (dis[i] > mx) {               mx = dis[i];               start = i;             }           }         }         if (true) {           vector<bool> vis(n + 1);           vector<long long> dis(n + 1);           queue<long long> q;           q.push(start);           vis[start] = true;           while (!q.empty()) {             long long cur = q.front();             q.pop();             for (long long nxt : adj[cur]) {               if (!vis[nxt]) {                 vis[nxt] = true;                 dis[nxt] = dis[cur] + 1;                 q.push(nxt);               }             }           }           long long dia = 0;           for (long long i = 1; i <= n; i++) {             dia = max(dia, dis[i]);           }           if (da * 2 >= dia) {             cout <<  Alice n ;             continue;           }         }       }       if (da * 2 < db) {         cout <<  Bob n ;       } else {         cout <<  Alice n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long p, d;     while (scanf( %I64d%I64d , &p, &d) != EOF) {       long long ans = ++p;       for (long long i = 10;; i *= 10) {         if (p % i > d) break;         ans = p - p % i;       }       printf( %I64d n , ans - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int d = 0, tot = 0, c;     bool flag = false;     for (int i = 0; i < n; i++) {       cin >> c;       tot = tot + c;       if (tot >= 8 && flag == false) {         k = k - 8;         tot = tot - 8;         d++;         if (k <= 0) flag = true;       } else if (tot < 8 && flag == false) {         k = k - tot;         tot = 0;         d++;         if (k <= 0) flag = true;       }     }     if (flag == true) {       cout << d << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, sum = 0, minodd = 101, i;     scanf( %d , &n);     for (; n > 0; --n) {       scanf( %d , &i);       if (minodd > i && i % 2) {         minodd = i;       }       sum += i;     }     if (minodd == 101)       printf( 0 );     else if (sum % 2)       printf( %d , sum);     else       printf( %d , sum - minodd);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, m;     cin >> t;     while (t--) {       cin >> n;       int i;       int a[n], b[n];       for (i = 0; i < n; i++) {         cin >> a[i];       }       int f = 0;       for (i = 0; i < n; i++) {         cin >> b[i];       }       int p = 0, v = 0;       for (i = 0; i < n; i++) {         if (a[i] < b[i]) {           p = i;           v = b[i] - a[i];           break;         }         if (a[i] > b[i]) {           f = 1;           cout <<  NO  << endl;           break;         }       }       if (f == 1) {         continue;       }       for (i = p; i < n; i++) {         if (a[i] < b[i]) {           if ((b[i] - a[i]) != v) {             f = 1;             cout <<  NO  << endl;             break;           }         } else if (a[i] > b[i]) {           f = 1;           cout <<  NO  << endl;           break;         } else {           p = i;           break;         }       }       if (f == 1) continue;       if (f == 0 && i == n) {         cout <<  YES  << endl;         continue;       }       for (i = p; i < n; i++) {         if (a[i] != b[i]) {           f = 1;           cout <<  NO  << endl;           break;         }       }       if (f == 0) cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000;   int cubeta[MAXN + 2];   int color;   int arr[MAXN + 2];   void mapea(int n) {     set<int> nums;     for (int i = 1; i <= n; i++) nums.insert(arr[i]);     map<int, int> val;     int cnt = 1;     set<int>::iterator it = nums.begin();     while (it != nums.end()) {       val[*it] = cnt;       cnt++;       it++;     }     for (int i = 1; i <= n; i++) arr[i] = val[arr[i]];   }   int busca(int l, int n) {     int r = n;     while (r > l && cubeta[arr[r]] != color) {       cubeta[arr[r]] = color;       r--;     }     return r + 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     mapea(n);     int resp = n;     for (int l = 0; l <= n; l++) {       color++;       bool continuar = true;       for (int i = 1; i <= l; i++) {         if (cubeta[arr[i]] == color) continuar = false;         cubeta[arr[i]] = color;       }       if (!continuar) break;       int r = busca(l, n);       resp = min(resp, r - l - 1);     }     cout << resp <<   n ;     return 0;   }