Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.

Let [*n*] denote the set {1, ..., *n*}. We will also write *f*: [*x*] → [*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*.

Now then, you are given a function *f*: [*n*] → [*n*]. Your task is to find a positive integer *m*, and two functions *g*: [*n*] → [*m*], *h*: [*m*] → [*n*], such that *g*(*h*(*x*)) = *x* for all <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a256711cc012560db991a322ff7b75323883dd8e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and *h*(*g*(*x*)) = *f*(*x*) for all <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2ad9b8e566fe6c09697f5cee64720999d04e8a6f.png" style="max-width: 100.0%;max-height: 100.0%;"/>, or determine that finding these is impossible.
The first line contains an integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>).

The second line contains *n* space-separated integers — values *f*(1), ..., *f*(*n*) (1 ≤ *f*(*i*) ≤ *n*).
none
3
1 2 3
3
1 2 3
1 2 3
3
2 2 2
1
1 1 1
2
2
2 1
-1
1
1
1
1
1
2
2 1
-1
2
2 2
1
1 1
2
5
5 5 5 3 5
-1
10
4 4 4 4 4 4 4 4 4 4
1
1 1 1 1 1 1 1 1 1 1
4
2
1 2
2
1 2
1 2
3
3 2 3
2
2 1 2
2 3
3
1 2 1
2
1 2 1
1 2
4
4 2 4 4
2
2 1 2 2
2 4
5
1 4 5 4 5
3
1 2 3 2 3
1 4 5
4
1 2 1 2
2
1 2 1 2
1 2
5
1 3 3 4 4
3
1 2 2 3 3
1 3 4
4
4 2 2 4
2
2 1 1 2
2 4
7
7 3 3 5 5 7 7
3
3 1 1 2 2 3 3
3 5 7
6
1 1 1 3 3 3
-1
4
2 2 3 2
2
1 1 2 1
2 3
6
1 2 3 4 5 5
5
1 2 3 4 5 5
1 2 3 4 5
3
1 1 2
-1
4
3 4 3 4
2
1 2 1 2
3 4
6
1 1 1 4 4 4
2
1 1 1 2 2 2
1 4
4
1 2 1 1
2
1 2 1 1
1 2
5
1 2 3 4 3
4
1 2 3 4 3
1 2 3 4
4
2 2 4 4
2
1 1 2 2
2 4
4
1 1 3 3
2
1 1 2 2
1 3
3
2 2 3
2
1 1 2
2 3
5
5 3 3 3 5
2
2 1 1 1 2
3 5
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof a)
#define R(i,s,t) for(register int i=s;i<=t;++i)
#define Rd(i,s,t) for(register int i=s;i>=t;--i)
#define RR(i,a) for(register int i=0;i<int(a.size());++i)
#define __ puts("")
#define _ putchar(' ')
#define all(T) T.begin(),T.end()
#define rall(T) T.rbegin(),T.rend()
#define sz(a) int(a.size())
#define mma max_element
#define mmi min_element
#define acu accumulate
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef double DB;
template <class T> T abs(T a){return a>=0?a:-a;}
template <class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template <class T> T mod(T a,T b){T ret=a%b;if(ret<0)ret+=b;return ret;}
ll mulmod(ll a,ll b,ll c){if(b==0LL)return 0LL;ll ret=mulmod(a,b>>1,c);ret=(ret+ret)%c;if(b&1LL)ret=(ret+a)%c;return ret;}
ll powmod(ll a,ll b,ll c){if(b==0LL)return 1LL;ll ret=powmod(a,b>>1,c);ret=ret*ret%c;if(b&1LL)ret=ret*a%c;return ret;}
template <class T> inline void wt(T x){if (x<0)putchar('-'),x=-x;if (x<10)putchar(x + '0');else wt(x / 10), putchar(x % 10 + '0');}
template <class T> inline void rd(T&x){bool f=0; char ch;for(ch=getchar();ch<=32;ch=getchar());if (ch=='-')f=1,ch=getchar();for(x=0;ch>32;ch=getchar()) x =(x<<3)+(x<<1)+ch-'0';if(f) x=-x;}
/* .................................................................................................................................. */
const int N=100005;
int tt;
int u,v,w,n,m;
/* .................................................................................................................................. */
int f[N],g[N],h[N];
int main(){
    rd(n);
    R(i,1,n)rd(f[i]);
    R(i,1,n)if(f[i]==i){
        m++;h[m]=i;g[i]=m;
    }
    R(i,1,m)if(g[f[i]]==0){
        puts("-1");
        return 0;
    }
    wt(m);__;
    R(i,1,n){if(i-1)_;wt(g[f[i]]);}__;
    R(i,1,m){if(i-1)_;wt(h[i]);}__;
    return 0;
}
/*







*/




