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

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

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

Input

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

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

Output

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

Examples

Input

3
1 2 3


Output

1 2


Input

5
4 2 3 1 6


Output

4 2 2 4
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
		// System.err.println(System.currentTimeMillis() - t);
	}

	public void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		long[] c = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
			b[i] = a[i];
		}
		Arrays.sort(b);
		for (int i = 0; i < n; ++i) {
			long v = a[i];
			a[i] = Arrays.binarySearch(b, a[i]);
			c[(int) a[i]] = v;
		}
		AVLTree tree = new AVLTree();
		LCATree lcatree = new LCATree(n);
		tree.insert(a[0]);
		lcatree.append(-1, (int) a[0]);
		boolean[] l = new boolean[n];
		boolean[] r = new boolean[n];
		l[(int) a[0]] = true;
		r[(int) a[0]] = true;
		for (int i = 1; i < n; ++i) {
			AVLTree.Node ceil = tree.ceiling(a[i]);
			AVLTree.Node floor = tree.floor(a[i]);
			int to = 0;
			if (!(ceil != null && floor != null)) {
				if (ceil != null && l[(int) ceil.key]) {
					to = -1;
				} else if (floor != null && r[(int) floor.key]) {
					to = 1;
				}
			} else {
				int lca = lcatree.lca((int) ceil.key, (int) floor.key);
				if (a[i] < lca) {
					to = -1;
				} else {
					to = 1;
				}
			}
			if (to == -1) {
				l[(int) ceil.key] = false;
				// System.out.println(ceil.key);
				System.out.println(c[(int) ceil.key]);
				lcatree.append((int) ceil.key, (int) a[i]);
				if (!r[(int) ceil.key])
					tree.delete(ceil);
			} else if (to == 1) {
				r[(int) floor.key] = false;
				System.out.println(c[(int) floor.key]);
				// System.out.println(floor.key);
				lcatree.append((int) floor.key, (int) a[i]);
				if (!l[(int) floor.key])
					tree.delete(floor);
			}
			tree.insert(a[i]);
			l[(int) a[i]] = true;
			r[(int) a[i]] = true;
		}
	}

	class LCATree {
		int[] depth;
		int[][] parent;
		int n;
		int root;

		public LCATree(int n_) {
			n = n_;
			parent = new int[30][n];
			depth = new int[n];
			for (int i = 0; i < parent.length; ++i) {
				for (int j = 0; j < parent[i].length; ++j) {
					parent[i][j] = -1;
				}
			}
		}

		void append(int p, int c) {
			if (p == -1) {
				root = c;
				return;
			}
			if (parent[0][c] != -1)
				throw new AssertionError();
			parent[0][c] = p;
			depth[c] = depth[p] + 1;
			for (int i = 1; i < 30; ++i) {
				if (parent[i - 1][c] == -1)
					break;
				parent[i][c] = parent[i - 1][parent[i - 1][c]];
			}
		}

		int lca(int u, int v) {
			if (depth[u] > depth[v]) {
				u ^= v;
				v ^= u;
				u ^= v;
			}
			for (int d = depth[v] - depth[u], c = 0; d > 0; d >>= 1, ++c) {
				if (d % 2 == 1) {
					v = parent[c][v];
				}
			}
			if (depth[u] != depth[v])
				throw new AssertionError();
			if (u == v)
				return u;
			for (int i = 29; i >= 0; --i) {
				if (parent[i][u] != parent[i][v]) {
					u = parent[i][u];
					v = parent[i][v];
				}
			}
			return parent[0][u];
		}

	}

	public static class AVLTree {
		Node root = null;

		Node ceiling(long v) {
			Node node = root;
			while (node != null) {
				if (min(node.right) <= v) {
					node = node.right;
				} else if (node.key <= v)
					return node;
				else
					node = node.left;
			}
			return node;
		}

		Node floor(long v) {
			Node node = root;
			while (node != null) {
				if (max(node.left) >= v) {
					node = node.left;
				} else if (node.key >= v)
					return node;
				else
					node = node.right;
			}
			return node;
		}

		class Node {
			long key;
			long max;
			long min;
			int height;
			int balance;
			int sz = 1;
			Node left = null;
			Node right = null;
			Node parent = null;

			public Node(long key_, Node parent_) {
				key = key_;
				parent = parent_;
				max = key_;
				min = key_;
			}
		}

		Node kth(long a) {
			Node node = root;
			int sum = 0;
			while (node != null) {
				if (sum + node.sz < a) {
					return null;
				}
				if (sum + sz(node.left) + 1 == a) {
					return node;
				}
				if (sum + sz(node.left) + 1 < a) {
					sum = sum + 1 + sz(node.left);
					node = node.right;
				} else {
					node = node.left;
				}
			}
			return null;
		}

		boolean contain(int delKey) {
			if (root == null)
				return false;
			Node node = root;
			while (node != null) {
				if (delKey == node.key) {
					return true;
				}
				node = delKey >= node.key ? node.right : node.left;
			}
			return false;
		}

		boolean delete(long key) {
			if (root == null)
				return false;
			Node node = root;
			while (node != null) {
				if (key == node.key) {
					delete(node);
					return true;
				}
				node = key >= node.key ? node.right : node.left;
			}
			return false;
		}

		void delete(Node node) {
			if (node.left == null && node.right == null) {
				if (node.parent == null) {
					root = null;
					return;
				}
				Node parent = node.parent;
				if (parent.left == node)
					parent.left = null;
				else
					parent.right = null;
				rebalance(parent);
			}
			if (node.left != null) {
				Node child = node.left;
				while (child.right != null) {
					child = child.right;
				}
				node.key = child.key;
				delete(child);
			} else if (node.right != null) {
				Node child = node.right;
				while (child.left != null) {
					child = child.left;
				}
				node.key = child.key;
				delete(child);
			}
		}

		boolean insert(long key) {
			if (root == null) {
				root = new Node(key, null);
				return true;
			}
			Node cur = root;
			Node parent = null;
			while (true) {
				if (cur.key == key) {
					return false;
				}
				parent = cur;
				boolean goLeft = key < cur.key;
				cur = goLeft ? cur.left : cur.right;
				if (cur == null) {
					if (goLeft) {
						parent.left = new Node(key, parent);
					} else {
						parent.right = new Node(key, parent);
					}
					rebalance(parent);
					break;
				}

			}
			return true;
		}

		void rebalance(Node n) {
			setBalance(n);
			if (n.balance == -2) {
				if (height(n.left.left) >= height(n.left.right)) {
					n = rotateRight(n);
				} else {
					n = rotateLeftThenRight(n);
				}
			} else if (n.balance == 2) {
				if (height(n.right.right) >= height(n.right.left)) {
					n = rotateLeft(n);
				} else {
					n = rotateRightThenLeft(n);
				}
			}
			if (n.parent != null) {
				rebalance(n.parent);
			} else {
				root = n;
			}
		}

		void setBalance(Node... nodes) {
			for (Node n : nodes) {
				n.height = 1 + Math.max(height(n.right), height(n.left));
				n.balance = height(n.right) - height(n.left);
				n.sz = 1 + sz(n.left) + sz(n.right);
				n.max = Math.max(n != null ? n.key : -Integer.MAX_VALUE, Math.max(max(n.left), max(n.right)));
				n.min = Math.min(n != null ? n.key : Integer.MAX_VALUE, Math.min(min(n.left), min(n.right)));
			}
		}

		int sz(Node node) {
			return node != null ? node.sz : 0;
		}

		int height(Node node) {
			return node != null ? node.height : -1;
		}

		long max(Node node) {
			return node != null ? node.max : -Long.MAX_VALUE;
		}

		long min(Node node) {
			return node != null ? node.min : Long.MAX_VALUE;
		}

		Node rotateRight(Node a) {
			Node b = a.left;
			if (a.parent != null) {
				if (a.parent.left == a) {
					a.parent.left = b;
				} else {
					a.parent.right = b;
				}
			}
			b.parent = a.parent;
			a.parent = b;
			a.left = b.right;
			b.right = a;
			if (a.left != null)
				a.left.parent = a;
			setBalance(a, b);
			return b;
		}

		Node rotateLeft(Node a) {
			Node b = a.right;
			if (a.parent != null) {
				if (a.parent.right == a) {
					a.parent.right = b;
				} else {
					a.parent.left = b;
				}
			}
			b.parent = a.parent;
			a.parent = b;
			a.right = b.left;
			b.left = a;
			if (a.right != null)
				a.right.parent = a;
			setBalance(a, b);
			return b;
		}

		Node rotateLeftThenRight(Node n) {
			n.left = rotateLeft(n.left);
			return rotateRight(n);
		}

		Node rotateRightThenLeft(Node n) {
			n.right = rotateRight(n.right);
			return rotateLeft(n);
		}

		void inOrder(Node cur) {
			if (cur == null)
				return;
			inOrder(cur.left);
			System.out.println(cur.key);
			inOrder(cur.right);
		}
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}