#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int f[1000010], pos[1000010], g[1000010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &f[i]);
  for (int i = 1; i <= n; ++i) {
    if (f[i] == i) {
      v.push_back(i);
      pos[i] = v.size();
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!pos[f[i]]) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    g[i] = pos[f[i]];
  }
  printf("%d\n", v.size());
  for (int i = 1; i <= n; ++i) printf("%d ", g[i]);
  puts("");
  for (int i = 0; i < v.size(); ++i) printf("%d ", v[i]);
  return 0;
}
