malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, MAX = 202;   struct Leg {     int len, cost;     friend bool operator<(const Leg x, const Leg y) { return x.len < y.len; }   };   Leg l[N];   int sum[N];   int c[MAX][N];   int f[N];   bool vis[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &l[i].len);     for (int i = 0; i < n; ++i) scanf( %d , &l[i].cost);     sort(l, l + n);     for (int i = 0; i < n; ++i) {       ++f[l[i].len];       ++c[l[i].cost][l[i].len];     }     for (int i = N - 1; i > 0; --i) {       f[i] += f[i + 1];     }     for (int i = 1; i < MAX; ++i) {       for (int j = 1; j < N; ++j) {         c[i][j] += c[i][j - 1];       }     }     int ans = INT_MAX;     for (int i = 0; i < n; ++i) {       int curLen = l[i].len;       if (vis[curLen]) continue;       vis[curLen] = 1;       int curFreq = f[curLen] - f[curLen + 1];       int all = n - f[curLen];       int total = 0;       for (int j = 1; j < MAX; ++j) {         total += (c[j][N - 1] - c[j][curLen]) * j;       }       priority_queue<pair<int, int>> q;       for (int j = 1; j < MAX; ++j) {         q.push(make_pair(-j, c[j][curLen - 1]));       }       while (!q.empty() && curFreq <= all) {         int cost = -q.top().first, cnt = q.top().second;         if (curFreq + cnt > all) {           total += (all - curFreq + 1) * cost;           all = curFreq - 1;           break;         }         total += cnt * cost;         all -= cnt;         q.pop();       }       ans = min(ans, total);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   int n, a, b, u;   int sol[N][N];   void W() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         printf( %d , sol[i][j]);       }       printf(  n );     }   }   int main() {     cin >> n >> a >> b;     if (a != 1 && b != 1) {       cout <<  NO ;       return 0;     }     if (a == 1 && b == 1) {       if (n == 1) {         printf( YES n0 );         return 0;       }       if (n <= 3) {         cout <<  NO ;         return 0;       }       printf( YES n );       for (int i = 1; i < n; i++) {         sol[i][i + 1] = 1;         sol[i + 1][i] = 1;       }       W();       return 0;     }     printf( YES n );     if (a != 1)       u = a;     else       u = b;     for (int i = 1; i <= n - u; i++) {       sol[i][i + 1] = 1;       sol[i + 1][i] = 1;     }     if (a != 1) {       W();       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) {           sol[i][j] ^= 1;         }       }     }     W();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > V;   int p[102345];   int main() {     int n, m, x, y;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       V.insert(make_pair(x, y));       V.insert(make_pair(y, x));     }     for (int i = 0; i < n; i++) p[i] = i + 1;     int tim = 16384;     bool flag = false;     while (tim && !flag) {       random_shuffle(p, p + n);       p[n] = p[0];       int cnt = 0;       for (int i = 0; i < n; i++) {         if (!V.count(pair<int, int>(p[i], p[i + 1]))) cnt++;         if (cnt == m) {           for (int i = 0; m > 0; i++) {             if (!V.count(pair<int, int>(p[i], p[i + 1]))) {               printf( %d %d n , p[i], p[i + 1]);               m--;             }           }           flag = true;           break;         }       }       tim--;     }     if (!flag) puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     s =  0  + s +  0 ;     for (long long i = 0; i < s.length() - 1; i++) {       if (k == 0) break;       if (s[i] ==  4  && s[i + 1] ==  4  && s[i + 2] ==  7  && i % 2) {         k = k % 2;         if (k) {           s[i + 1] =  7 ;         }         k = 0;       } else if (s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] ==  7  && i % 2) {         k = k % 2;         if (k) {           s[i + 1] =  4 ;         }         k = 0;       } else if (s[i] ==  4  && s[i + 1] ==  7  && i % 2) {         s[i + 1] =  4 ;         k--;       } else if (s[i] ==  4  && s[i + 1] ==  7 ) {         s[i] =  7 ;         k--;       }     }     cout << s.substr(1, n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pow(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T x, T y) {     for (T t; x; t = x, x = y % x, y = t)       ;     return y;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     Graph() { adj.clear(); }     void resize(int n) { adj.resize(n + 5); }     void add(int s, edge e) { adj[s].push_back(e); }     void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }     vector<edge> &operator[](int t) { return adj[t]; }   };   int main() {     ios_base::sync_with_stdio(false);     int n, ans = 0;     cin >> n;     stack<int> Q;     for (int i = 1, v; i <= n; ++i) {       cin >> v;       for (; !Q.empty(); Q.pop()) {         int x = Q.top();         chkmax(ans, v ^ x);         if (x > v) {           break;         }       }       Q.push(v);     }     cout << setprecision(15) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a[100010], dp[100010];   int len[100010];   int main() {     int n, m, i, j, k, l, r;     while (~scanf( %d%d , &n, &m)) {       for (i = 1; i <= n; i++) {         a[i].resize(m + 1);         for (j = 1; j <= m; j++) scanf( %d , &a[i][j]);       }       memset(len, 0, sizeof(len));       for (i = 1; i <= n; i++) {         dp[i].resize(m + 1);         if (i == 1)           for (j = 1; j <= m; j++) dp[i][j] = 1;         else           for (j = 1; j <= m; j++)             if (a[i][j] >= a[i - 1][j])               dp[i][j] = dp[i - 1][j] + 1;             else               dp[i][j] = 1;         for (j = 1; j <= m; j++) len[i] = max(len[i], dp[i][j]);       }       scanf( %d , &k);       while (k--) {         scanf( %d%d , &l, &r);         if (len[r] >= r - l + 1)           printf( Yes n );         else           printf( No n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<char> Set;   pair<int, int> p[181];   string s, sn;   int i, k, sum;   bool pole[181];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> s;     cin >> k;     for (i = 0; i < s.size(); i++) p[s[i] - 96].first++;     for (i = 1; i <= 26; i++) p[i].second = i;     sort(p + 1, p + 1 + 26);     for (i = 1; i <= 26; i++) {       sum += p[i].first;       if (k - sum >= 0)         pole[p[i].second] = true;       else         break;     }     for (i = 0; i < s.size(); i++)       if (!pole[s[i] - 96]) {         Set.insert(s[i]);         sn += s[i];       }     cout << Set.size() <<   n ;     cout << sn <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, u, w;     edge() {}     edge(int v, int u, int w) : v(v), u(u), w(w) {}   };   const int N = 2e5 + 7;   vector<pair<int, bool>> g[N];   vector<pair<int, int>> gg[N];   vector<edge> glob_ans;   int color[N];   void init(int n) {     for (int i = 1; i <= n; i++) {       g[i].clear();       gg[i].clear();       color[i] = -1;     }     glob_ans.clear();   }   bool dfs0(int v, int cl) {     color[v] = cl;     for (auto [u, c] : g[v]) {       if (color[u] == -1) {         if (!dfs0(u, c ^ cl)) return 0;       } else {         if (color[u] != (c ^ cl)) return 0;       }     }     return 1;   }   void dfs(int v, int pr = -1) {     for (auto [u, w] : gg[v]) {       if (u == pr) continue;       if (w != -1) {         assert(__builtin_popcount(w) % 2 == (color[v] ^ color[u]));         glob_ans.push_back(edge(v, u, w));       } else {         glob_ans.push_back(edge(v, u, color[v] ^ color[u]));       }       dfs(u, v);     }   }   void solve() {     int n, m;     cin >> n >> m;     init(n);     for (int i = 0; i < n - 1; i++) {       int x, y, v;       cin >> x >> y >> v;       gg[x].push_back({y, v});       gg[y].push_back({x, v});       if (v != -1) {         int c = __builtin_popcount(v) % 2;         g[x].push_back({y, c});         g[y].push_back({x, c});       }     }     for (int i = 0; i < m; i++) {       int a, b, p;       cin >> a >> b >> p;       g[a].push_back({b, p});       g[b].push_back({a, p});     }     for (int i = 1; i <= n; i++) {       if (color[i] == -1) {         if (!dfs0(i, 0)) {           cout <<  NO n ;           return;         }       }     }     dfs(1);     cout <<  YES n ;     for (auto elem : glob_ans) {       cout << elem.v <<     << elem.u <<     << elem.w <<   n ;     }   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<long long> v(100005);   vector<int> cache(1e5 + 10, -1);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     map<int, int> mp;     for (long long i = 0; i < n; i++) {       int x;       cin >> x;       set<int> st;       for (int k = 2; k * k <= x; k++) {         if (x % k == 0) {           st.insert(k);           while (x % k == 0) {             x = x / k;           }         }       }       int mx = 0;       if (x > 1) {         st.insert(x);       }       for (auto it : st) {         mp[it]++;         mx = max(mx, mp[it]);       }       for (auto it : st) {         mp[it] = mx;       }     }     int maxi = 1;     for (auto it : mp) maxi = max(maxi, it.second);     cout << maxi <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int a[10], b[10];   int main() {     int m, n;     cin >> m >> n;     for (int i = 0; i < m; i++) cin >> a[i];     for (int j = 0; j < n; j++) cin >> b[j];     sort(a, a + m);     sort(b, b + n);     int flag = 0, ans;     for (int i = 0, j = 0; i < m && j < n;) {       if (a[i] == b[j]) {         ans = a[i];         flag = 1;         break;       } else if (a[i] < b[j])         i++;       else if (a[i] > b[j])         j++;     }     if (flag == 1) {       cout << ans << endl;     } else {       if (a[0] == b[0])         cout << a[0] << endl;       else {         if (a[0] < b[0])           cout << a[0] * 10 + b[0] << endl;         else           cout << b[0] * 10 + a[0] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int n, m;   char c[maxn][maxn];   static int dx[] = {-1, 0, 0, 1};   static int dy[] = {0, -1, 1, 0};   namespace dsu {   int fa[maxn * maxn];   int cnt[maxn * maxn];   int id(int x, int y) { return x * m + y; }   int findfa(int x) {     if (fa[x] == x) return x;     return fa[x] = findfa(fa[x]);   }   void unite(int x, int y) {     x = findfa(x);     y = findfa(y);     if (x == y) return;     if (cnt[x] < cnt[y]) swap(x, y);     fa[y] = x;     cnt[x] += cnt[y];   }   }  // namespace dsu   using namespace dsu;   bool judge(int x, int y) {     if (x < 0 || y < 0 || x >= n || y >= m) return 0;     if (c[x][y] ==  * ) return 0;     return 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> c[i][j];       }     for (int i = 0; i < n * m; i++) fa[i] = i, cnt[i] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (c[i][j] ==  * ) continue;         for (int k = 0; k < 4; k++) {           int _i = i + dx[k];           int _j = j + dy[k];           if (!judge(_i, _j)) continue;           int id1 = id(i, j);           int id2 = id(_i, _j);           unite(id1, id2);         }       }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] !=  * ) {           cout <<  . ;           continue;         }         set<int> st;         for (int k = 0; k < 4; k++) {           int _i = i + dx[k];           int _j = j + dy[k];           if (!judge(_i, _j)) continue;           st.insert(findfa(id(_i, _j)));         }         int ans = 0;         while (!st.empty()) {           int id = *st.begin();           st.erase(st.begin());           ans += cnt[id];         }         cout << (ans + 1) % 10;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int b, d, ct;   int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   int main() {     cin >> b >> d;     while (gcd(b, d) > 1) {       d /= gcd(b, d);       ++ct;     }     if (d == 1)       cout <<  2-type n  << ct <<   n ;     else if (!ct && b % d == 1)       cout <<  3-type n ;     else if (!ct && b % d == d - 1)       cout <<  11-type n ;     else if ((b - 1) * (b + 1) / (b % 2 + 1) % d == 0)       cout <<  6-type n ;     else       cout <<  7-type n ;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, mod, sumz, sumy, sum, last, first, kol, z;   long long run(long long x, long long step) {     long long res = 1;     while (step) {       if (step & 1) res = (res * x) % mod;       x = x * x % mod;       step >>= 1;     }     return res % mod;   }   int main() {     cin >> a >> b;     mod = 1000 * 1000 * 1000 + 7;     sumz = (a * b) % mod;     sumz = (sumz * (b - 1)) % mod;     sumz = (sumz * run(2, mod - 2)) % mod;     sumy = (a * (a + 1)) % mod;     sumy = (sumy * b) % mod;     sumy = (sumy * (b - 1)) % mod;     sumy = (sumy * run(4, mod - 2)) % mod;     sum = ((b * sumy) % mod + sumz) % mod;     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int ans = 0;     int tub[3] = {0};     int n, a;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a);       tub[a % 3]++;     }     ans = (tub[0] / 2) + ((tub[1] > tub[2]) ? tub[2] : tub[1]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const double EPS = 1e-7;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     string s;     cin >> s;     int ans = 0;     for (int i = n; i < (int)s.length(); i += n) {       bool equal = true;       for (int j = 1; j <= 3; j++)         if (s[i - j] != s[i - 1]) equal = false;       if (equal) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int din[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   bool correct(int d, int m, int y) {     if (d > 31 || m > 12 || y > 99) return false;     int dc = din[m - 1];     if (y % 4 == 0 && m == 2) dc++;     if (d > dc) return false;     return true;   }   bool good(int db, int mb, int yb, int df, int mf, int yf) {     yb += 18;     if (yb > yf) return false;     if (yb < yf) return true;     if (mb > mf) return false;     if (mb < mf) return true;     if (db > df) return false;     return true;   }   int main() {     int db, mb, yb, df, mf, yf;     scanf( %d.%d.%d , &df, &mf, &yf);     scanf( %d.%d.%d , &db, &mb, &yb);     if (correct(db, mb, yb) && good(db, mb, yb, df, mf, yf)) {       cout <<  YES ;       return 0;     }     if (correct(db, yb, mb) && good(db, yb, mb, df, mf, yf)) {       cout <<  YES ;       return 0;     }     if (correct(mb, db, yb) && good(mb, db, yb, df, mf, yf)) {       cout <<  YES ;       return 0;     }     if (correct(mb, yb, db) && good(mb, yb, db, df, mf, yf)) {       cout <<  YES ;       return 0;     }     if (correct(yb, db, mb) && good(yb, db, mb, df, mf, yf)) {       cout <<  YES ;       return 0;     }     if (correct(yb, mb, db) && good(yb, mb, db, df, mf, yf)) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int N = 23;   int n, m, u, v, adj[N], hamsaye[1 << N], ans = N, ans2;   bool connected[1 << N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (2 * m == n * (n - 1)) {       cout << 0 <<   n ;       return 0;     }     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--, v--;       adj[u] ^= 1 << v;       adj[v] ^= 1 << u;     }     for (int i = 0; i < n; i++) adj[i] ^= (1 << i);     connected[0] = true;     for (int mask = 1; mask < (1 << n); mask++) {       if (__builtin_popcount(mask) == 1) {         connected[mask] = true;         continue;       }       for (int i = 0; i < n; i++) {         if ((adj[i] & (mask ^ (1 << i))) && connected[mask ^ (1 << i)])           connected[mask] = true;       }     }     for (int mask = 1; mask < (1 << n); mask++) {       hamsaye[mask] =           adj[__builtin_ctz(mask)] | hamsaye[mask ^ (1 << __builtin_ctz(mask))];       if (connected[mask] && __builtin_popcount(hamsaye[mask]) == n) {         if (__builtin_popcount(mask) < ans) {           ans = __builtin_popcount(mask);           ans2 = mask;         }       }     }     cout << ans <<   n ;     for (int i = 0; i < n; i++)       if (ans2 & (1 << i)) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     auto n = 19;     auto t = 1;     while (true) {       auto temp = n;       auto sum = 0;       while (temp > 0) {         auto a = temp % 10;         temp = temp / 10;         sum = sum + a;       }       if (sum == 10) {         if (t == k) {           break;         } else {           t++;         }       }       n++;     }     cout << n <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k;     cin >> k;     string s, t;     cin >> s;     cin >> t;     int sarr[k];     int tarr[k];     for (int i = k - 1; i >= 0; i--) {       sarr[i] = s[i] -  a ;       tarr[i] = t[i] -  a ;     }     int sumarr[k + 1];     int carry = 0;     for (int i = k - 1; i >= 0; i--) {       sumarr[i + 1] = (sarr[i] + tarr[i] + carry) % 26;       if (sarr[i] + tarr[i] + carry >= 26) {         carry = 1;       } else {         carry = 0;       }     }     sumarr[0] = carry;     for (int i = 0; i <= k; i++) {       if (sumarr[i] % 2 == 1) {         sumarr[i + 1] += 26;       }       sumarr[i] /= 2;     }     for (int i = 1; i <= k; i++) {       cout << (char)(sumarr[i] +  a );     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, c = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (!x && !c)         c = 1;       else if (c == 1 && !x)         c = 2;     }     if (n == 1) {       if (x)         printf( YES n );       else         printf( NO n );     } else {       if (c == 1)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const long long int INFLL = 1e18 + 10;   const long double EPS = 1e-8;   const long double EPSLD = 1e-14;   const long long int MOD = 1000000007;   template <class T>   T &chmin(T &a, const T &b) {     return a = min(a, b);   }   template <class T>   T &chmax(T &a, const T &b) {     return a = max(a, b);   }   const int MAX_N = 256;   int x, n, ip;   long double p;   int a[MAX_N];   long double dp[2][MAX_N][MAX_N];   long double dp2[2][MAX_N];   long double ans;   int main() {     scanf( %d %d %d , &x, &n, &ip);     p = (long double)ip / 100.0;     int nx = x;     int it = 0;     while (x > 0) {       a[it++] = x % 2;       x /= 2;     }     if (nx % 256 == 0) {       for (int i = (8); i < (int)(MAX_N); i++) {         if (a[i] == 1) {           dp2[0][i - 8] = 1.0;           break;         }       }     } else {       for (int i = (8); i < (int)(MAX_N); i++) {         if (a[i] == 0) {           dp[0][i - 8][nx % 256] = 1.0;           break;         }       }     }     for (int i = (0); i < (int)(n); i++) {       for (int j = (0); j < (int)(MAX_N); j++)         for (int k = (0); k < (int)(MAX_N); k++) dp[(i + 1) % 2][j][k] = 0.0;       for (int j = (0); j < (int)(MAX_N); j++) dp2[(i + 1) % 2][j] = 0.0;       for (int j = (0); j < (int)(MAX_N); j++)         for (int k = (0); k < (int)(MAX_N); k++)           if (dp[i % 2][j][k] > EPSLD) {             int nk = k + 1;             if (nk == 256) {               dp2[(i + 1) % 2][j] += dp[i % 2][j][k] * (1.0 - p);             } else {               dp[(i + 1) % 2][j][nk] += dp[i % 2][j][k] * (1.0 - p);             }             if (k / 128 == 1) {               if (k % 128 == 0) {                 dp2[(i + 1) % 2][0] += dp[i % 2][j][k] * p;               } else {                 dp[(i + 1) % 2][j + 1][(k * 2) % 256] += dp[i % 2][j][k] * p;               }             } else {               dp[(i + 1) % 2][0][(k * 2) % 256] += dp[i % 2][j][k] * p;             }           }       for (int j = (0); j < (int)(MAX_N); j++)         if (dp2[i % 2][j] > EPSLD) {           dp[(i + 1) % 2][0][1] += dp2[i % 2][j] * (1.0 - p);           dp2[(i + 1) % 2][j + 1] += dp2[i % 2][j] * p;         }     }     for (int j = (0); j < (int)(MAX_N); j++)       for (int k = (0); k < (int)(MAX_N); k++)         if (dp[n % 2][j][k] > EPSLD) {           int nk = k;           int res = 0;           while (nk % 2 == 0) {             res++;             nk /= 2;           }           ans += dp[n % 2][j][k] * res;         }     for (int j = (0); j < (int)(MAX_N); j++)       if (dp2[n % 2][j] > EPSLD) {         ans += dp2[n % 2][j] * (8 + j);       }     printf( %.18lf n , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> s;   vector<vector<int> > t;   bool sortFunc(vector<int> a, vector<int> b) {     if (a.size() == 0) return false;     if (b.size() == 0) return true;     return a.size() < b.size();   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     s.resize(n + 1);     for (int i = 1; i <= n; i++) cin >> s[i];     vector<bool> was(n + 1, false);     int index = 0;     t.push_back(vector<int>());     for (int i = 1; i <= n; i++) {       if (was[i]) continue;       int ind = i;       while (!was[ind]) {         was[ind] = true;         t[index].push_back(ind);         ind = s[ind];       }       t.push_back(vector<int>());       index++;     }     vector<int> sol(n + 1);     sort(t.begin(), t.end(), sortFunc);     bool poss = true;     for (int i = 0; i < index; i++) {       vector<int> real;       if (t[i].size() % 2 == 1) {         real.resize(t[i].size());         for (int j = 0; j < t[i].size() / 2; j++) {           real[j * 2] = t[i][j];           int b = t[i].size() / 2 + 1 + j;           real[j * 2 + 1] = t[i][b];         }         int b = t[i].size() / 2;         real[t[i].size() - 1] = t[i][b];       } else if (t[i + 1].size() == t[i].size()) {         real.resize(2 * t[i].size());         for (int j = 0; j < t[i].size(); j++) {           real[2 * j] = t[i][j];           real[2 * j + 1] = t[i + 1][j];         }         i++;       } else         poss = false;       for (int j = 0; j < real.size(); j++) {         sol[real[j]] = real[(j + 1) % real.size()];       }     }     if (poss) {       for (int i = 1; i <= n; i++) {         cout << sol[i] <<    ;       }       cout <<   n ;     } else {       cout <<  -1 n ;     }   }