#include <bits/stdc++.h>
using namespace std;
int fx[123456], h[123456], g[123456];
set<int> Set, dist;
map<int, int> Map;
int main() {
  int n;
  cin >> n;
  for (long long i = (1); i <= (n); i++) {
    scanf("%d", &fx[i]);
    if (fx[i] == i) Set.insert(i);
    dist.insert(fx[i]);
  }
  if (Set.size() != dist.size()) {
    cout << -1;
    return 0;
  }
  int m = Set.size();
  cout << m << endl;
  auto it = Set.begin();
  int k = 1;
  for (; it != Set.end(); it++) {
    h[k] = *it;
    Map[*it] = k++;
  }
  for (long long i = (1); i <= (n); i++) {
    printf("%d ", Map[fx[i]]);
  }
  printf("\n");
  for (long long i = (1); i <= (m); i++) {
    printf("%d ", h[i]);
  }
}
