#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int f[200000 + 1];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> f[i];
  }
  map<int, int> index;
  vector<int> values;
  map<int, int> h;
  values.push_back(0);
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (h[f[i]] == 0) {
      ans++;
      if (f[f[i]] != f[i]) {
        cout << -1 << '\n' << flush;
        return 0;
      }
      index[f[i]] = ans;
      values.push_back(f[i]);
    }
    h[f[i]]++;
  }
  int m = ans;
  cout << m << '\n';
  for (int i = 1; i < n + 1; i++) {
    cout << index[f[i]] << " ";
  }
  cout << '\n';
  for (int i = 1; i < m + 1; i++) {
    cout << values[i] << " ";
  }
}
