#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 10;
const int MOD = (int)1e9 + 7;
int n;
int first[N];
int g[N];
int h[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &first[i]);
  }
  int sz = 0;
  map<int, int> used;
  for (int i = 1; i <= n; i++) {
    if (!used.count(first[i])) {
      sz++;
      h[sz] = first[i];
      used[first[i]] = sz;
    }
    g[i] = used[first[i]];
  }
  for (int x = 1; x <= sz; x++) {
    if (g[h[x]] != x) {
      cout << -1;
      return 0;
    }
  }
  for (int x = 1; x <= n; x++) {
    if (h[g[x]] != first[x]) {
      cout << -1;
      return 0;
    }
  }
  cout << sz << endl;
  for (int i = 1; i <= n; i++) printf("%d ", g[i]);
  puts("");
  for (int i = 1; i <= sz; i++) printf("%d ", h[i]);
  return 0;
}
