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