During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help.

You are given a sequence a, consisting of n distinct integers, that is used to construct the binary search tree. Below is the formal description of the construction process.

  1. First element a_1 becomes the root of the tree. 
  2. Elements a_2, a_3, …, a_n are added one by one. To add element a_i one needs to traverse the tree starting from the root and using the following rules: 
    1. The pointer to the current node is set to the root. 
    2. If a_i is greater than the value in the current node, then its right child becomes the current node. Otherwise, the left child of the current node becomes the new current node. 
    3. If at some point there is no required child, the new node is created, it is assigned value a_i and becomes the corresponding child of the current node. 

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the length of the sequence a.

The second line contains n distinct integers a_i (1 ≤ a_i ≤ 10^9) — the sequence a itself.

Output

Output n - 1 integers. For all i > 1 print the value written in the node that is the parent of the node with value a_i in it.

Examples

Input

3
1 2 3


Output

1 2


Input

5
4 2 3 1 6


Output

4 2 2 4
//package codeforces353;

import java.io.*;
import java.util.*;


public class q4{
	static InputReader in;
	static int mod=(int)(1e9+7);
	public static void main(String[] args) throws Exception
	{
		in=new InputReader(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=in.nextInt();
		int[] a=readint(n);
		TreeMap<Integer,Integer> hm=new TreeMap<Integer,Integer>();
		hm.put(a[0], 1);
        HashMap<Integer,LongLongPair> hmm=new HashMap<Integer,LongLongPair>();
        hmm.put(a[0], new LongLongPair(0,0));
        for(int i=1;i<n;i++)
        {
            if(hm.floorKey(a[i])!=null)
            {
                int x=hm.floorKey(a[i]);
                LongLongPair q=hmm.get(x);
                long b=q.second;
                if(b==1)
                {
                    int x2=hm.ceilingKey(a[i]);
                    int p=hm.get(x2);
                    long y=((long)(2*(long)p))%mod;
                    int z=(int)y;
                    hm.put(a[i],z);
                    
                    hmm.put(a[i],new LongLongPair(0,0));
                    
                    pw.print(x2+" ");
                }
                else
                {
                int p=hm.get(x);
                long y=((long)(2*(long)p)+(long)1)%mod;
                int z=(int)y;
                hm.put(a[i],z);
                hmm.put(a[i],new LongLongPair(0,0));
                hmm.put(x, new LongLongPair(0,1));
                pw.print(x+" ");
                }
            }
            else
            {
                int x=hm.firstKey();
                int p=hm.get(x);
                long y=(2*(long)p)%mod;
                int z=(int)y;
                hm.put(a[i],z);
                hmm.put(a[i],new LongLongPair(0,0));
                pw.print(x+" ");
            }
            
        }
        
	
		
		
		pw.close();
	}
	public static long[] readlong(int n)
	{
		long[] a=new long[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextLong();
		}
		return a;
	}
	public static int[] readint(int n)
	{
		int[] a=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
		}
		return a;
	}
	
	static  class LongLongPair implements Comparable<LongLongPair> {
	    public final long first;
	    public final long second;

	    public LongLongPair(long first, long second) {
	        this.first = first;
	        this.second = second;
	    }


	    public boolean equals(Object o) {
	        if (this == o) {
	            return true;
	        }
	        if (o == null || getClass() != o.getClass()) {
	            return false;
	        }

	        LongLongPair pair = (LongLongPair) o;

	        return first == pair.first && second == pair.second;
	    }


	    public int hashCode() {
	        int result = Long.hashCode(first);
	        result = 31 * result + Long.hashCode(second);
	        return result;
	    }


	    public String toString() {
	        return "(" + first + "," + second + ")";
	    }

	    @SuppressWarnings({"unchecked"})
	    public int compareTo(LongLongPair o) {
	        int value = Long.compare(first, o.first);
	        if (value != 0) {
	            return value;
	        }
	        return Long.compare(second, o.second);
	    }

	}
	
	
	
	
	
	
	
	
	 static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}
		
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			long res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}
		
		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

}

