#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int A[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  map<int, int> G, H, P;
  int C[n + 1];
  for (int i = 1; i <= n; i++) {
    C[i] = 0;
  }
  int m = 0;
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (i != A[i]) {
      if (C[A[i]] != 0) {
        ans = 0;
        break;
      }
      C[i] = 1;
    }
    if (P[A[i]]) {
      G[i] = P[A[i]];
      H[P[A[i]]] = A[i];
    } else {
      m++;
      P[A[i]] = m;
      G[i] = P[A[i]];
      H[P[A[i]]] = A[i];
    }
  }
  if (ans == 0) {
    cout << -1 << endl;
  } else {
    cout << m << endl;
    for (int i = 1; i <= n; i++) {
      cout << G[i] << ' ';
    }
    cout << endl;
    for (int i = 1; i <= m; i++) {
      cout << H[i] << ' ';
    }
    cout << endl;
  }
  return 0;
}
