#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
vector<int> v[100005];
int g[100005], h[100005], f[100005], id[100005];
set<int> H;
int main() {
  int n, m = 0;
  scanf("%d", &n);
  for (int k = 1; k <= (n); k++) scanf("%d", &f[k]);
  for (int k = 1; k <= (n); k++) {
    if (f[f[k]] != f[k]) {
      printf("-1");
      return 0;
    }
    H.insert(f[k]);
  }
  for (set<int>::iterator it = H.begin(); it != H.end(); it++) {
    h[++m] = *it;
    id[*it] = m;
  }
  for (int k = 1; k <= (n); k++) g[k] = id[f[k]];
  printf("%d\n", m);
  for (int k = 1; k <= (n); k++) printf("%d ", g[k]);
  putchar('\n');
  for (int k = 1; k <= (m); k++) printf("%d ", h[k]);
  return 0;
}
