#include<stdio.h>
#include<stdlib.h>

typedef struct __struct_BST{
	int val;  //Values stored in the node.
	int h;  //Height of the node. Starts from 0 for leaf nodes
	int count;  //Count of the number 'val' present in the BST. Set to 0 if deleted
	int w;  //Number of numbers in the sub-tree rooted at this node
	struct __struct_BST *left,*right;  //left and right children
}BST;

void BST_insert(BST **, int);
void BST_update(BST **);
int BST_geth(BST *);
int BST_getw(BST *);
int BST_getc(BST *);
void BST_fixit(BST **);
void BST_rotl(BST **);
void BST_rotr(BST **);
BST * BST_search(BST *, int);
void BST_delete(BST **, int);
int BST_lessthan(BST *, int);
int BST_greaterthan(BST *, int);
BST *BST_previous(BST *, int);
BST *BST_next(BST *, int);

int main(){
	BST *all, *left, *right, *tmp;
	int n,i,j;
	all=left=right=NULL;
	scanf("%d", &n);
	while(n--){
		scanf("%d", &i);
		tmp=BST_previous(all, i);
		if(tmp!=NULL && BST_search(right, tmp->val)==NULL){
			printf("%d ", tmp->val);
			BST_insert(&right, tmp->val);
		}
		else if((tmp=BST_next(all, i))!=NULL && BST_search(left, tmp->val)==NULL){
			printf("%d ", tmp->val);
			BST_insert(&left, tmp->val);
		}
		BST_insert(&all, i);
	}
	printf("\n");
	return 0;
}

void BST_insert(BST **tarp, int val){
	/*
	  Inserts the number 'val' under the BST whose pointer is pointed by tarp
	 */
	BST *target = *tarp;
	if(target == NULL){
		//Make a new leaf node
		target = (BST *)malloc(sizeof(BST));
		target->val = val;
		target->h = 0;
		target->left = NULL;
		target->right = NULL;
		target->count = 1;
		target->w = 1;
		*tarp = target;  //Change the pointer value to the newly allocated node
		return ;
	}
	if(target->val ==val){
		//Number already present in the BST. Only need to increase the count.
		target->count++;
		target->w++;
	}
	else if(target->val > val){
		BST_insert(&(target->left), val);
	}
	else{
		BST_insert(&(target->right), val);
	}
	//Update values like height, weight etc.
	BST_update(tarp);
}

void BST_update(BST **tarp){
	/*
	  Updates 'w' and 'h' of the BST.
	  Make sure the children are updated before calling this for the parent.
	*/
	BST *target = *tarp;
	int lh, rh;
	if(target == NULL){
		return ;
	}
	target->w = BST_getw(target->left) + BST_getw(target->right) + target->count;
	lh = BST_geth(target->left);
	rh = BST_geth(target->right);
	if(lh > rh)
		target->h = lh+1;
	else
		target->h = rh+1;
	//Make sure the BST is balanced
	if(lh > rh+1 || rh > lh+1)
		BST_fixit(tarp);
}

int BST_getw(BST *target){
	if(target == NULL)
		return 0;
	return target->w;
}

int BST_geth(BST *target){
	//Set height of NULL to -1 to make height of leaf nodes as 0
	if(target == NULL)
		return -1;
	return target->h;
}

int BST_getc(BST *target){
	if(target == NULL)
		return 0;
	return target->count;
}

void BST_fixit(BST **tarp){
	/*
	  Fixes imbalanced BST
	 */
	BST *target = *tarp;
	if(BST_geth(target->left) > BST_geth(target->right)){
		if(BST_geth(target->left->left) > BST_geth(target->left->right)){
			BST_rotr(tarp);
			BST_update(&((*tarp)->right));
			BST_update(tarp);
		}
		else{
			BST_rotl(&(target->left));
			BST_rotr(tarp);
			target = *tarp;
			BST_update(&(target->left));
			BST_update(&(target->right));
			BST_update(tarp);
		}
	}
	else{
		if(BST_geth(target->right->right) > BST_geth(target->right->left)){
			BST_rotl(tarp);
			BST_update(&((*tarp)->left));
			BST_update(tarp);
		}
		else{
			BST_rotr(&(target->right));
			BST_rotl(tarp);
			target = *tarp;
			BST_update(&(target->right));
			BST_update(&(target->left));
			BST_update(tarp);
		}
	}
}

void BST_rotl(BST **tarp){
	/*
	  Rotates the node towards left ie. CCW
	 */
	BST *r, *target;
	target = *tarp;
	r = target->right;
	*tarp = r;
	target->right = r->left;
	r->left = target;
}

void BST_rotr(BST **tarp){
	/*
	  Rotates the node towards left ie. CCW
	 */
	BST *l, *target;
	target = *tarp;
	l = target->left;
	*tarp = l;
	target->left = l->right;
	l->right = target;
}

BST *BST_search(BST *target, int val){
	/*
	  Search for the node containing the number 'val'
	 */
	if(target == NULL)
		return NULL;
	if(target->val == val)
		return target;
	else if(target->val > val){
		return BST_search(target->left, val);
	}
	else{
		return BST_search(target->right, val);
	}
}

void BST_delete(BST **tarp, int val){
	/*
	  Delete the number 'val' from the BST
	 */
	BST *target;
	if(tarp == NULL)
		return ;
	target = *tarp;
	if(target->val == val){
		if(target->count > 0){
			target->count--;
			target->w--;
		}
	}
	else if(target->val > val){
		BST_insert(&(target->left), val);
	}
	else{
		BST_insert(&(target->right), val);
	}
	BST_update(tarp);
}

int BST_lessthan(BST *target, int val){
	/*
	  Return the number of elements in the BST lesser than 'val'
	 */
	if(target == NULL)
		return 0;
	if(target->val >= val){
		return BST_lessthan(target->left, val);
	}
	else{
		return BST_lessthan(target->right, val) + BST_getc(target) + BST_getw(target->left);
	}
}

int BST_greaterthan(BST *target, int val){
	/*
	  Return the number of elements in the BST greater than 'val'
	 */
	if(target == NULL)
		return 0;
	if(target->val <= val){
		return BST_greaterthan(target->right, val);
	}
	else{
		return BST_greaterthan(target->left, val) + BST_getc(target) + BST_getw(target->right);
	}
}

BST *BST_previous(BST *node, int val){
	if(node == NULL)
		return NULL;
	if(node->val < val){
		BST *tmp = BST_previous(node->right, val);
		if(tmp)
			return tmp;
		if(BST_getc(node)){
			return node;
		}
	}
	return BST_previous(node->left, val);
}

BST *BST_next(BST *node, int val){
	if(node == NULL)
		return NULL;
	if(node->val > val){
		BST *tmp = BST_next(node->left, val);
		if(tmp)
			return tmp;
		if(BST_getc(node)){
			return node;
		}
	}
	return BST_next(node->right, val);
}


//requires stdlib.h
#include<stdio.h>
#include<stdlib.h>

