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:
/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

	InputReader in;
	PrintWriter out;
	Main() throws IOException {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		//in = new InputReader(new FileInputStream("output_.txt"));
		//out = new PrintWriter(new File("output_.txt"));
		solve();
		out.close();
	}

	public static void main(String args[]) {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	//--------------------My Code Starts Here----------------------
	int mod=(int)1e9+7;
	public void solve() throws IOException{
		int n=in.nextInt();
		int a[]=in.readIntBrray(n);
		HashMap<Integer, Integer> hm=new HashMap<>();
		int ptr=1;
		for(int i=0;i<n;i++){
			if(!hm.containsKey(a[i])){
				hm.put(a[i], ptr++);
			}
		}
		int g[]=new int[n+1];
		int h[]=new int[ptr];
		for(int i=1;i<=n;i++){
			g[i]=hm.get(a[i-1]);
			h[hm.get(a[i-1])]=a[i-1];
		}
		boolean ok=true;
		for(int i=1;i<=ptr-1;i++){
			if(g[h[i]]!=i){
				ok=false;
			}
		}
		for(int i=1;i<=n;i++){
			if(h[g[i]]!=a[i-1]){
				ok=false;
			}
		}
		if(!ok){
			out.println("-1");
		}
		else{
			out.println(ptr-1);
			for(int i=1;i<=n;i++){
				out.print(g[i]+" ");
			}
			out.println();
			for(int i=1;i<=ptr-1;i++){
				out.print(h[i]+" ");
			}
			out.println();
			
		}
	}
	//---------------------My Code Ends Here-----------------------
	
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		int i;
		long size;
		int pos;
		Pair(int xx,int yy){
			x=xx;
			y=yy;
		}
		@Override
		public int compareTo(Pair o) {
			if(Long.compare(this.x, o.x)!=0)
				return Long.compare(this.x, o.x);
			else
				return Long.compare(this.y, o.y);
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	static final class InputReader{
		private final InputStream stream;
		private final byte[] buf=new byte[1024];
		private int curChar;
		private int numChars;
		public InputReader(InputStream stream){this.stream=stream;}
		private int read()throws IOException{
			if(curChar>=numChars){
				curChar=0;
				numChars=stream.read(buf);
				if(numChars<=0)
					return -1;
			}
			return buf[curChar++];
		}
		public final int nextInt()throws IOException{return (int)nextLong();}
		public final long nextLong()throws IOException{
			int c=read();
			while(isSpaceChar(c)){
				c=read();
				if(c==-1) throw new IOException();
			}
			boolean negative=false;
			if(c=='-'){
				negative=true;
				c=read();
			}
			long res=0;
			do{
				if(c<'0'||c>'9')throw new InputMismatchException();
				res*=10;
				res+=(c-'0');
				c=read();
			}while(!isSpaceChar(c));
			return negative?(-res):(res);
		}
		public final int[] readIntBrray(int size)throws IOException{
			int[] arr=new int[size];
			for(int i=0;i<size;i++)arr[i]=nextInt();
			return arr;
		}
		public final String next()throws IOException{
			int c=read();
			while(isSpaceChar(c))c=read();
			StringBuilder res=new StringBuilder();
			do{
				res.append((char)c);
				c=read();
			}while(!isSpaceChar(c));
			return res.toString();
		}
		public final String nextLine()throws IOException{
			int c=read();
			while(isSpaceChar(c))c=read();
			StringBuilder res=new StringBuilder();
			do{
				res.append((char)c);
				c=read();
			}while(c!='\n'&&c!=-1);
			return res.toString();
		}
		private boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
	}
}