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