typedef struct __struct_BSTV{
    int val;
}BSTV;

typedef struct __struct_BST{
    BSTV val;  //Values stored in the node.
    int h;  //Height of the node. Starts from 0 for leaf nodes
    int count;  //Count of the number 'val' present in the BST. Set to 0 if deleted
    int w;  //Number of numbers in the sub-tree rooted at this node
    struct __struct_BST *left,*right;  //left and right children
}BST;

BSTV BST_makeV(int);
int BST_cmp(BSTV, BSTV);
void BST_insert(BST **, BSTV);
void BST_update(BST **);
int BST_geth(BST *);
int BST_getw(BST *);
int BST_getc(BST *);
void BST_fixit(BST **);
void BST_rotl(BST **);
void BST_rotr(BST **);
BST * BST_search(BST *, BSTV);
void BST_delete(BST **, BSTV);
int BST_lessthan(BST *, BSTV);
int BST_greaterthan(BST *, BSTV);
BST *BST_previous(BST *, BSTV);
BST *BST_next(BST *, BSTV);

int main(){
	BST *all, *left, *right, *tmp;
	int n,i,j;
	all=left=right=NULL;
	scanf("%d", &n);
	while(n--){
		scanf("%d", &i);
		tmp=BST_previous(all, BST_makeV(i));
		BST_insert(&all, BST_makeV(i));
		if(tmp!=NULL && BST_search(right, tmp->val)==NULL){
			printf("%d ", tmp->val.val);
			BST_insert(&right, tmp->val);
		}
		else if((tmp=BST_next(all, BST_makeV(i)))!=NULL && BST_search(left, tmp->val)==NULL){
			printf("%d ", tmp->val.val);
			BST_insert(&left, tmp->val);
		}
	}
	printf("\n");
	return 0;
}

BSTV BST_makeV(int val){
    /*
      returns the struct which is used by the bst
    */
    BSTV retval;
    retval.val = val;
}

int BST_cmp(BSTV a, BSTV b){
    /*
      Compares the values of a and b
      -1(less than zero) if a < b
      0 if a == b
      1(greater than zero) if a > b
    */
    return a.val - b.val;
}

void BST_insert(BST **tarp, BSTV val){
    /*
      Inserts the number 'val' under the BST whose pointer is pointed by tarp
    */
    BST *target = *tarp;
    if(target == NULL){
	//Make a new leaf node
	target = (BST *)malloc(sizeof(BST));
	target->val = val;
	target->h = 0;
	target->left = NULL;
	target->right = NULL;
	target->count = 1;
	target->w = 1;
	*tarp = target;  //Change the pointer value to the newly allocated node
	return ;
    }
    if(BST_cmp(target->val, val) == 0){
	//Number already present in the BST. Only need to increase the count.
	target->count++;
	target->w++;
    }
    else if(BST_cmp(target->val, val) > 0){
	BST_insert(&(target->left), val);
    }
    else{
	BST_insert(&(target->right), val);
    }
    //Update values like height, weight etc.
    BST_update(tarp);
}

void BST_update(BST **tarp){
    /*
      Updates 'w' and 'h' of the BST.
      Make sure the children are updated before calling this for the parent.
    */
    BST *target = *tarp;
    int lh, rh;
    if(target == NULL){
	return ;
    }
    target->w = BST_getw(target->left) + BST_getw(target->right) + target->count;
    lh = BST_geth(target->left);
    rh = BST_geth(target->right);
    if(lh > rh)
	target->h = lh+1;
    else
	target->h = rh+1;
    //Make sure the BST is balanced
    if(lh > rh+1 || rh > lh+1)
	BST_fixit(tarp);
}

int BST_getw(BST *target){
    if(target == NULL)
	return 0;
    return target->w;
}

int BST_geth(BST *target){
    //Set height of NULL to -1 to make height of leaf nodes as 0
    if(target == NULL)
	return -1;
    return target->h;
}

int BST_getc(BST *target){
    if(target == NULL)
	return 0;
    return target->count;
}

void BST_fixit(BST **tarp){
    /*
      Fixes imbalanced BST
    */
    BST *target = *tarp;
    if(BST_geth(target->left) > BST_geth(target->right)){
	if(BST_geth(target->left->left) > BST_geth(target->left->right)){
	    BST_rotr(tarp);
	    BST_update(&((*tarp)->right));
	    BST_update(tarp);
	}
	else{
	    BST_rotl(&(target->left));
	    BST_rotr(tarp);
	    target = *tarp;
	    BST_update(&(target->left));
	    BST_update(&(target->right));
	    BST_update(tarp);
	}
    }
    else{
	if(BST_geth(target->right->right) > BST_geth(target->right->left)){
	    BST_rotl(tarp);
	    BST_update(&((*tarp)->left));
	    BST_update(tarp);
	}
	else{
	    BST_rotr(&(target->right));
	    BST_rotl(tarp);
	    target = *tarp;
	    BST_update(&(target->right));
	    BST_update(&(target->left));
	    BST_update(tarp);
	}
    }
}

void BST_rotl(BST **tarp){
    /*
      Rotates the node towards left ie. CCW
    */
    BST *r, *target;
    target = *tarp;
    r = target->right;
    *tarp = r;
    target->right = r->left;
    r->left = target;
}

void BST_rotr(BST **tarp){
    /*
      Rotates the node towards left ie. CCW
    */
    BST *l, *target;
    target = *tarp;
    l = target->left;
    *tarp = l;
    target->left = l->right;
    l->right = target;
}

BST *BST_search(BST *target, BSTV val){
    /*
      Search for the node containing the number 'val'
    */
    if(target == NULL)
	return NULL;
    if(BST_cmp(target->val, val) == 0)
	return target;
    else if(BST_cmp(target->val, val) > 0){
	return BST_search(target->left, val);
    }
    else{
	return BST_search(target->right, val);
    }
}

void BST_delete(BST **tarp, BSTV val){
    /*
      Delete the number 'val' from the BST
    */
    BST *target;
    if(tarp == NULL)
	return ;
    target = *tarp;
    if(BST_cmp(target->val, val) == 0){
	if(target->count > 0){
	    target->count--;
	    target->w--;
	}
    }
    else if(BST_cmp(target->val, val) > 0){
	BST_insert(&(target->left), val);
    }
    else{
	BST_insert(&(target->right), val);
    }
    BST_update(tarp);
}

int BST_lessthan(BST *target, BSTV val){
    /*
      Return the number of elements in the BST lesser than 'val'
    */
    if(target == NULL)
	return 0;
    if(BST_cmp(target->val, val) >= 0){
	return BST_lessthan(target->left, val);
    }
    else{
	return BST_lessthan(target->right, val) + BST_getc(target) + BST_getw(target->left);
    }
}

int BST_greaterthan(BST *target, BSTV val){
    /*
      Return the number of elements in the BST greater than 'val'
    */
    if(target == NULL)
	return 0;
    if(BST_cmp(target->val, val) <= 0){
	return BST_greaterthan(target->right, val);
    }
    else{
	return BST_greaterthan(target->left, val) + BST_getc(target) + BST_getw(target->right);
    }
}

