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.*;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    private NotMyScanner in;
    private PrintWriter out;
//    private Timer timer = new Timer();

    class Segment implements Comparable<Segment> {
        int start, end, parent;

        public Segment(int start, int end, int parent) {
            this.start = start;
            this.end = end;
            this.parent = parent;
        }

        public int compareTo(Segment o) {
            return start - o.start;
        }

        boolean isCorrect() {
            return start <= end;
        }
    }


    private void solve() throws IOException {
        int n = in.nextInt();
        TreeSet<Segment> ts = new TreeSet<Segment>();
        int root = in.nextInt();
        ts.add(new Segment(0, root - 1, root));
        ts.add(new Segment(root + 1, (int)1e9 + 1, root));
        for (int i = 1; i < n; i++) {
            int added = in.nextInt();
            Segment cur = ts.floor(new Segment(added, 0, 0));
//            System.err.println(added + " " + cur.start + " " + cur.end);
            out.print(cur.parent);
            out.print(' ');
            ts.remove(cur);
            Segment l = new Segment(cur.start, added - 1, added);
            Segment r = new Segment(added + 1, cur.end, added);
            if (l.isCorrect()) ts.add(l);
            if (r.isCorrect()) ts.add(r);
        }
        out.println();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        in = new NotMyScanner();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }
}

class NotMyScanner {

    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public NotMyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public NotMyScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public NotMyScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

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

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

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

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

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

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }
}