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.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws Exception {
    	//InputStream inputStream = new FileInputStream("d.in");
    	InputStream inputStream = System.in;
    	OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(in, out);
        out.close();
    }
    
    static class Interval implements Comparable<Interval>{
    	private Integer beg, end;

    	public Interval(int b, int e){
    		this.beg = b;
    		this.end = e;
    	}
    	
		@Override
		public int compareTo(Interval o) {
			if(this.beg < o.beg) return -1;
			else if(this.beg > o.beg) return 1;
			else if(this.end < o.end) return -1;
			else if(this.end > o.end) return 1;
			return 0;
		}

		public Integer getBeg() {
			return beg;
		}

		public void setBeg(Integer beg) {
			this.beg = beg;
		}

		public Integer getEnd() {
			return end;
		}

		public void setEnd(Integer end) {
			this.end = end;
		}
		
		
    	
    	
    }
    static class TaskD {
        public void solve(InputReader in, OutputWriter out) {
            Integer n = Integer.parseInt(in.next());
            
            TreeMap<Interval, Integer> t = new TreeMap<>();
            
            int x = Integer.parseInt(in.next());
            
            if(x-1 >= 1) t.put(new Interval(1, x-1), x);
            if(x+1 <= 1000000000) t.put(new Interval(x+1, 1000000000), x);
            
            StringBuilder ans = new StringBuilder();
            
            for(int i = 0; i<n-1; i++){
            	x = Integer.parseInt(in.next());
            	Map.Entry<Interval, Integer> entry = t.floorEntry(new Interval(x+1, x+1));
            	Interval key = entry.getKey();
            	Integer value = entry.getValue();
            	if(i > 0) ans.append(" ");
            	ans.append(value);
            	t.remove(key);
            	if(x-1 >= key.getBeg()) t.put(new Interval(key.getBeg(), x-1), x);
            	if(x+1 <= key.getEnd()) t.put(new Interval(x+1, key.getEnd()), x);
            	
            	//for(Map.Entry<Interval, Integer> et : t.entrySet()){
            	//	System.out.print(et.getKey().getBeg() + "," + et.getKey().getEnd() + " -> " + et.getValue() + "\n");
            	//}
            	//System.out.print("RESP " + value + "\n");
            }
            
            out.print(ans.toString());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }
        
        public void print(String i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}