BST *BST_previous(BST *node, BSTV val){
    /*
      Return the node which comes before 'val' in-order.
      Returns NULL if no node is found.
    */
    if(node == NULL)
	return NULL;
    if(BST_cmp(node->val, val) < 0){
	BST *tmp = BST_previous(node->right, val);
	if(tmp)
	    return tmp;
	if(BST_getc(node)){
	    return node;
	}
    }
    return BST_previous(node->left, val);
}

BST *BST_next(BST *node, BSTV val){
    /*
      Return the node which comes after 'val' in-order.
      Returns NULL if no node is found.
    */
    if(node == NULL)
	return NULL;
    if(BST_cmp(node->val, val) > 0){
	BST *tmp = BST_next(node->left, val);
	if(tmp)
	    return tmp;
	if(BST_getc(node)){
	    return node;
	}
    }
    return BST_next(node->right, val);
}


import java.io.*;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class TreeConstruction {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
		StringTokenizer st = new StringTokenizer(br.readLine());
		tm.put(Integer.parseInt(st.nextToken()), 0);
		for (int i = 1; i < n; i++) {
			int input = Integer.parseInt(st.nextToken()), ans = 0;
			tm.put(input, i);
			if (tm.higherKey(input) == null || tm.lowerKey(input) == null){
				if (tm.higherKey(input) == null) ans = tm.lowerKey(input);
				else ans = tm.higherKey(input);

			} else {
				int high = tm.higherKey(input), low = tm.lowerKey(input);
				ans = (tm.get(high) > tm.get(low)) ? high : low;
			}
			System.out.print(ans + " ");

		}

	}

}


import java.util.*;
public class TreeConstruction {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        HashMap<Long, Long> tree = new HashMap<Long, Long>();
        for (int i = 0; i < n; i++){
            long input = in.nextLong(), cur = 0, prev = 0;
            if (i == 0) tree.put((long)0, input);
            else {
                while (tree.get(cur) != null){
                    prev = cur;
                    cur = cur * 2 + ((tree.get(cur) > input) ? 1 : 2);
                }
                tree.put(cur, input);
                System.out.print(tree.get(prev) + " ");
            }
        }

    }
}


import java.util.*;
public class TreeConstruction {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        HashMap<Integer, Integer> tree = new HashMap<>();
        for (int i = 0; i < n; i++){
            int input = in.nextInt(), cur = 0, prev = 0;
            if (i == 0) tree.put(0, input);
            else {
                while (tree.get(cur) != null){
                    prev = cur;
                    cur = cur * 2 + ((tree.get(cur) > input) ? 1 : 2);
                }
                tree.put(cur, input);
                System.out.print(tree.get(prev) + " ");
            }
        }

    }
}


import java.util.*;
public class D {
	public static void main(String[] args)
	{
		Scanner cin=new Scanner(System.in);
		int n=cin.nextInt();

		int[] V = new int[100005];
		int[] L = new int[100005];
		int[] R = new int[100005];
		V[1] = cin.nextInt();
		R[1] = 0; L[1] = 0;

		for (int i = 2; i <= n; i ++)
		{
			V[i]=cin.nextInt();
			int cur = 1, ans;
			for (;;)
			{
				if (V[i] > V[cur])
				{
					if (R[cur] == 0)
					{
						ans = cur;
						R[cur] = i; R[i] = L[i] = 0;
						break;
					}
					else cur = R[cur];
				}
				else
				{
					if (L[cur] == 0)
					{
						ans = cur;
						L[cur] = i; R[i] = L[i] = 0;
						break;
					}
					else cur = L[cur];
				}
			}
			System.out.println(V[ans]);
		}
	}
}


import java.util.*;

import javax.print.attribute.HashAttributeSet;
public class D {
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int a[] = new int[100005];
		for (int i = 1; i <= n; i ++)
			a[i] = cin.nextInt();

		HashMap<Integer, Integer> mp = new HashMap<Integer, Integer>();
		TreeSet<Integer> st = new TreeSet<Integer>();

		for (int i = 1; i <= n; i++)
			mp.put(a[i], i);
		st.add(a[1]);

		for (int i = 2; i <= n; i++)
		{
			Integer R = st.higher(a[i]);
			Integer L = st.lower(a[i]);
			Integer ans;
			if (R == null) ans = L;
			else if (L == null) ans = R;
			else if (mp.get(R) > mp.get(L)) ans = R;
			else  ans = L;
			st.add(a[i]);
			System.out.println(ans);
		}
	}
}


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

public class CF_675_D_TREE_CONSTRUCTION {

	static HashMap<Integer, Integer> p ;

	static Node dfs(Node n , int par , int newVal)
	{
		if(n == null)
		{
			p.put(newVal, par);

			n = new Node(newVal);
			return n;
		}
		Node root = new Node(n.val);
		root.l = n.l;
		root.r = n.l;

		Node nxt =  (n.val <= newVal )? (root.l = dfs(n.l, n.val, newVal)) : (root.r = dfs(n.r, n.val, newVal));

		return root;

	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		p = new HashMap<>();

		Node head = new Node(a[1]);

		for(int i = 2 ; i<= n ; i++)
			head = dfs(head, -1, a[i]);

		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ;i++)
			st.append(p.get(a[i])).append(" ");

