#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f[100009], h[100009], g[100009];
  bool vis[100009] = {false};
  int m = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (f[i] == i) {
      h[m + 1] = i;
      g[i] = m + 1;
      vis[i] = true;
      m++;
    }
  }
  bool flag = (m > 0);
  for (int i = 1; i <= n; i++) {
    if (f[i] != i && !vis[f[i]]) {
      flag = false;
      break;
    } else if (f[i] != i) {
      g[i] = g[f[i]];
    }
  }
  if (!flag)
    cout << -1 << "\n";
  else {
    cout << m << "\n";
    for (int i = 1; i <= n; i++) cout << g[i] << " ";
    cout << "\n";
    for (int i = 1; i <= m; i++) cout << h[i] << " ";
    cout << "\n";
  }
  return 0;
}
