#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(long long a) {
  if (a < 0) {
    printf("-");
    a = -a;
  }
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
inline void writeln(long long a) {
  write(a);
  printf("\n");
}
int n, m;
int a[100010];
int b[100100];
int mrk[100010];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] == i) b[++m] = i, mrk[i] = m;
  }
  for (int i = 1; i <= n; i++)
    if (!mrk[a[i]]) {
      puts("-1");
      return 0;
    }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) printf("%d ", mrk[a[i]]);
  puts("");
  for (int i = 1; i <= m; i++) printf("%d ", b[i]);
  puts("");
}
