#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int f[MAXN], g[MAXN], h[MAXN];
int v[MAXN];
int main() {
  memset(g, 0, sizeof(g));
  int n;
  scanf("%d", &n);
  int sz = 1;
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++) {
    if (!g[f[i]]) {
      g[i] = g[f[i]] = sz++;
    } else
      g[i] = g[f[i]];
    h[g[i]] = f[i];
  }
  bool flag = 1;
  for (int i = 1; i < sz; i++) {
    if (g[h[i]] != i) flag = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (h[g[i]] != f[i]) flag = 0;
  }
  if (flag) {
    printf("%d\n", sz - 1);
    for (int i = 1; i <= n; i++) printf("%d ", g[i]);
    puts("");
    for (int i = 1; i < sz; i++) printf("%d ", h[i]);
  } else
    puts("-1");
  return 0;
}
