#include <bits/stdc++.h>
using namespace std;
int n, i, f[1000001], g[1000001], h[1000001], m, mark[1000001];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> f[i];
  for (i = 1; i <= n; i++) {
    if (!mark[f[i]]) {
      mark[f[i]] = 1;
      ++m;
      h[m] = f[i];
      g[f[i]] = m;
    }
  }
  for (i = 1; i <= n; i++) g[i] = g[f[i]];
  for (i = 1; i <= m; i++)
    if (g[h[i]] != i) return cout << -1, 0;
  for (i = 1; i <= n; i++)
    if (h[g[i]] != f[i]) return cout << -1, 0;
  cout << m << endl;
  for (i = 1; i <= n; i++) cout << g[i] << " ";
  cout << endl;
  for (i = 1; i <= m; i++) cout << h[i] << " ";
}
