Problem: 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

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class D
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] f = new int[n];
		int[] tmp = new int[100000+5];
		int nnn = 0;
		Arrays.fill(tmp, -1);
		ArrayList<Integer> rr = new ArrayList<Integer>();
		for (int i = 0; i < f.length; i++)
		{
			f[i] = sc.nextInt();
			if(tmp[f[i]] == -1)
			{
				tmp[f[i]] = ++nnn;
				rr.add(f[i]);
			}
		}
		
		int[] h = new int[rr.size()];
		for (int i = 0; i < h.length; i++)
		{
			h[i] = rr.get(i);
		}
		int[] g = new int[n];
		
		
		for (int i = 0; i < h.length; i++)
		{
			g[h[i]-1] = (i+1);
		}
		
		for (int i = 0; i < h.length; i++)
		{
			if(g[h[i] - 1] != (i+1))
				if(g[h[i]-1] == 0)
					g[h[i]-1] = (i+1);
				else
				{
					System.out.println(-1);
					return;
				}
		}
		
		
		for (int i = 0; i < g.length; i++)
		{
			if(g[i] == 0)
			{
				g[i] = tmp[f[i]];
			}
			else
				if(h[g[i]-1] != f[i])
				{
					System.out.println(-1);
					return;
				}
		}
		

		
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(rr.size());
		for (int i = 0; i < g.length; i++)
		{
			if(i == 0)
				pw.print(g[i]);
			else
				pw.print(" " + g[i]);
		}
		pw.println();
		for (int i = 0; i < h.length; i++)
		{
			if(i == 0)
				pw.print(h[i]);
			else
				pw.print(" " + h[i]);
		}
		pw.println();
		pw.flush();
		pw.close();
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(String s) throws FileNotFoundException
		{
			br = new BufferedReader(new FileReader(new File(s)));
		}
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
		
		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}
		
		public boolean ready() throws IOException {return br.ready();}

	}
}