#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int f[N], g[N], h[N], p[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  set<int> st;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    st.insert(f[i]);
  }
  int m = 0;
  for (int x : st) {
    if (f[x] != x) {
      cout << -1;
      return 0;
    }
    m++;
    h[m] = x;
    p[x] = m;
  }
  for (int i = 1; i <= n; i++) {
    g[i] = p[f[i]];
  }
  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] << ' ';
}
