#include <bits/stdc++.h>
using namespace std;
int n, f[100010], h[100010], g[100010], chk[100010], m;
map<int, int> d, lk;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (!chk[f[i]]) h[++m] = f[i], chk[f[i]] = m;
    g[i] = chk[f[i]];
  }
  for (int i = 1; i <= m; i++)
    if (g[h[i]] != i) return cout << -1, 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;
}
