#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e+9 + 7ll;
const long long linf = (long long)1e+18 + 7ll;
const long double eps = (long double)1e-10;
const long double pi = acosl((long double)-1.0);
const int alph = 26;
static char buff[(int)2e6 + 17];
const int maxn = (int)1e6 + 17;
int n;
int f[maxn], p[maxn], g[maxn];
bool read() {
  if (scanf("%d", &n) != 1) return false;
  for (int i = 0; i < n; ++i) scanf("%d", &f[i]), --f[i];
  return true;
}
void solve() {
  vector<int> h;
  for (int i = 0; i < n; ++i) h.push_back(f[i]);
  sort(h.begin(), h.end());
  h.resize(unique(h.begin(), h.end()) - h.begin());
  for (int i = 0; i < ((int)(h.size())); ++i) p[h[i]] = i;
  for (int i = 0; i < n; ++i) g[i] = p[f[i]];
  for (int i = 0; i < ((int)(h.size())); ++i)
    if (g[h[i]] != i) {
      printf("-1\n");
      return;
    }
  printf("%d\n", ((int)(h.size())));
  for (long long i = 0ll; i < (long long)n; ++i) printf("%d ", g[i] + 1);
  printf("\n");
  for (long long i = 0ll; i < (long long)((int)(h.size())); ++i)
    printf("%d ", h[i] + 1);
}
int main() {
  while (read()) solve();
  return 0;
}
