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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Map.Entry;
import java.util.TreeMap;

public class P675D {
  InputStream is;
  PrintWriter out;
  String INPUT = "5 4 2 3 1 6";
      
  public class BinarySearchTree<Key extends Comparable<Key>, Value> {
    private Node root;

    private class Node {
      private Key key;
      private Value value;
      private Node left;
      private Node right;
      private int N;

      public Node(Key key, Value value, int n) {
        this.key = key;
        this.value = value;
        N = n;
      }
    }

    public boolean contains(Key key) {
      return get(key) != null;
    }

    public Value get(Key key) {
      return get(root, key);
    }

    private Value get(Node node, Key key) {
      if (node == null) {
        return null;
      }
      final int cmp = key.compareTo(node.key);
      if (cmp < 0) return get(node.left, key);
      if (cmp > 0) return get(node.right, key);
      return node.value;
    }

    public int size() {
      return size(root);
    }

    private int size(Node root) {
      return root == null ? 0 : root.N;
    }

    public void put(Key key, Value value) {
      root = put(root, root, key, value);
    }

    private Node put(Node parent, Node node, Key key, Value value) {
      if (node == null) {
        if (parent != null) {
          out.print(String.valueOf(parent.value) + " ");
        }
        return new Node(key, value, 1);
      }
      final int cmp = key.compareTo(node.key);
      if (cmp < 0) {
        node.left = put(node, node.left, key, value);
      } else if (cmp > 0) {
        node.right = put(node, node.right, key, value);
      } else {
        node.value = value;
      }
      node.N = 1 + size(node.left) + size(node.right);
      return node;
    }
  }
  
  void solve() {
    int n = ni();
    int[] a = new int[n - 1];
    // BinarySearchTree<Integer, Integer> 
    //  tree = new BinarySearchTree<Integer, Integer>();
    TreeMap<Integer, Integer> tree = new TreeMap<Integer, Integer>();
    for (int i = 0; i < n; i++) {
      int num = ni();
      Entry<Integer, Integer> next = tree.ceilingEntry(num);
      Entry<Integer, Integer> prev = tree.floorEntry(num);
      if (next != null && prev != null) {
        if (next.getValue() > prev.getValue()) {
          out.print(next.getKey() + " ");
        } else {
          out.print(prev.getKey() + " ");
        }
      } else if (next != null) {
        out.print(next.getKey() + " ");
      } else if (prev != null) {
        out.print(prev.getKey() + " ");
      }
      tree.put(num, i);
    }
  }
  
  public static void main(String[] args) throws Exception {
    new P675D().run();
  }
  
  void run() throws Exception {
    is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
    out = new PrintWriter(System.out);
  
    long s = System.currentTimeMillis();
    solve();
    out.flush();
    tr(System.currentTimeMillis() - s + "ms");
  }
  
  private byte[] inbuf = new byte[1024];
  private int lenbuf = 0, ptrbuf = 0;
  
  private int readByte() {
    if (lenbuf == -1)
      throw new InputMismatchException();
    if (ptrbuf >= lenbuf) {
      ptrbuf = 0;
      try {
        lenbuf = is.read(inbuf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (lenbuf <= 0)
        return -1;
    }
    return inbuf[ptrbuf++];
  }
  
  private boolean isSpaceChar(int c) {
    return !(c >= 33 && c <= 126);
  }
  
  private int skip() {
    int b;
    while ((b = readByte()) != -1 && isSpaceChar(b))
      ;
    return b;
  }
  
  private double nd() {
    return Double.parseDouble(ns());
  }
  
  private char nc() {
    return (char) skip();
  }
  
  private String ns() {
    int b = skip();
    StringBuilder sb = new StringBuilder();
    while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }
  
  private char[] ns(int n) {
    char[] buf = new char[n];
    int b = skip(), p = 0;
    while (p < n && !(isSpaceChar(b))) {
      buf[p++] = (char) b;
      b = readByte();
    }
    return n == p ? buf : Arrays.copyOf(buf, p);
  }
  
  private char[][] nm(int n, int m) {
    char[][] map = new char[n][];
    for (int i = 0; i < n; i++)
      map[i] = ns(m);
    return map;
  }
  
  private int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }
  
  private int ni() {
    int num = 0, b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
      ;
    if (b == '-') {
      minus = true;
      b = readByte();
    }
  
    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }
  
  private long nl() {
    long num = 0;
    int b;
    boolean minus = false;
    while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
      ;
    if (b == '-') {
      minus = true;
      b = readByte();
    }
  
    while (true) {
      if (b >= '0' && b <= '9') {
        num = num * 10 + (b - '0');
      } else {
        return minus ? -num : num;
      }
      b = readByte();
    }
  }
  
  private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
  
  private void tr(Object... o) {
    if (!oj)
      System.out.println(Arrays.deepToString(o));
  }
}
