#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int main() {
  int n, t = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (i == a[i]) {
      b[++t] = i;
      c[i] = t;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (c[a[i]] == 0) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", t);
  for (int i = 1; i < n; i++) printf("%d ", c[a[i]]);
  printf("%d\n", c[a[n]]);
  for (int i = 1; i < t; i++) printf("%d ", b[i]);
  printf("%d\n", b[t]);
}