		System.out.println(st);

	}

	static class Node {
		int val ;
		Node l , r ;

		Node(int x)
		{
			val = x ;
		}

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	static HashMap<Integer, Integer> p ;

	static Node dfs(Node n , int par , int newVal)
	{
		if(n == null)
		{
			p.put(newVal, par);

			n = new Node(newVal);
			return n;
		}
		Node root = new Node(n.val);
		root.l = n.l;
		root.r = n.l;

		Node nxt =  (n.val < newVal )? (root.l = dfs(n.l, n.val, newVal)) : (root.r = dfs(n.r, n.val, newVal));

		return root;

	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		p = new HashMap<>();

		Node head = new Node(a[1]);

		for(int i = 2 ; i<= n ; i++)
			head = dfs(head, -1, a[i]);

		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ;i++)
			st.append(p.get(a[i])).append(" ");

		System.out.println(st);

	}

	static class Node {
		int val ;
		Node l , r ;

		Node(int x)
		{
			val = x ;
		}

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner();

		int n = sc.nextInt() - 1;

		TreeSet<Integer> tree = new TreeSet<>();
		TreeSet<Integer> lower = new TreeSet<>();

		tree.add(sc.nextInt());

		StringBuilder st = new StringBuilder();

		while (n-- > 0) {
			int a = sc.nextInt();
			Integer x = tree.lower(a);

			if (x == null || lower.contains(x))
				x = tree.higher(a);
			else
				lower.add(x);

			tree.add(a);
			st.append(x).append(" ");

		}

		System.out.println(st);

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	static int ans ;
	static Node dfs(Node n , int par , int newVal)
	{
		if(n == null)
		{
			ans = par ;
			n = new Node(newVal);
			return n;
		}

		Node root = new Node(n.val);
		root.l = n.l;
		root.r = n.r;

		if(n.val < newVal)
			root.r = dfs(n.r, n.val, newVal);
		else
			root.l = dfs(n.l, n.val, newVal);

		return root;

	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		Node head = new Node(a[1]);
		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ; i++) {
			head = dfs(head, -1, a[i]);
			st.append(ans).append(" ");
		}

		System.out.println(st);

	}

	static class Node {
		int val ;
		Node l , r ;

		Node(int x)
		{
			val = x ;
		}

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];
		TreeSet<Integer> tree = new TreeSet<>();

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		tree.add(a[1]);

		TreeSet<Integer> lower = new TreeSet<>();
		TreeSet<Integer> upper = new TreeSet<>();

		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ;i++)
		{
			Integer x = tree.lower(a[i]);

			if(x == null || lower.contains(a[i]))
			{
				x = tree.higher(a[i]);
				upper.add(x);
			}
			else
				lower.add(x);

			st.append(x).append(" ");
			tree.add(a[i]);

		}

		System.out.println(st);

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];
		TreeSet<Integer> tree = new TreeSet<>();

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		tree.add(a[1]);

		TreeSet<Integer> lower = new TreeSet<>();

		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ;i++)
		{

			Integer x = tree.lower(a[i]);

			if(x == null || lower.contains(x))
				x = tree.higher(a[i]);
			else
				lower.add(x);

			tree.add(a[i]);
			st.append(x).append(" ");

		}

		System.out.println(st);

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

public class CF_675_D_TREE_CONSTRUCTION {

	static HashMap<Integer, Integer> p ;

	static Node dfs(Node n , int par , int newVal)
	{
		if(n == null)
		{
			p.put(newVal, par);

			n = new Node(newVal);
			return n;
		}
		Node root = new Node(n.val);
		root.l = n.l;
		root.r = n.r;

		Node nxt =  (n.val < newVal )?  (root.r = dfs(n.r, n.val, newVal)) : (root.l = dfs(n.l, n.val, newVal)) ;

		return root;

	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner();

		int n = sc.nextInt();

		int [] a = new int [n+1];

		for(int i = 1 ; i <= n ;i++)
			a[i] = sc.nextInt();

		p = new HashMap<>();

		Node head = new Node(a[1]);

		for(int i = 2 ; i<= n ; i++)
			head = dfs(head, -1, a[i]);

		StringBuilder st = new StringBuilder();

		for(int i = 2 ; i<= n ;i++)
			st.append(p.get(a[i])).append(" ");

		System.out.println(st);

	}

	static class Node {
		int val ;
		Node l , r ;

		Node(int x)
		{
			val = x ;
		}

	}

	static class Scanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}
	}

}


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

/**
  * @author Mighty Cohadar
  */
public class Delta {

	final int nn;
	final int[] A;
	final int[] R;

	public Delta(int nn, int[] A) {
		this.nn = nn;
		this.A = A;
		this.R = new int[nn - 1];
	}

	public void insert(Node p, int index, int value) {
		Node c = p;
		while (true) {
			if (c == null) {
				c = new Node(value);
				R[index-1] = p.val;
				if (value > p.val) {
					p.r = c;
				} else {
					p.l = c;
				}
				return;
			}
			p = c;
			c = (value > c.val) ? c.r : c.l;
		}
	}

	public int[] solve() {
		Node root = new Node(A[0]);
		for (int i = 1; i < A.length; i++) {
			insert(root, i, A[i]);
		}
		return R;
	}

	public static Delta load(FastScanner scanner) {
		int nn = scanner.nextInt();
		assert 2 <= nn && nn <= 1e5 : "out of range, nn: " + nn;
		int[] A = new int[nn];
		for (int i = 0; i < nn; i++) {
			A[i] = scanner.nextInt();
		}
		return new Delta(nn, A);
	}

	public static void main(String[] args) {
		FastScanner scanner = new FastScanner(System.in);
		Delta o = Delta.load(scanner);
		System.out.println(join(" ", o.solve()));
	}

	static String join(String delimiter, int[] A) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < A.length; i++) {
			sb.append(A[i]);
			sb.append(' ');
		}
		return sb.toString();
	}
}

