#include <bits/stdc++.h>
using namespace std;
using LD = long double;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout.setf(ios_base::fixed);
  cout.precision(28);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
    x[i]--;
  }
  vector<int> h, g(n, -1);
  vector<int> zn(n, -1);
  for (int i = 0; i < n; ++i) {
    if (zn[x[i]] == -1) {
      h.push_back(x[i]);
      zn[x[i]] = h.size() - 1;
    }
    g[i] = zn[x[i]];
  }
  bool ok = true;
  for (int i = 0; i < h.size(); ++i) {
    if (g[h[i]] != i) {
      ok = false;
    }
  }
  if (!ok) {
    cout << -1;
    return 0;
  }
  cout << h.size() << "\n";
  for (int i = 0; i < n; ++i) {
    cout << g[i] + 1 << " ";
  }
  cout << "\n";
  for (int i = 0; i < h.size(); ++i) {
    cout << h[i] + 1 << " ";
  }
  return 0;
}
