#include <bits/stdc++.h>
using namespace std;
int matrix[1005][1005];
vector<int> fs;
vector<int> hs;
vector<int> gs;
int counter = 0;
void hset(int i, int v) {
  fs[i] = v;
  if (fs[i] == i) {
    gs[i] = ++counter;
    hs[gs[i]] = i;
  }
}
int main() {
  int n;
  cin >> n;
  fs = vector<int>(n + 1);
  gs = vector<int>(n + 1);
  hs = vector<int>(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> fs[i];
    hset(i, fs[i]);
  }
  for (int i = 1; i <= n; ++i) {
    if (fs[fs[i]] != fs[i]) {
      cout << -1;
      return 0;
    }
    gs[i] = gs[fs[i]];
  }
  cout << counter << "\n";
  for (int i = 1; i <= n; ++i) {
    cout << gs[i] << " ";
  }
  cout << "\n";
  for (int i = 1; i <= counter; ++i) {
    cout << hs[i] << " ";
  }
  return 0;
}
