#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
int f[maxn];
int g[maxn];
int h[maxn];
int ans[maxn];
int mph[maxn];
void work() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> f[i];
  int m = 0;
  for (int i = 1; i <= n; ++i) {
    if (f[i] == i) {
      g[i] = ++m;
      h[m] = i;
      mph[i] = m;
    }
  }
  if (m == 0) {
    cout << "-1" << endl;
    return;
  }
  for (int i = 1; i <= n; ++i) {
    if (g[i] != 0 && h[g[i]] != f[i]) {
      cout << -1 << endl;
      return;
    }
    if (g[i] == 0) {
      if (!mph[f[i]]) {
        cout << -1 << endl;
        return;
      }
      g[i] = mph[f[i]];
    }
    if (i <= m && g[h[i]] != i && g[h[i]] != 0) {
      cout << -1 << endl;
      return;
    }
    if (g[h[i]] == 0) {
      g[h[i]] = i;
      i--;
    }
  }
  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;
}
int main() {
  work();
  return 0;
}
