#include <bits/stdc++.h>
using namespace std;
int f[100005];
int h[1000005];
int numh;
int g[100005];
int numg;
int main() {
  int n;
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> f[i];
  }
  for (i = 1; i <= n; i++) {
    if (f[f[i]] == f[i]) {
      continue;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  numh = 1;
  for (i = 1; i <= n; i++) {
    if (g[f[i]] == 0) {
      g[i] = numh;
      g[f[i]] = numh;
      h[numh] = f[i];
      numh++;
    } else {
      g[i] = g[f[i]];
    }
  }
  cout << numh - 1 << endl;
  for (i = 1; i <= n; i++) {
    cout << g[i] << " ";
  }
  cout << endl;
  for (i = 1; i < numh; i++) {
    cout << h[i] << " ";
  }
  cout << endl;
}