class FastScanner {
	private final BufferedReader in;
	private final StringBuilder sb;
	private StringTokenizer strtok;
	public FastScanner(InputStream is) {
		this.in = new BufferedReader(new InputStreamReader(is));
		this.sb = new StringBuilder();
		this.strtok = null;
	}
	public String next() {
		try {
			if (strtok == null || strtok.hasMoreTokens() == false) {
				strtok = new StringTokenizer(in.readLine());
			}
			return strtok.nextToken();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String nextLine() {
		try {
			if (strtok == null) {
				return in.readLine();
			} else {
				String ret = (strtok.hasMoreTokens()) ? strtok.nextToken("\n") : "";
				strtok = null;
				return ret;
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}

class Node {
	Node l;
	Node r;
	final int val;
	Node(int val) {
		this.val = val;
	}
	public String toString() {
		return String.format("(l=%d, r=%d, val=%d)", l, r, val);
	}
}


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

/**
  * @author Mighty Cohadar
  */
public class Delta {

	final int nn;
	final int[] A;
	final int[] R;
	final Map<Integer, Integer> M = new HashMap<>();

	public Delta(int nn, int[] A) {
		this.nn = nn;
		this.A = A;
		for (int i = 0; i < A.length; i++) {
			M.put(A[i], i);
		}
		this.R = new int[nn - 1];
	}

	public int[] solve() {
		TreeSet<Integer> T = new TreeSet<>();
		T.add(A[0]);
		for (int i = 1; i < A.length; i++) {
			Integer h = T.higher(A[i]);
			Integer l = T.lower(A[i]);
			if (h == null) {
				R[i-1] = l;
			} else if (l == null) {
				R[i-1] = h;
			} else {
				R[i-1] = (M.get(l) > M.get(h)) ? l : h;
			}
			T.add(A[i]);
		}
		return R;
	}

	public static Delta load(FastScanner scanner) {
		int nn = scanner.nextInt();
		assert 2 <= nn && nn <= 1e5 : "out of range, nn: " + nn;
		int[] A = new int[nn];
		for (int i = 0; i < nn; i++) {
			A[i] = scanner.nextInt();
		}
		return new Delta(nn, A);
	}

	public static void main(String[] args) {
		FastScanner scanner = new FastScanner(System.in);
		Delta o = Delta.load(scanner);
		System.out.println(join(" ", o.solve()));
	}

	static String join(String delimiter, int[] A) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < A.length; i++) {
			sb.append(A[i]);
			sb.append(' ');
		}
		return sb.toString();
	}
}

class FastScanner {
	private final BufferedReader in;
	private final StringBuilder sb;
	private StringTokenizer strtok;
	public FastScanner(InputStream is) {
		this.in = new BufferedReader(new InputStreamReader(is));
		this.sb = new StringBuilder();
		this.strtok = null;
	}
	public String next() {
		try {
			if (strtok == null || strtok.hasMoreTokens() == false) {
				strtok = new StringTokenizer(in.readLine());
			}
			return strtok.nextToken();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String nextLine() {
		try {
			if (strtok == null) {
				return in.readLine();
			} else {
				String ret = (strtok.hasMoreTokens()) ? strtok.nextToken("\n") : "";
				strtok = null;
				return ret;
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D {

	static int[] left, right;
	static int[] unmap;
	static TreeMap<Integer, Integer> map;

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();

		unmap = new int[n + 1];
		map  = new TreeMap<Integer, Integer>();
		int[] a = new int[n + 1];
		Integer[] b = new Integer[n];
		for(int i = 1; i <= n; ++i)
			a[i] = b[i-1] = sc.nextInt();
		Arrays.sort(b);
		for(int i = 0; i < n; ++i)
		{
			map.put(b[i], i+1);
			unmap[i+1] = b[i];
		}
		left = new int[n+1];
		right = new int[n+1];
		int root = map.get(a[1]);
		int N = (int) Math.pow(2, Math.ceil(Math.log(n)/Math.log(2)));	//padding
		int[] in = new int[N+1];
		for(int i = 1; i <= n; i++)
			in[i] = root;
		left[root] = 1;
		right[root] = n;
		SegmentTree st = new SegmentTree(in);

		for(int i = 2; i <= n; ++i)
		{
			int x = map.get(a[i]), q = st.query(x, x);

			out.print(unmap[q] +  " ");
			if(x > q)
			{
				right[x] = right[q];
				left[x] = q;
			}
			else
			{
				left[x] = left[q];
				right[x] = q;
			}

			st.update_range(left[x], right[x], x);
		}
		out.flush();
		out.close();

	}

static class SegmentTree {		// 1-based DS, OOP

	int N; 			//the number of elements in the array as a power of 2 (i.e. after padding)
	int[] array, sTree, lazy;
	boolean[] leaf;
	SegmentTree(int[] in)
	{
		array = in; N = in.length - 1;
		sTree = new int[N<<1];		//no. of nodes = 2*N - 1, we add one to cross out index zero
		lazy = new int[N<<1];
		leaf = new boolean[N<<1];
		build(1,1,N);
	}

	void build(int node, int b, int e)	// O(n)
	{
		if(b == e)
		{
			sTree[node] = array[b];
			leaf[node] = true;
		}
		else
		{
			build(node<<1,b,(b+e)/2);
			build((node<<1)+1,(b+e)/2+1,e);
		}
	}

	void update_range(int i, int j, int val)		// O(log n)
	{
		update_range(1,1,N,i,j,val);
	}

	void update_range(int node, int b, int e, int i, int j, int val)
	{
		if(i > e || j < b)
			return;
		if(b >= i && e <= j)
		{
			if(leaf[node])
				sTree[node] = val;
			else
				lazy[node] = val;
		}
		else
		{
			propagate(node, b, e);
			update_range(node<<1,b,(b+e)/2,i,j,val);
			update_range((node<<1)+1,(b+e)/2+1,e,i,j,val);
		}

	}
	void propagate(int node, int b, int e)
	{
		if(lazy[node] == 0)
			return;
		update_range(node<<1,b,(b+e)/2,b,(b+e)/2,lazy[node]);
		update_range((node<<1)+1,(b+e)/2+1,e,(b+e)/2+1,e, lazy[node]);
		lazy[node] = 0;
	}

	int query(int i, int j)
	{
		return query(1,1,N,i,j);
	}

	int query(int node, int b, int e, int i, int j)	// O(log n)
	{
		if(i>e || j <b)
			return 0;
		if(b>= i && e <= j)
			return sTree[node];
		propagate(node, b, e);
		return query(node<<1,b,(b+e)/2,i,j) + query((node<<1)+1,(b+e)/2+1,e,i,j);

	}

}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D {

	static int[] left, right;
	static int[] unmap;
	static TreeMap<Integer, Integer> map;

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();

		unmap = new int[n + 1];
		map  = new TreeMap<Integer, Integer>();
		int[] a = new int[n + 1];
		Integer[] b = new Integer[n];
		for(int i = 1; i <= n; ++i)
			a[i] = b[i-1] = sc.nextInt();
		Arrays.sort(b);
		for(int i = 0; i < n; ++i)
		{
			map.put(b[i], i+1);
			unmap[i+1] = b[i];
		}
		left = new int[n+1];
		right = new int[n+1];
		int root = map.get(a[1]);
		int N = (int) Math.pow(2, Math.ceil(Math.log(n)/Math.log(2)));	//padding
		int[] in = new int[N+1];
		for(int i = 1; i <= n; i++)
			in[i] = root;
		left[1] = 1;
		right[1] = n;
		SegmentTree st = new SegmentTree(in);

		for(int i = 2; i <= n; ++i)
		{
			int x = map.get(a[i]), q = st.query(x, x);

			out.println(unmap[q] +  " ");
			if(x > q)
			{
				right[x] = right[q];
				left[x] = q;
			}
			else
			{
				left[x] = left[q];
				right[x] = q;
			}

			st.update_range(left[x], right[x], x);
		}
		out.flush();
		out.close();

	}

static class SegmentTree {		// 1-based DS, OOP

	int N; 			//the number of elements in the array as a power of 2 (i.e. after padding)
	int[] array, sTree, lazy;

	SegmentTree(int[] in)
	{
		array = in; N = in.length - 1;
		sTree = new int[N<<1];		//no. of nodes = 2*N - 1, we add one to cross out index zero
		lazy = new int[N<<1];
		build(1,1,N);
	}

	void build(int node, int b, int e)	// O(n)
	{
		if(b == e)
			sTree[node] = array[b];
		else
		{
			build(node<<1,b,(b+e)/2);
			build((node<<1)+1,(b+e)/2+1,e);
		}
	}

	void update_range(int i, int j, int val)		// O(log n)
	{
		update_range(1,1,N,i,j,val);
	}

	void update_range(int node, int b, int e, int i, int j, int val)
	{
		if(i > e || j < b)
			return;
		if(b >= i && e <= j)
		{
			sTree[node] = val;
			lazy[node] = val;
		}
		else
		{
			propagate(node, b, e);
			update_range(node<<1,b,(b+e)/2,i,j,val);
			update_range((node<<1)+1,(b+e)/2+1,e,i,j,val);
		}

	}
	void propagate(int node, int b, int e)
	{
		if(lazy[node] == 0)
			return;
		lazy[node<<1] = lazy[node];
		lazy[(node<<1)+1] = lazy[node];
		sTree[node<<1] = lazy[node];
		sTree[(node<<1)+1] = lazy[node];
		lazy[node] = 0;
	}

	int query(int i, int j)
	{
		return query(1,1,N,i,j);
	}

	int query(int node, int b, int e, int i, int j)	// O(log n)
	{
		if(i>e || j <b)
			return 0;
		if(b>= i && e <= j)
			return sTree[node];
		propagate(node, b, e);
		return query(node<<1,b,(b+e)/2,i,j) + query((node<<1)+1,(b+e)/2+1,e,i,j);

	}

}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P675D {

  class Node implements Comparable<Node> {
    int value;
    boolean usedAsLess;

    public Node(int value) {
      this.value = value;
    }

    @Override
    public int compareTo(Node node) {
      return (this.value - node.value);
    }
  }

  public void run() throws Exception {
    TreeSet<Node> nodes = new TreeSet();

    int n = nextInt();
    nodes.add(new Node(nextInt()));
    while ((n--) > 1) {
      Node node = new Node(nextInt());
      Node less = nodes.floor(node);

      if ((less != null) && (!less.usedAsLess)) {
        print(less.value + " ");
        less.usedAsLess = true;
      } else {
        print(nodes.ceiling(node).value + " ");
      }

      nodes.add(node);
    }
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P675D().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P675D {

  class Node {
    int val;
    Node less, more, parent;

    public Node(int val) {
      this.val = val;
    }

    public void add(Node node) {
      if (node.val < val) {
        if (less != null) {
          less.add(node);
        } else {
          less = node;
          node.parent = this;
        }
      } else {
        if (more != null) {
          more.add(node);
        } else {
          more = node;
          node.parent = this;
        }
      }
    }
  }

  public void run() throws Exception {
    int n = nextInt();

    List<Node> nodes = new ArrayList();
    Node root = new Node(nextInt());
    while ((n--) > 1) {
      Node node = new Node(nextInt());
      root.add(node);
      nodes.add(node);
    }

    for (Node node : nodes) {
      print(node.parent.val + " ");
    }
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P675D().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}


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

public class Main{
	class Node{
		int value;
		int index;
		Node parent;
		Node left;
		Node right;
		public Node(int index, int value){
			this.index = index;
			this.value = value;
		}
	}
	/*
	public void solve(){
		int N = nextInt();
		Node[] nodes = new Node[N];
		nodes[0] = new Node(0, nextInt());
		for(int i = 1; i < N; i++){
			nodes[i] = new Node(i, nextInt());
			add(nodes[0], nodes[i]);
			if(i != 1) out.print(" ");
			out.print(nodes[i].parent.value);
		}
	}
	public void add(Node current, Node node){
		if(current.value < node.value){
			if(current.right != null){
				add(current.right, node);
			}else{
				current.right = node;
				node.parent = current;
			}

		}else{
			if(current.left != null){
				add(current.left, node);
			}else{
				current.left = node;
				node.parent = current;
			}

		}
	}
*/
	public void solve(){
		int N = nextInt();
		Node[] nodes = new Node[N];
		nodes[0] = new Node(0, nextInt());
		TreeMap<Integer, Node> tree = new TreeMap<>();
		tree.put(0, nodes[0]);
		tree.put(nodes[0].value, nodes[0]);

		for(int i = 1; i < N; i++){
			nodes[i] = new Node(i, nextInt());
			Map.Entry<Integer, Node> entry = tree.floorEntry(nodes[i].value);
			if(i != 1) out.print(" ");
			out.print(entry.getValue().value);
			tree.put(entry.getKey(), nodes[i]);
			tree.put(nodes[i].value, nodes[i]);
		}
	}

	/*
	 x a y
	 b z c
	 v d w

	 */

	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}

	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}


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

public class Main{
	class Node{
		int value;
		int index;
		Node parent;
		Node left;
		Node right;
		public Node(int index, int value){
			this.index = index;
			this.value = value;
		}
	}
	public void solve(){
		int N = nextInt();
		Node[] nodes = new Node[N];
		nodes[0] = new Node(0, nextInt());
		for(int i = 1; i < N; i++){
			nodes[i] = new Node(i, nextInt());
			add(nodes[0], nodes[i]);
			if(i != 1) out.print(" ");
			out.print(nodes[i].parent.value);
		}
	}
	public void add(Node current, Node node){
		if(current.value < node.value){
			if(current.right != null){
				add(current.right, node);
			}else{
				current.right = node;
				node.parent = current;
			}

		}else{
			if(current.left != null){
				add(current.left, node);
			}else{
				current.left = node;
				node.parent = current;
			}

		}
	}

	/*
	 x a y
	 b z c
	 v d w

	 */

	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}

	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MottoX
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            TreeSet<Integer> set = new TreeSet<Integer>();
            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            map.put(0, -1);
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                if (i > 0) {
                    int d = (set.lower(a) == null ? 0 : set.lower(a));
                    int u = (set.higher(a) == null ? 0 : set.higher(a));
                    out.println((map.get(d) > map.get(u) ? d : u) + " ");
                }
                map.put(a, i);
                set.add(a);
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MottoX
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            TreeSet<Integer> set = new TreeSet<>();
            Map<Integer, Integer> map = new HashMap<>();
            map.put(0, -1);
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                if (i > 0) {
                    int d = (set.lower(a) == null ? 0 : set.lower(a));
                    int u = (set.higher(a) == null ? 0 : set.higher(a));
                    out.println((map.get(d) > map.get(u) ? d : u) + " ");
                }
                map.put(a, i);
                set.add(a);
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		Node q = s.l;
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();
	public static void main(String[] args) {
		//mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		Splay mySplay = new Splay(a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		Node q = s.l;
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();
	public static void main(String[] args) {
//		Splay mySplay = new Splay(MIN_K);
//		mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		Splay mySplay = new Splay(a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


import java.util.*;
import java.util.Scanner;

public class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}
public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		Node q = s.l;
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();
	public static void main(String[] args) {
		Splay mySplay = new Splay(MIN_K);
		mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		mySplay.insert(mySplay.root, a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();

		Splay mySplay = new Splay(a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();

	public static void main(String[] args) {
//		Splay mySplay = new Splay(MIN_K);

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();

		Splay mySplay = new Splay(a[0]);
		mySplay.insert(mySplay.root, MAX_K);
		for(int i=1; i<n; i++){
			int ans = 0;
			mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		Node q = s.l;
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();
	public static void main(String[] args) {
		//mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		Splay mySplay = new Splay(a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();

	public static void main(String[] args) {
//		Splay mySplay = new Splay(MIN_K);
//		mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();

		Splay mySplay = new Splay(a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


package algorithm;

import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();

		Splay mySplay = new Splay(a[0]);
		System.out.println(mySplay.root.k);
		for(int i=1; i<n; i++){
			int ans = 0;
			mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && !left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


import java.util.*;
import java.util.Scanner;

public class Splay {
	Node root;
	Node _hot;
	Splay(){
		root = _hot = null;
	}
	Splay(int k){
		root = new Node(k, null);
		_hot = root;
	}
	void zig(Node cur){
		if(cur == null) return ;
		Node v = cur.l;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.l = v.r;
		if(cur.l != null) cur.l.p = cur;

		cur.p = v;
		v.r = cur;
		if(cur == root) root = v;
	}
	void zag(Node cur){
		if(cur == null) return ;
		Node v = cur.r;
		if(v == null) return ;
		Node g = cur.p;

		v.p = g;
		if(g != null){
			if(cur == g.l) g.l = v;
			else g.r = v;
		}

		cur.r = v.l;
		if(cur.r != null) cur.r.p = cur;

		cur.p = v;
		v.l = cur;
		if(cur == root) root = v;
	}
	void splay(Node x, Node f){
		if(x == null) return ;
		while(x.p != f){
			Node p = x.p;
			if(p == null) return ;
			if(p.p == f){
				if(x == p.l){

					zig(p);
				}
				else{
					zag(p);
				}
			}else{
				Node g = p.p;
				if(g == null) return ;
				if(g.l == p){
					if(p.l == x){
						zig(g); zig(p);
					}else{
						zag(p); zig(g);
					}
				}else{
					if(p.l == x){
						zig(p); zag(g);
					}else{
						zag(g); zag(p);
					}
				}
			}
		}
	}
	Node search(Node cur, int k){
		if(cur == null) return _hot;
		if(cur.k == k){
			splay(cur, null);
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return search(cur.l, k);
		else return search(cur.r, k);
	}
	Node insert(Node cur, int k){
		if(cur == null){
			cur = new Node(k, _hot);
			if(k < _hot.k) _hot.l = cur;
			else _hot.r = cur;
			_hot = cur;
			//System.out.println("find place");
			splay(cur, null);
			//System.out.println(cur.k + "created");
			return cur;
		}
		_hot = cur;
		if(k < cur.k) return insert(cur.l, k);
		else return insert(cur.r, k);
	}
	Node prev(int k){
		splay(search(root, k), null);
		Node cur = root.l;
		if(cur == null) return null;
		while(cur.r != null) cur = cur.r;
		return cur;
	}
	Node succ(int k){
		splay(search(root, k), null);
		Node cur = root.r;
		if(cur == null) return null;
		while(cur.l != null) cur = cur.l;
		return cur;
	}
	void deleteInterval(int a, int b){
		Node pa = search(root, a);
		if(pa.k != a) pa = insert(pa, a);
		Node pb = search(root, b);
		if(pb.k != b) pb = insert(pb, b);

		Node p = prev(a);
		Node s = succ(b);
		splay(p, null);
		splay(s, p);
		Node q = s.l;
		_hot = s;
		s.l = null;
	}
	static int MIN_K = 0;
	static int MAX_K = 1000000005;
	static Set<Integer> left = new HashSet<Integer>();
	static Set<Integer> right = new HashSet<Integer>();
	public static void main(String[] args) {
		Splay mySplay = new Splay(MIN_K);
		mySplay.insert(mySplay.root, MAX_K);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		mySplay.insert(mySplay.root, a[0]);
		for(int i=1; i<n; i++){
			int ans = 0;
			Node q = mySplay.insert(mySplay.root, a[i]);
			Node p = mySplay.prev(a[i]);
			if(p != null && !right.contains(p.k)){
				right.add(p.k);
				ans = p.k;
			}else{
				Node s = mySplay.succ(a[i]);
				if(s != null && left.contains(s.k)){
					left.add(s.k);
					ans = s.k;
				}
			}
			System.out.println(ans);
		}
	}
}
class Node{
	int k;
	Node l, r;
	Node p;
	Node(){p = null;}
	Node(int kk, Node pp){
		k = kk;
		p = pp;
		l = r = null;
	}
}


//package myPackage;

import java.util.*;

//import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;

import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
import java.util.Arrays;
public class Main
{

	public static void main(String[] args)
	{
		Map<Integer, Integer> left = new TreeMap<Integer, Integer>();
		Map<Integer, Integer> right = new TreeMap<Integer, Integer>();
		TreeSet<Integer> set = new TreeSet<>();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer a = sc.nextInt();
		set.add(a);
		for(int i = 1; i < n; i++)
		{
			a = sc.nextInt();
			Integer node = set.ceiling(a);
			Integer parent;
			if(node == null)
			{
				parent = set.floor(a);
				right.put(parent, a);
			}
			else
			{
				if(!left.containsKey(node))
				{
					parent = node;
					left.put(parent, a);
				}
				else
				{
					parent = set.floor(a);
					right.put(a, parent);
				}
			}
			set.add(a);
			out.print(parent);
			if(i != n - 1)
				out.print(" ");
			else
				out.println();
		}
	}
}


//package myPackage;

import java.util.*;
import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
public class Main
{
	static Map<Integer, Integer[]> map = new HashMap<Integer, Integer[]>();
	static int parent;
	static int root;
	public static void find(int root, int a)
	{
		if(map.containsKey(root))
		{
			if(a < root)
			{
				if(map.get(root)[0] == 0)
				{
					map.get(root)[0] = a;
					parent = root;
					return;
				}
				else
				{
					find(map.get(root)[0], a);
				}
			}
			else
			{
				if(map.get(root)[1] == 0)
				{
					map.get(root)[1] = a;
					parent = root;
					return;
				}
				else
				{
					find(map.get(root)[1], a);
				}
			}
		}
		else
		{
			Integer[] son = new Integer[2];
			if(a < root)
			{
				son[0] = a;
				son[1] = 0;
				map.put(root, son);
				parent = root;
				return;
			}
			else
			{
				son[0] = 0;
				son[1] = a;
				map.put(root, son);
				parent = root;
				return;
			}
		}
	}
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		root = sc.nextInt();
		for(int i = 1; i < n; i++)
		{
			int a = sc.nextInt();
			find(root, a);
			out.print(parent);
			if(i == n - 1)
				out.println();
			else
				out.print(" ");
		}
	}
}


//package myPackage;

import java.util.*;

import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;

import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
import java.util.Arrays;
public class Main
{

	public static void main(String[] args)
	{
		TreeMap<Integer, Integer> left = new TreeMap<Integer, Integer>();
		TreeMap<Integer, Integer> right = new TreeMap<Integer, Integer>();
		TreeSet<Integer> set = new TreeSet<>();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer a = sc.nextInt();
		set.add(a);
		for(int i = 1; i < n; i++)
		{
			a = sc.nextInt();
			Integer node = set.ceiling(a);
			Integer parent;
			if(node == null)
			{
				parent = set.floor(a);
				right.put(a, parent);
			}
			else
			{
				if(!left.containsValue(node))
				{
					parent = node;
					left.put(a, parent);
				}
				else
				{
					parent = set.floor(a);
					right.put(a, parent);
				}
			}
			set.add(a);
			out.print(parent);
			if(i != n - 1)
				out.print(" ");
			else
				out.println();
		}
	}
}


//package myPackage;

import java.util.*;

//import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;

import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
import java.util.Arrays;
public class Main
{

	public static void main(String[] args)
	{
		TreeMap<Integer, Integer> left = new TreeMap<Integer, Integer>();
		TreeMap<Integer, Integer> right = new TreeMap<Integer, Integer>();
		TreeSet<Integer> set = new TreeSet<>();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		set.add(a);
		for(int i = 1; i < n; i++)
		{
			a = sc.nextInt();
			Integer node = set.ceiling(a);
			Integer parent;
			if(node == null)
			{
				parent = set.floor(a);
				right.put(a, parent);
			}
			else
			{
				if(!left.containsValue(node))
				{
					parent = node;
					left.put(a, parent);
				}
				else
				{
					parent = set.floor(a);
					right.put(a, parent);
				}
			}
			set.add(a);
			out.print(parent);
			if(i != n - 1)
				out.print(" ");
			else
				out.println();
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

typedef long long ll;
typedef pair<int, int> pii;

const int MOD = (int)1e9 + 7;

int mult(int a, int b) {
    return (a * 1LL * b) % MOD;
}

const int N = 5050;

int s[N];
int l[N], r[N];
int pref[N][N];
set<int> cow[N];

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf("%d", &s[i]), --s[i];

    for (int i = 0; i < n; ++i) {
        for (int x = 0; x < n; ++x)
            pref[x][i + 1] = pref[x][i] + (s[i] == x);
    }

    while(m--) {
        int color, dist;
        scanf("%d %d", &color, &dist);
        --color;
        if (dist <= pref[color][n]) {
            cow[color].insert(dist);
        }
    }

    int mx = 0, ways = 1;
    for (int x = 0; x < n; ++x) {
        l[x] = 0;
        r[x] = sz(cow[x]);
        if (sz(cow[x])) {
            ++mx;
            ways = mult(ways, sz(cow[x]));
        }
    }

    for (int i = 0; i < n; ++i)
    {
        int x = s[i];
        if (cow[x].count(pref[x][n] - pref[x][i]))
            --r[x];
        if (!cow[x].count(pref[x][i + 1]))
            continue;
        ++l[x];

        /*
        for (int c = 0; c < n; ++c)
            printf("%d: %d %d\n", c, l[c], r[c]);
        printf("\n");
        */

        int cur_mx = 1, cur_ways = 1;
        if (pref[x][n] - pref[x][i + 1] >= pref[x][i + 1]) {
            if (r[x] > 1) {
                cur_mx = 2;
                cur_ways = r[x] - 1;
            }
        }
        else {
            if (r[x] > 0) {
                cur_mx = 2;
                cur_ways = r[x];
            }
        }
        //printf("%d %d\n", cur_mx, cur_cnt);

        for (int c = 0; c < n; ++c) {
            if (c == x) continue;
            //printf("%d %d\n", cur_mx, cur_cnt);
            int cnt_one, cnt_pair;
            cnt_one = l[c] + r[c];
            cnt_pair = min(l[c], r[c]) * (max(l[c], r[c]) - 1);
            if (cnt_pair != 0) {
                cur_mx += 2;
                cur_ways = mult(cur_ways, cnt_pair);
            } else if (cnt_one != 0) {
                cur_mx += 1;
                cur_ways = mult(cur_ways, cnt_one);
            }
        }

        //printf("%d %d\n\n\n", cur_mx, cur_cnt);

        if (cur_mx > mx) {
            mx = cur_mx;
            ways = cur_ways;
        } else if (cur_mx == mx) {
            ways += cur_ways;
            ways %= MOD;
        }
    }

    printf("%d %d\n", mx, ways);

}


#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

typedef long long ll;
typedef pair<int, int> pii;

const int MOD = (int)1e9 + 7;

int mult(int a, int b) {
    return (a * 1LL * b) % MOD;
}

const int N = 5050;

int s[N];
int l[N], r[N];
int pref[N][N];
set<int> cow[N];

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf("%d", &s[i]), --s[i];

    for (int i = 0; i < n; ++i) {
        for (int x = 0; x < n; ++x)
            pref[x][i + 1] = pref[x][i] + (s[i] == x);
    }

    while(m--) {
        int col, dist;
        scanf("%d %d", &col, &dist);
        if (dist <= pref[x][n]) {
            --col;
            cow[col].insert(dist);
        }
    }

    int mx = 0, cnt = 1;
    for (int x = 0; x < n; ++x) {
        l[x] = 0;
        r[x] = sz(cow[x]);
        if (sz(cow[x])) {
            ++mx;
            cnt = mult(cnt, sz(cow[x]));
        }
    }

    for (int i = 0; i < n; ++i)
    {
        int x = s[i];
        if (cow[x].count(pref[x][n] - pref[x][i]))
            --r[x];
        if (!cow[x].count(pref[x][i + 1]))
            continue;
        ++l[x];

        /*
        for (int c = 0; c < n; ++c)
            printf("%d: %d %d\n", c, l[c], r[c]);
        printf("\n");
        */

        int cur_mx = 1, cur_cnt = 1;
        if (n - i - 1 >= i + 1) {
            if (r[x] > 1) {
                cur_mx = 2;
                cur_cnt = r[x] - 1;
            }
        }
        else {
            if (r[x] > 0) {
                cur_mx = 2;
                cur_cnt = r[x];
            }
        }
        //printf("%d %d\n", cur_mx, cur_cnt);

        for (int c = 0; c < n; ++c) {
            if (c == x) continue;
            //printf("%d %d\n", cur_mx, cur_cnt);
            int cnt_one, cnt_pair;
            cnt_one = l[c] + r[c];
            cnt_pair = min(l[c], r[c]) * (max(l[c], r[c]) - 1);
            if (cnt_pair != 0) {
                cur_mx += 2;
                cur_cnt = mult(cur_cnt, cnt_pair);
            } else if (cnt_one != 0) {
                cur_mx += 1;
                cur_cnt = mult(cur_cnt, cnt_one);
            }
        }

        //printf("%d %d\n\n\n", cur_mx, cur_cnt);

        if (cur_mx > mx) {
            mx = cur_mx;
            cnt = cur_cnt;
        } else if (cur_mx == mx) {
            cnt += cur_cnt;
            cnt %= MOD;
        }
    }

    printf("%d %d\n", mx, cnt);

}


#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

typedef long long ll;
typedef pair<int, int> pii;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    string s;
    cin >> s;
    int n = sz(s);

    vector<int> cnt(26, 0);
    for (char ch : s) ++cnt[ch - 'a'];

    ll best = 0;

    function<void(char)> chkmax = [&](char a) {
        int right = cnt[a - 'a'];
        best = max(best, (ll)right);
        vector<ll> res(26, 0);
        for (int i = 0; i < n; ++i) {
            if (s[i] == a) --right;
            res[s[i] - 'a'] += right;
        }
        best = max(best, *max_element(all(res)));
    };

    for (char a = 'a'; a <= 'z'; ++a)
        chkmax(a);

    cout << best;

}