#include <bits/stdc++.h>
using namespace std;
int g[100005] = {0}, h[1000005] = {0}, rankh[1000005] = {0};
int main() {
  int n, f[100005], cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> f[i];
  for (int i = 1; i <= n; i++) {
    if (rankh[f[i]] == 0) {
      cnt++;
      h[cnt] = f[i];
      rankh[f[i]] = cnt;
    }
    g[i] = rankh[f[i]];
  }
  for (int i = 1; i <= cnt; i++) {
    if (g[h[i]] != i) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", g[i]);
  }
  printf("\n");
  for (int i = 1; i <= cnt; i++) {
    if (i != 1) printf(" ");
    printf("%d", h[i]);
  }
  return 0;
}
