Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.

Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.

Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

Output

If there is no answer, print one integer -1.

Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).

If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.

Examples

Input

3
1 2 3


Output

3
1 2 3
1 2 3


Input

3
2 2 2


Output

1
1 1 1
2


Input

2
2 1


Output

-1
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author littlesheep
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        private int desired;
        private boolean[] vis;
        private int[] number;
        private List<Integer> nodes;
        private Edge[] first;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            first = new Edge[n];
            vis = new boolean[n];

            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                --a[i];
                new Edge(i, a[i]);
                new Edge(a[i], i);
            }

            boolean[] appeared = new boolean[n];
            this.number = a;
            this.nodes = new ArrayList<>();

            boolean good = true;
            int[] first = new int[n];
            int[] second = new int[n];

            int components = 0;
            for (int i = 0; i < n; ++i) {
                if (vis[i]) {
                    continue;
                }
                desired = a[i];
                if (appeared[desired]) {
                    good = false;
                    break;
                }
                appeared[desired] = true;
                nodes.clear();
                dfs(i);
                if (desired == -1) {
                    good = false;
                    break;
                }

                for (Integer node : nodes) {
                    first[node] = components;
                }
                second[components++] = desired;
            }

            if (!good) {
                out.println(-1);
                return;
            }

            out.println(components);
            for (int i = 0; i < n; ++i) {
                if (i != 0) out.print(" ");
                out.print(first[i] + 1);
            }
            out.println();
            for (int i = 0; i < components; ++i) {
                if (i != 0) out.print(" ");
                out.print(second[i] + 1);
            }
            out.println();
        }

        void dfs(int x) {
            nodes.add(x);
            if (desired != number[x]) {
                desired = -1;
            }
            vis[x] = true;
            for (Edge e = first[x]; e != null; e = e.next) {
                if (!vis[e.to]) {
                    dfs(e.to);
                }
            }
        }

        class Edge {
            int to;
            Edge next;

            Edge(int from, int to) {
                this.to = to;
                this.next = first[from];
                first[from] = this;
            }

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new UnknownError();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

