#include <bits/stdc++.h>
using namespace std;
int a[100005], vis[100005], b[100005], h[100005], g[100005];
int main() {
  int n, m = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i) {
      g[a[i]] = ++m;
      h[m] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!g[a[i]]) {
      cout << -1;
      return 0;
    }
  }
  cout << m << endl;
  for (int i = 1; i <= n; i++) {
    cout << g[a[i]] << ' ';
  }
  cout << endl;
  for (int i = 1; i <= m; i++) cout << h[i] << ' ';
}
