#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int f[MAXN + 1], g[MAXN + 1], h[MAXN + 1];
int main() {
  int n;
  cin >> n;
  map<int, int> calc;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    calc[f[i]]++;
  }
  int m = (int)calc.size();
  map<int, int> was;
  int cur = 1;
  for (int i = 1; i <= n; i++) {
    if (!was[f[i]]) was[f[i]] = cur++;
    g[i] = was[f[i]];
    h[g[i]] = f[i];
  }
  for (int i = 1; i <= m; i++) {
    if (g[h[i]] != i) {
      cout << -1 << endl;
      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;
}
