#include <bits/stdc++.h>
using namespace std;
long long inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 1000000000000000000;
class MulticoreProcessingEasy {
 public:
  int fastestTime(int jobLength, int corePenalty, vector<int> speed,
                  vector<int> cores) {}
};
int main() {
  int a;
  while (cin >> a) {
    int A[100005] = {};
    for (int i = 1; i <= a; i++) cin >> A[i];
    int no = 0;
    for (int i = 1; i <= a; i++) {
      if (A[i] != A[A[i]]) {
        no = 1;
      }
    }
    if (no) {
      cout << -1 << '\n';
      continue;
    }
    int b[100005] = {};
    int c[100005] = {};
    int vis[100005] = {};
    int now = 0;
    for (int i = 1; i <= a; i++) {
      if (!vis[A[i]]) {
        now++;
        vis[A[i]] = now;
        c[now] = A[i];
      }
      b[i] = vis[A[i]];
    }
    cout << now << '\n';
    for (int i = 1; i <= a; i++) cout << b[i] << " ";
    cout << '\n';
    for (int i = 1; i <= now; i++) cout << c[i] << " ";
    cout << '\n';
  }
  return 0;
}
