#include <bits/stdc++.h>
using namespace std;
int g[100010], h[1000010], f[100010], mark[100010], flag[100010];
int main() {
  int n, m, i, j, t, count = 1, first = 1;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> f[i];
  memset(flag, 0, sizeof(flag));
  for (i = 1; i <= n; i++) {
    if (first) {
      mark[f[i]] = count;
      flag[f[i]] = 1;
      first = 0;
      continue;
    }
    if (!flag[f[i]]) {
      flag[f[i]] = 1;
      count++;
      mark[f[i]] = count;
    }
  }
  for (i = 1; i <= n; i++) {
    g[i] = mark[f[i]];
  }
  m = count;
  for (i = 1; i <= n; i++) h[g[i]] = f[i];
  for (i = 1; i <= m; i++)
    if (g[h[i]] != i) {
      cout << "-1\n";
      return 0;
    }
  cout << m << "\n";
  for (i = 1; i < n; i++) cout << g[i] << " ";
  cout << g[n] << "\n";
  for (i = 1; i < m; i++) cout << h[i] << " ";
  cout << h[m] << "\n";
  return 0;
}
