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