#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, f[N], g[N], h[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++)
    if (f[i] == i) h[g[i] = ++m] = i;
  for (int i = 1; i <= n; i++)
    if (!g[i]) {
      if (h[g[f[i]]] == f[i])
        g[i] = g[f[i]];
      else
        return puts("-1"), 0;
    }
  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]);
  puts("");
  return 0;
}
