#include <bits/stdc++.h>
using namespace std;
map<int, int> p;
int a[100005];
int a1[100005], a2[100005];
int n, flag, pl = 1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (p[a[i]] == 0) p[a[i]] = pl++;
  }
  for (int i = 1; i <= n; i++) {
    a1[i] = p[a[i]];
    a2[a1[i]] = a[i];
  }
  int l = p.size();
  for (int i = 1; i <= l; i++) {
    if (a1[a2[i]] != i) flag = 1;
  }
  if (flag)
    printf("-1\n");
  else {
    printf("%d\n", p.size());
    for (int i = 1; i <= n; i++) {
      if (i != 1) printf(" ");
      printf("%d", a1[i]);
    }
    printf("\n");
    for (int i = 1; i <= l; i++) {
      if (i != 1) printf(" ");
      printf("%d", a2[i]);
    }
    printf("\n");
  }
  return 0;
}
