#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn], n, b[maxn], c[maxn], m;
map<int, int> H;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    if (a[a[i]] != a[i]) {
      cout << "-1" << endl;
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (!H[a[i]]) {
      m++;
      H[a[i]] = m;
      c[m] = a[i];
    }
    b[i] = H[a[i]];
  }
  cout << m << endl;
  for (int i = 1; i <= n; i++) cout << b[i] << " ";
  cout << endl;
  for (int i = 1; i <= m; i++) cout << c[i] << " ";
  cout << endl;
}
