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