#include <bits/stdc++.h>
using namespace std;
int n;
int f[100001];
int g[100001];
int h[100001];
int g_inv[100001];
int h_inv[100001];
bool seen[100001];
int ok = true;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    f[i] = tmp - 1;
    seen[f[i]] = true;
  }
  int m = 0;
  for (int i = 0; i < n; i++) {
    if (seen[i]) {
      h[m] = i;
      h_inv[i] = m;
      m++;
    }
  }
  for (int i = 0; i < n; i++) {
    g[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int hx = h[i];
    if (g[hx] != -1 && g[hx] != i) {
      ok = false;
    }
    g[hx] = i;
  }
  for (int i = 0; i < n; i++) {
    int gx = h_inv[f[i]];
    if (g[i] != -1 && g[i] != gx) {
      ok = false;
    }
    g[i] = gx;
  }
  for (int i = 0; i < n; i++) {
    if (g[i] == -1) g[i] = 0;
  }
  if (!ok) {
    cout << "-1";
    return 0;
  }
  cout << m << "\n";
  for (int i = 0; i < n - 1; i++) {
    cout << g[i] + 1 << " ";
  }
  cout << g[n - 1] + 1 << "\n";
  for (int i = 0; i < m - 1; i++) {
    cout << h[i] + 1 << " ";
  }
  cout << h[m - 1] + 1 << "\n";
}
