#include <bits/stdc++.h>
int n;
int f[100001], g[100001], h[100001];
int x[100001];
int main() {
  int m = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (x[f[i]] == 0) {
      if (f[f[i]] == f[i]) {
        x[f[i]] = m;
        m++;
      } else {
        printf("-1");
        return 0;
      }
    }
  }
  m--;
  for (int i = 1; i <= n; i++) {
    g[i] = x[f[i]];
    h[x[f[i]]] = f[i];
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) {
    printf("%d ", g[i]);
  }
  printf("\n");
  for (int i = 1; i <= m; i++) {
    printf("%d ", h[i]);
  }
  return 0;
}
