#include <bits/stdc++.h>
using namespace std;
int f[1000010], g[1000010], h[1000010];
int pi[1000010];
int main() {
  int n;
  cin >> n;
  vector<int> has;
  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
    if (pi[f[i]] == 0) has.push_back(f[i]);
    if (pi[f[i]] == 0) pi[f[i]] = has.size();
  }
  for (int i = 0; i < has.size(); ++i) {
    if (f[has[i]] != has[i]) {
      cout << -1;
      return 0;
    }
  }
  cout << has.size() << endl;
  for (int i = 1; i <= n; ++i) {
    cout << pi[f[i]] << ' ';
  }
  cout << endl;
  for (int i = 0; i < has.size(); ++i) cout << has[i] << ' ';
  return 0;
}
