#include <bits/stdc++.h>
using namespace std;
int n;
int a[1001001];
bool vis[1001001];
int from[1001001], m = 1;
int to[1001001];
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] && a[i] != i) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      from[m++] = i;
      to[i] = m - 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      to[i] = to[a[i]];
    }
  }
  m--;
  cout << m << endl;
  for (int i = 1; i <= n; i++) {
    cout << to[i] << " ";
  }
  cout << endl;
  for (int i = 1; i <= m; i++) {
    cout << from[i] << " ";
  }
}
