#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int cur = 0, lv = 0;
  vector<int> g, h;
  map<int, int> asd;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    if (asd.count(v)) {
      g.push_back(asd[v]);
      continue;
    }
    g.push_back(++cur);
    h.push_back(v);
    asd[v] = cur;
    lv = v;
  }
  for (int i = 0; i < h.size(); ++i) {
    if (g[h[i] - 1] - 1 != i) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << h.size() << endl;
  for (int i = 0; i < n; ++i) cout << g[i] << " ";
  cout << endl;
  for (int i : h) cout << i << " ";
  cout << endl;
}
