#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100, inf = 1e9, ninf = -inf, MOD = 1e9 + 7;
int n, m, f[MAXN], g[MAXN], h[MAXN];
char s[1005];
bool llegada[MAXN], anda;
int main() {
  while (cin >> n) {
    memset(llegada, 0, sizeof llegada);
    anda = true;
    m = 0;
    for (int i = 0; i < (int)(n); i++) {
      cin >> f[i];
      f[i]--;
    }
    for (int i = 0; i < (int)(n); i++) llegada[f[i]] = true;
    for (int i = 0; i < (int)(n); i++) {
      if (llegada[i]) {
        if (f[i] != i) {
          anda = false;
          break;
        }
        g[i] = m;
        h[m] = i;
        m++;
      }
    }
    if (!anda) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 0; i < (int)(n); i++) g[i] = g[f[i]];
    cout << m << endl;
    for (int i = 0; i < (int)(n); i++) cout << g[i] + 1 << " ";
    cout << endl;
    for (int i = 0; i < (int)(m); i++) cout << h[i] + 1 << " ";
    cout << endl;
  }
  return 0;
}
