#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
  if (t < f) t = f;
}
long long N;
long long to[111111];
bool ok[111111];
vector<long long> g, h;
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (N); i++) scanf("%lld", &to[i]), to[i]--;
  for (long long i = 0; i < (N); i++)
    if (to[i] == i) ok[i] = true;
  for (long long i = 0; i < (N); i++)
    if (!ok[i] && !ok[to[i]]) {
      puts("-1");
      return 0;
    }
  g.resize(N);
  for (long long i = 0; i < (N); i++) {
    if (ok[i]) {
      g[i] = h.size();
      h.push_back(i);
    }
  }
  for (long long i = 0; i < (N); i++) {
    if (!ok[i]) {
      g[i] = g[to[i]];
    }
  }
  printf("%lld\n", (long long)h.size());
  for (long long i = 0; i < (N); i++) printf("%lld ", g[i] + 1);
  puts("");
  for (long long i = 0; i < (h.size()); i++) printf("%lld ", h[i] + 1);
  puts("");
  return 0;
}
