#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int b[100001];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> a[i + 1];
    b[a[i + 1]] = 1;
  }
  vector<int> v;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) {
      v.push_back(i);
      if (a[i] != i) {
        cout << -1 << endl;
        return 0;
        ;
      }
    }
  }
  int m = v.size();
  cout << m << endl;
  int g[n + 1], h[m + 1];
  unordered_map<int, int> mm;
  for (int i = 0; i < m; ++i) {
    h[i + 1] = v[i];
    mm[v[i]] = i + 1;
  }
  for (int i = 0; i < n; ++i) {
    int x = a[i + 1];
    x = mm[x];
    g[i + 1] = x;
  }
  for (int i = 0; i < n; ++i) {
    cout << g[i + 1] << " ";
  }
  cout << endl;
  for (int i = 0; i < m; ++i) {
    cout << h[i + 1] << " ";
  }
  cout << endl;
  return 0;
}
