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
import java.io.*;
import java.math.BigInteger;
import java.util.*;
 
 
public class Main {
	static HashSet<Integer> set;
	static int count=0;
	static int citi=0;
	static ArrayList<Integer> left=new ArrayList<Integer>();
	static ArrayList<Integer> right=new ArrayList<Integer>();
	static ArrayList<Integer> g[];
	
	public static void main(String[] args) throws IOException 
		{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);
//int n=in.nextInt();
		/*
BST b=new BST();
Node root=b.NewNode(1);
root.left=b.NewNode(3);
root.right=b.NewNode(2);
root.left.left=b.NewNode(4);
root.left.right=b.NewNode(5);
root.left.left.left=b.NewNode(6);*/
		TreeSet<Integer> ts = new TreeSet<>();
		HashMap<Integer,Integer> hm = new HashMap<>();
		int n = in.nextInt();
		int arr[] = in.nextIntArray(n);
		for(int i = 0;i<n;i++){
			hm.put(arr[i], i);
		}
		ts.add(arr[0]);
		for(int i =1;i<n;i++){
			Integer x = ts.lower(arr[i]),y = ts.higher(arr[i]);
			if(y==null){
				System.out.print(x+" ");
				ts.add(arr[i]);
				continue;
			}
			else if(x==null){
				System.out.print(y+" ");
				ts.add(arr[i]);
				continue;
			}
			else{
				if(hm.get(x)>hm.get(y))
				System.out.print(x+" ");
			else System.out.print(y+" ");
				
				ts.add(arr[i]);
			}
		}
		}
	public static String reverse(String s)
	{
		StringBuilder sb=new StringBuilder(s);
		return sb.reverse().toString();
	}
	/**    public static void dfs(int curr,int t)
	    {
	    	visited[curr]=true;
	    	//edjes++;
	    	col[curr]=t;
	    	if(t%2==0)
	    		left.add(curr);
	    	else
	    		right.add(curr);
	    	for(int x:g[curr])
	    	{
	    		edjes++;
	    		if(!visited[x])
	    			dfs(x,t+1);
	    		else
	    		{
	    			if(col[curr]%2==col[x]%2)
	    			{
	    				System.out.println(-1);
	    				System.exit(0);
	    			}
	    		}
	    	}
	    }
	
		/*public static boolean dfs(int curr,int prev)
		{
			vis[curr]=true;
		    int trees=0;
		    for(int x:g[curr])
		    {
		    	if(!vis[x])
		    	{
		    		trees++;
		    		Continue[curr]&=dfs(x,curr);
		    	}
		    }
		  System.out.println(curr+" "+prev+" " +Math.abs(curr-prev)+" "+Continue[5]);
		  if(trees==0)
		  {
			  Continue[curr]=true;
			  if(Math.abs(prev-curr)==1)
				  return true;
			  else
				  return false;
		  }
		  else
		  {
			  if(Continue[curr])
			  {
				  if(Math.abs(prev-curr)==1)
					  return true;
				  else
					  return false;
			  }
			  return false;
		  }
		    
		}
	/*	public static void dfs(int curr,int prev)
		{
			for(int x:g[curr])
			{
				if(x!=prev)
				{
		            dfs(x,curr);
		            val[curr]+=val[x];
					
			    }
			}
		}
	/*	public static boolean dfs2(int curr,int prev)
		{
			for(int x:g[curr])
			{
			    if(x!=prev)
			    {
			    	bool[curr]|=dfs2(x,curr);
			    }
			}
			if(bool[curr])
				return true;
			else if(two[curr].contains(prev)&&(!bool[curr]))
			{
			      ans.add(curr);
		        bool[prev]=true;
				bool[curr]=true;
				return true;
			}
			
			return false;
		}
	*/
		public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
				public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}
	static class Pair implements Comparable<Pair>{
		int aud;
		int vid;
		Pair(int mr,int er){
			aud=mr;
			vid=er;
			
		}
		@Override
		public int compareTo(Pair o) {
			return 1;
			}
	}
	public static long gcd(long a, long b) {
		  if (b == 0) return a;
		  return gcd(b, a%b);
		}
	static class InputReader {
 
		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, 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 int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		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);
		}
	}
}