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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;


public class CTree {
	static int max = Integer.MAX_VALUE;
	static int min = Integer.MIN_VALUE;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = Integer.parseInt(br.readLine());
		String[] input = br.readLine().split(" ");
		HashMap<Integer, Integer> indices = new HashMap<Integer, Integer>();
		Tree t = new Tree();
		t.insert(Integer.parseInt(input[0]));
		indices.put(Integer.parseInt(input[0]), 1);
		indices.put(Integer.MIN_VALUE, -1);
		indices.put(Integer.MAX_VALUE, -1);
		for(int i = 1; i < n; i++){
			indices.put(Integer.parseInt(input[i]),i+1);
			t.insert(Integer.parseInt(input[i]));
			out.print(input[Math.max(indices.get(min), indices.get(max))-1] + " ");
		}
		out.close();
	}
	
	//AVL tree taken from: https://www.unf.edu/~wkloster/3540/avl.java
	//I slightly modified insert

	// demonstrates AVL tree
	////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////
	public static class Node
	   {
	   public int iData;              // data item (key)
	   public int height;             // height of node
	   public Node left;         // this node's left child
	   public Node right;        // this node's right child

	   public Node(int id) 			// constructor
	      {
	      iData = id;
	      height = 0;
	      left = null;
	      right = null;
	      }

	   }  // end class Node
	public static class Tree
	
	   {
	   private Node root;             // first node of tree

	// -------------------------------------------------------------
	   public Tree()                  // constructor
	      { root = null; }            // no nodes in tree yet
	// -------------------------------------------------------------

	   public Node getRoot()
	      { return root;}

	//--------------------------------------------------------------

	   public Node find(int key, Node foo)  // RECURSIVE find node with given key
	      {

	       if (foo == null)
	           return null;
	       else
	       if (foo.iData == key)
	           return foo;
	       else
	       if (foo.iData < key)
	           return find(key, foo.right);
	       else
	           return find(key, foo.left);


	       }  // end find()

	// -------------------------------------------------------

	   public int height(Node x)  // return height of tree rooted at x
	     {
	      if (x == null) return -1;
	         else return x.height;
	     }

	   public Node rotatewithleft(Node c)
	   {
	     Node p;  // left child of c

	     p = c.left;
	     c.left = p.right;
	     p.right = c;

	     c.height = Math.max(height(c.left), height(c.right)) + 1;
	     p.height = Math.max(height(p.left), height(p.right)) + 1;

	     return p;

	   }

	   public Node rotatewithright(Node c)
	   {

	     Node p;  // right child of c

	     p = c.right;
	     c.right = p.left;
	     p.left = c;

	     c.height = Math.max(height(c.left), height(c.right)) + 1;
	     p.height = Math.max(height(p.left), height(p.right)) + 1;

	     return p;

	   }

	   public Node doublerotatewithleft(Node c)
	   {

	     Node tmp;

	     c.left = rotatewithright(c.left);
	     tmp = rotatewithleft(c);

	     return tmp;

	   }


	   public Node doublerotatewithright(Node c)
	   {

	    Node tmp;

	    c.right = rotatewithleft(c.right);
	    tmp = rotatewithright(c);

	    return tmp;

	   }


	   public Node avlinsert(Node newNode, Node par)
	   {

	   Node newpar = par;  // root of subtree par

	   if (newNode.iData < par.iData)
	   {
		 if(par.iData < max) max = par.iData;

	     if (par.left == null)
	       {

	         par.left = newNode;  //attach new node as leaf

	       }
	     else {

	         par.left = avlinsert(newNode, par.left);   // branch left

	         if ((height(par.left) - height(par.right)) == 2) {

	            if (newNode.iData < par.left.iData) {

	              newpar=rotatewithleft(par);

	            }
	            else {

	              newpar=doublerotatewithleft(par);

	            } //else
	         } //if
	      } // else
	   } // if

	   else if (newNode.iData > par.iData)  // branch right
	   {
		   if(par.iData > min) min = par.iData;
	        if (par.right == null)
	       {

	         par.right = newNode;   // attach new node as leaf

	       }
	     else {

	           par.right = avlinsert(newNode, par.right);  // branch right

	           if ((height(par.right) - height(par.left)) == 2) {

	            if (newNode.iData > par.right.iData) {

	              newpar=rotatewithright(par);


	            } //if
	            else {

	              newpar=doublerotatewithright(par);

	            } //else
	           } //if
	        } //else
	   }  // else if

	   else System.out.println("Duplicate Key");

	 // Update the height, just in case

	   if ((par.left == null) && (par.right != null))
	      par.height = par.right.height + 1;
	   else if ((par.right == null) && (par.left != null))
	      par.height = par.left.height + 1;
	   else
	      par.height = Math.max(height(par.left), height(par.right)) + 1;

	   return newpar; // return new root of this subtree

	 }  // end avlinsert

	// -------------------------------------------------------------
	   public void insert(int id) // Recursive insert
	      {
		   min = Integer.MIN_VALUE;
		   max = Integer.MAX_VALUE;
	      Node newNode = new Node(id);    // make new node

	      if(root==null)
	         root = newNode;
	      else
	         {

	          root=avlinsert(newNode, root);

	          }
	      }  // end insert()

	   }  // end class Tree
}
