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
/*
 * Remember a 6.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience. 
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.text.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=1000000000;//10^9+7
	private static final int N=100000+7; //10^5+7
	private static final double EPS=1e-9;
//	private static final int LIM=26;
//	private static final double PI=3.1415;
//	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static int color[]=new int[N];
//	private static boolean mark[]=new boolean[N];
//	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//	private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x);}}}
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
//	private static <E extends Comparable> E min(E a,E b){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static <E extends Comparable> E min(E a,E b,E c){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static void shuffle(long [] arr) {
//		for (int i = arr.length - 1; i >= 2; i--) {
//			int x = new Random().nextInt(i - 1);
//	        long temp = arr[x];
//	        arr[x] = arr[i];
//	        arr[i] = temp;
//	    }
//	 }
//	private static long gcd(long a, long b){
//		if(b==0)return a;
//		return gcd(b,a%b);
//	}
//	private static boolean check(int x,int y){
//		if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//		return false;
//	}
//	static class Node{
//		int left;
//		int right;
//		Node(){
//			left=0;
//			right=0;
//		}
//	}
	public static void main(String[] args) throws IOException{
		HashMap<Integer,Pair> map=new HashMap();
		int n=in.nextInt();
		TreeSet<Integer> set=new TreeSet();
		int x;
		Integer up,lw;
		for(int i=0;i<n;i++){
			x=in.nextInt();
			if(i!=0){
				up=set.ceiling(x);
				lw=set.floor(x);
//				out.println(i+" "+up+" "+lw);
				if(up!=null&&map.get(up).l==0){
					map.get(up).l=x;
					ans.append(up+" ");
				}
				else{
					map.get(lw).r=x;
					ans.append(lw+" ");
				}
			}
			map.put(x,new Pair());
			set.add(x);
		}
		out.print(ans);
	}
	static class Pair<T> implements Comparable<Pair>{
		long l;
		int r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(long k,int v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o) {
			if(o.l!=l)return (int) (l-o.l);
			else return (int)(r-o.r);
		}
		
	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
     
                	st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}