#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  scanf("%ld", &n);
  map<long, long> temp;
  long f[n + 5];
  for (long i = 1; i < n + 1; i++) {
    scanf("%ld", &f[i]);
  }
  vector<long> h, g;
  h.push_back(0);
  g.push_back(0);
  for (long i = 1; i < n + 1; i++) {
    if (f[f[i]] != f[i]) {
      cout << -1 << endl;
      exit(0);
    }
    if (f[i] == i) {
      temp[f[i]] = h.size();
      h.push_back(f[i]);
    }
  }
  cout << h.size() - 1 << endl;
  for (long i = 1; i < n + 1; i++) {
    g.push_back(temp[f[i]]);
  }
  for (long i = 1; i < g.size(); i++) {
    cout << g[i] << " ";
  }
  cout << endl;
  for (long i = 1; i < h.size(); i++) {
    cout << h[i] << " ";
  }
  cout << endl;
}
