#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, m;
int f[MAXN];
int g[MAXN];
int h[MAXN];
bool used[MAXN];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (!used[f[i]]) m++;
    used[f[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    g[i] = -1;
  }
  int cur = 1;
  for (int i = 1; i <= n; i++) {
    if (g[f[i]] == -1) {
      g[i] = cur;
      g[f[i]] = cur;
      cur++;
    } else {
      g[i] = g[f[i]];
    }
  }
  for (int i = 1; i <= n; i++) {
    h[g[i]] = f[i];
  }
  for (int i = 1; i <= n; i++) {
    if ((g[i] < 1) || g[i] > m) {
      cout << "-1\n";
      return 0;
    }
    if (h[g[i]] != f[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    if ((h[i] < 1) || (h[i] > n)) {
      cout << "-1\n";
      return 0;
    }
    if (g[h[i]] != i) {
      cout << "-1\n";
      return 0;
    }
  }
  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;
}
