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.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            DArtsemAndSaunders solver = new DArtsemAndSaunders();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DArtsemAndSaunders {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.readInt();
            int[] f = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                f[i] = in.readInt();
            }
            int m = 0;
            for (int i = 1; i <= n; i++) {
                if (f[f[i]] != f[i]) {
                    out.println(-1);
                    return;
                }
                if (f[i] == i) {
                    m++;
                }
            }

            boolean[] handled = new boolean[n + 1];
            int cur = 1;
            int[] g = new int[n + 1];
            int[] h = new int[m + 1];
            for (int i = 1; i <= n; i++) {
                if (handled[f[i]]) {
                    continue;
                }
                handled[f[i]] = true;
                g[f[i]] = cur++;
            }
            for (int i = 1; i <= n; i++) {
                g[i] = g[f[i]];
            }
            for (int i = 1; i <= n; i++) {
                h[g[i]] = f[i];
            }
            boolean valid = true;
            for (int i = 1; i <= m; i++) {
                if (g[h[i]] != i) {
                    valid = false;
                }
            }
            for (int i = 1; i <= n; i++) {
                if (h[g[i]] != f[i]) {
                    valid = false;
                }
            }
            if (!valid) {
                out.println(-1);
                return;
            }
            out.println(m);
            for (int i = 1; i <= n; i++) {
                out.print(g[i]);
                out.append(' ');
            }
            out.println();
            for (int i = 1; i <= m; i++) {
                out.print(h[i]);
                out.append(' ');
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}

