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;
void bad(string mes = "impossible") {
  cout << mes;
  exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
  string ans = "";
  while (x > 0) {
    ans += char('0' + x % st);
    x /= st;
  }
  reverse(ans.begin(), ans.end());
  return ans.empty() ? "0" : ans;
}
template <typename T>
T dcm(string& second) {
  T x = 0;
  for (int i = 0; i < second.size(); i++) {
    x = (x * 2) + (second[i] == '1');
  }
  return x;
}
template <typename T>
T input() {
  T ans = 0, m = 1;
  char c = ' ';
  while (c == ' ' || c == '\n') c = getchar();
  if (c == '-') m = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + int(c - '0'), c = getchar();
  }
  return ans * m;
}
template <typename T>
T binpow(T n, T second) {
  if (second <= 0) return 1LL;
  if (second % 2 == 0) {
    T b = binpow(n, second / 2);
    return (1LL * b * b);
  } else {
    return (1LL * binpow(n, second - 1) * n);
  }
}
string is() {
  string str;
  cin >> str;
  return str;
}
const int inf = 2e9;
const double eps = 1e-9;
const int maxn = 1e5 + 10, base = 1e9 + 7;
const long long llinf = 1e18;
int a[maxn], b[maxn];
int main() {
  int n = input<int>();
  for (int i = 0; i < n; i++) a[i] = input<int>();
  map<int, int> ans;
  int m = 1;
  int kol = 0;
  for (int i = 0; i < n; i++) {
    if (ans[a[i]] == 0) {
      ans[a[i]] = m;
      m++;
    }
    if (a[i] == i + 1) kol++;
  }
  if ((int)ans.size() != kol) {
    cout << -1;
    return 0;
  }
  cout << kol << '\n';
  int ans1[maxn], ans2[maxn];
  for (map<int, int>::iterator it = ans.begin(); it != ans.end(); it++) {
    ans1[it->second] = it->first;
  }
  for (int i = 0; i < n; i++) cout << ans[a[i]] << ' ';
  cout << '\n';
  for (int i = 1; i <= kol; i++) cout << ans1[i] << ' ';
  return 0;
}