Problem: 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 <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

Output

If there is no answer, print one integer -1.

Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).

If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.

Examples

Input

3
1 2 3


Output

3
1 2 3
1 2 3


Input

3
2 2 2


Output

1
1 1 1
2


Input

2
2 1


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
template <class T>
T sqr(T x) {
  return x * x;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int n, h[MAXN], g[MAXN], vs[MAXN], G, a[MAXN];
vector<int> adj[MAXN], has[MAXN];
void dfs(int u, int p) {
  vs[u] = 1;
  has[G].push_back(u);
  for (int i = 0; i < ((int)(adj[u]).size()); i++) {
    int v = adj[u][i];
    if (vs[v]) continue;
    dfs(v, u);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    adj[i].push_back(a[i]);
    adj[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (!vs[i]) {
      dfs(i, 0);
      G++;
    }
  }
  int m = 0;
  for (int i = 0; i < G; i++) {
    int cur = a[has[i][0]];
    g[has[i][0]] = i + 1;
    for (int j = 1; j < ((int)(has[i]).size()); j++) {
      if (a[has[i][j]] != cur) {
        printf("%d", -1);
        return 0;
      }
      g[has[i][j]] = i + 1;
    }
    m++;
    h[m] = cur;
  }
  for (int i = 1; i <= m; i++) {
    if (g[h[i]] != i) {
      printf("%d", -1);
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (h[g[i]] != a[i]) {
      printf("%d", -1);
      return 0;
    }
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) printf("%d ", g[i]);
  puts("");
  for (int i = 1; i <= m; i++) printf("%d ", h[i]);
  return 0;
}