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.DataInputStream;
import java.util.HashMap;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;

public class Main
{
	static class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[201]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1)
			{
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}
        static int pa[],R[];
        static int find(int u){
         if(pa[u]==u)return u;
         else return pa[u]=find(pa[u]);
        }
        static void m(int u,int v){
         int pu=find(u),pv=find(v);
         if(R[pu]==R[pv])R[pv]++;
         if(R[pu]>R[pv]){pu^=pv;pv^=pu;pu^=pv;}
         pa[pu]=pv;
        }
        public static void main(String[] args) throws IOException
	{
		Reader s=new Reader();PrintWriter pw=new PrintWriter(System.out);
                int n=s.nextInt();
                int f[]=new int[n+1];
                for(int i=1;i<n+1;i++)f[i]=s.nextInt();
                pa=new int[n+1];R=new int[n+1];
                for(int i=1;i<=n;i++)pa[i]=i;
                for(int i=1;i<=n;i++){
                 m(f[i],i);
                }
                HashMap<Integer,Integer> hm=new HashMap<>();
                int cnt=0;int g[]=new int[n+1];
                for(int i=1;i<n+1;i++){
                 if(hm.get(pa[i])==null){hm.put(pa[i],++cnt);}
                 g[i]=hm.get(pa[i]);
                }
                int h[]=new int[cnt+1];boolean r=true;
                for(int i=1;i<=n;i++){
                 if(h[g[i]]!=0&&h[g[i]]!=f[i]){r=false;break;}
                 h[g[i]]=f[i];
                }
                if(r){
                pw.write(cnt+"\n");
                for(int i=1;i<=n;i++)pw.write(g[i]+" ");
                pw.write("\n");
                for(int i=1;i<=cnt;i++)pw.write(h[i]+" ");}else pw.write("-1");
        	pw.flush();pw.close();
	}
}
