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
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926;
template <typename T>
T gcd(T a, T b) {
  while (b) {
    T c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
T lcm(T a, T b) {
  assert(a / gcd(a, b) <= numeric_limits<T>::max() / b);
  return a * (b / gcd(a, b));
}
class out {
 public:
  template <typename T>
  out &operator()(const T &t) {
    cout << t << ' ';
    return *this;
  }
  template <typename T1, typename T2>
  out &operator()(const pair<T1, T2> &t) {
    cout << '(' << t.first << ',' << t.second << ')' << ' ';
    return *this;
  }
};
template <typename iter>
inline void print_(iter beg, iter end) {
  for_each(beg, end, out());
  cout << endl;
}
template <typename T>
inline void print_(const T &t) {
  cout << t << endl;
}
inline void print_(const char *fmt, ...) {
  va_list va;
  va_start(va, fmt);
  vprintf(fmt, va);
  va_end(va);
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N]) {
  for (unsigned int i = 0; i < M; ++i) {
    for (unsigned int j = 0; j < N; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N], unsigned int r, unsigned int c) {
  for (unsigned int i = 0; i < r; ++i) {
    for (unsigned int j = 0; j < c; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T>
inline int BKDRHash(const T *str) {
  register int hash = 0;
  while (int ch = (int)*str++) {
    hash = hash * 131 + ch;
  }
  return hash;
}
inline unsigned long long powxy(unsigned long long x, int y = 2) {
  unsigned long long r;
  for (r = 1; y > 0; --y) r *= x;
  return r;
}
inline unsigned long long factorial(unsigned long long n) {
  unsigned long long r;
  for (r = 1; n > 0; --n) r *= n;
  return r;
}
inline unsigned long long permutation(unsigned long long n,
                                      unsigned long long k) {
  unsigned long long r = 1;
  while (k--) r *= n--;
  return r;
}
inline unsigned long long combination(unsigned long long n,
                                      unsigned long long k) {
  return permutation(n, k) / factorial(k);
}
inline string tostr(int i) {
  ostringstream is;
  is << i;
  return is.str();
}
int n;
vector<char> lv, rv;
struct node {
  int left;
  int right;
  int v;
  node(int v) : v(v) {
    left = lv.size();
    lv.push_back(0);
    right = rv.size();
    rv.push_back(0);
  }
};
struct cmp : public binary_function<const node &, const node &, bool> {
  bool operator()(const node &n1, const node &n2) { return n1.v < n2.v; }
};
set<node, cmp> s;
int main() {
  int v1;
  scanf("%d%d", &n, &v1);
  clock_t start = clock();
  s.insert(node(v1));
  for (int i = 1; i < n; ++i) {
    int v;
    scanf("%d", &v);
    set<node, cmp>::iterator iter = s.insert(node(v)).first;
    set<node, cmp>::iterator pre = iter;
    --pre;
    set<node, cmp>::iterator nxt = iter;
    ++nxt;
    if (iter == s.begin() || rv[pre->right]) {
      lv[nxt->left] = 1;
      printf("%d ", nxt->v);
    } else {
      rv[pre->right] = 1;
      printf("%d ", pre->v);
    }
    if (clock() - start >= 1900) break;
  }
  return 0;
}
