#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     scanf( %d , &n);     vector<int> f(n + 1, -1);     vector<int> g(n + 1, -1);     vector<int> h(1);     int m = 0;     vector<bool> b(n + 1, false);     for (int i = 1; i <= n; i++) {       scanf( %d , &f[i]);       if (f[i] == i) {         m++;         h.push_back(i);         g[i] = m;         b[i] = true;       }     }     for (int i = 1; i <= n; i++) {       if (f[i] != i) {         int to = g[f[i]];         if (b[f[i]] == false || to == -1) {           puts( -1 );           return 0;         }         g[i] = to;       }     }     printf( %d n , m);     for (int i = 1; i <= n; i++) {       if (i > 1) {         putchar(   );       }       printf( %d , g[i]);     }     puts(  );     for (int i = 1; i <= m; i++) {       if (i > 1) {         putchar(   );       }       printf( %d , h[i]);     }     puts(  );     return 0;   }   