#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
template <typename t>
t read() {
  t x = 0;
  int f = 1;
  char c = getchar();
  while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x * f;
}
template <typename t>
void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
const int maxn = 1e6 + 10;
int f[maxn], g[maxn], h[maxn], p[maxn], n, m;
int main() {
  n = read<int>();
  for (int i = 1; i <= n; i++) {
    f[i] = read<int>();
    if (i == f[i]) h[p[i] = ++m] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!p[f[i]]) return puts("-1"), 0;
    g[i] = p[f[i]];
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) printf("%d ", g[i]);
  puts("");
  for (int i = 1; i <= m; i++) printf("%d ", h[i]);
  return 0;
}
