#include <bits/stdc++.h>
int main() {
  size_t n;
  std::cin >> n;
  std::vector<size_t> f(n + 1);
  for (size_t x = 1; x <= n; ++x) {
    std::cin >> f[x];
  }
  size_t m = 0;
  std::vector<std::vector<size_t>> f_preimage(n + 1);
  for (size_t x = 1; x <= n; ++x) {
    auto& xs = f_preimage[f[x]];
    if (xs.empty()) {
      ++m;
    }
    xs.push_back(x);
  }
  std::vector<size_t> h(m + 1);
  std::vector<size_t> g(n + 1);
  size_t hx = 0;
  for (size_t fy = 1; fy <= n; ++fy) {
    if (!f_preimage[fy].empty()) {
      h[++hx] = fy;
      bool valid = false;
      for (size_t fx : f_preimage[fy]) {
        g[fx] = hx;
        if (fx == fy) {
          valid = true;
        }
      }
      if (!valid) {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
  }
  std::cout << m << std::endl;
  for (size_t x = 1; x <= n; ++x) {
    std::cout << g[x] << " ";
  }
  std::cout << std::endl;
  for (size_t x = 1; x <= m; ++x) {
    std::cout << h[x] << " ";
  }
  std::cout << std::endl;
  return 0;
}
