#include <bits/stdc++.h>
using namespace std;
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
int isDigit(char xx) { return ('0' <= xx && xx <= '9'); }
void swapInt(int &x, int &y) {
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
}
class bigint {
 public:
  int a[100];
  void add(bigint &y);
  void print();
};
void bigint::add(bigint &y) {
  int i, d;
  if (a[0] < y.a[0]) a[0] = y.a[0];
  d = 0;
  for (i = 1; i <= a[0]; i++) {
    a[i] += y.a[i] + d;
    d = a[i] / 1000000;
    a[i] %= 1000000;
  }
  while (d > 0) {
    a[0]++;
    a[a[0]] = d % 1000000;
    d /= 1000000;
  }
}
void bigint::print() {
  int i, n = a[0];
  cout << a[n];
  for (i = n - 1; i >= 1; i--) {
    if (a[i] < 10)
      cout << "00000";
    else if (a[i] < 100)
      cout << "0000";
    else if (a[i] < 1000)
      cout << "000";
    else if (a[i] < 10000)
      cout << "00";
    else if (a[i] < 100000)
      cout << "0";
    cout << a[i];
  }
}
int exitInput = 0;
int ntest = 1, itest = 1;
void read();
void solve();
int main() {
  clock_t t1, t2;
  t1 = clock();
  for (itest = 1; itest <= ntest; ++itest) {
    read();
    if (exitInput) {
      break;
    }
    if (itest > 1) {
    }
    solve();
  }
  t2 = clock();
  return 0;
}
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const long long Mod = 1e9 + 7;
const int maxn = 1e5 + 2;
int n, a[maxn], ans[maxn], res;
int it[4 * maxn + 4];
void update(int node, int l, int r, int idx, int val) {
  if (r < idx || idx < l) {
    return;
  }
  if (r == l && r == idx) {
    it[node] = val;
    return;
  }
  update((node << 1), l, ((l + r) >> 1), idx, val);
  update(((node << 1) + 1), ((l + r) >> 1) + 1, r, idx, val);
  it[node] = max(it[(node << 1)], it[((node << 1) + 1)]);
}
int query(int node, int l, int r, int i, int j) {
  if (i > j) {
    return 0;
  }
  if (r < i || j < l) {
    return 0;
  }
  if (i <= l && r <= j) {
    return it[node];
  }
  int p1 = query((node << 1), l, ((l + r) >> 1), i, j);
  int p2 = query(((node << 1) + 1), ((l + r) >> 1) + 1, r, i, j);
  return max(p1, p2);
}
void read() {
  gi(n);
  for (int i = 1; i <= n; ++i) {
    gi(a[i]);
  }
}
void solve() {
  int i, j;
  stack<int> st;
  for (i = 1; i <= n; ++i) {
    while (!st.empty() && a[st.top()] <= a[i]) {
      st.pop();
    }
    while (!st.empty()) {
      j = st.top();
      int val = query(1, 1, n, j + 1, i - 1);
      int t = ans[j];
      if (t <= val) {
        st.pop();
      } else
        break;
    }
    if (!st.empty()) {
      j = st.top();
      ans[i] = query(1, 1, n, j + 1, i - 1) + 1;
      res = max(res, ans[i]);
    } else {
      ans[i] = 1e9;
    }
    st.push(i);
    update(1, 1, n, i, ans[i]);
  }
  cout << res;
}

### Prompt

Your task is to create a cpp solution to the following problem:

There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. 

You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.

Input

The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right.

Output

Print the number of steps, so that the line remains the same afterward.

Examples

Input

10
10 9 7 8 6 5 3 4 2 1


Output

2


Input

6
1 2 3 4 5 6


Output

0

Note

In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1]  →  [10 8 4] →  [10]. So, there are two steps.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
int isDigit(char xx) { return ('0' <= xx && xx <= '9'); }
void swapInt(int &x, int &y) {
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
}
class bigint {
 public:
  int a[100];
  void add(bigint &y);
  void print();
};
void bigint::add(bigint &y) {
  int i, d;
  if (a[0] < y.a[0]) a[0] = y.a[0];
  d = 0;
  for (i = 1; i <= a[0]; i++) {
    a[i] += y.a[i] + d;
    d = a[i] / 1000000;
    a[i] %= 1000000;
  }
  while (d > 0) {
    a[0]++;
    a[a[0]] = d % 1000000;
    d /= 1000000;
  }
}
void bigint::print() {
  int i, n = a[0];
  cout << a[n];
  for (i = n - 1; i >= 1; i--) {
    if (a[i] < 10)
      cout << "00000";
    else if (a[i] < 100)
      cout << "0000";
    else if (a[i] < 1000)
      cout << "000";
    else if (a[i] < 10000)
      cout << "00";
    else if (a[i] < 100000)
      cout << "0";
    cout << a[i];
  }
}
int exitInput = 0;
int ntest = 1, itest = 1;
void read();
void solve();
int main() {
  clock_t t1, t2;
  t1 = clock();
  for (itest = 1; itest <= ntest; ++itest) {
    read();
    if (exitInput) {
      break;
    }
    if (itest > 1) {
    }
    solve();
  }
  t2 = clock();
  return 0;
}
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const long long Mod = 1e9 + 7;
const int maxn = 1e5 + 2;
int n, a[maxn], ans[maxn], res;
int it[4 * maxn + 4];
void update(int node, int l, int r, int idx, int val) {
  if (r < idx || idx < l) {
    return;
  }
  if (r == l && r == idx) {
    it[node] = val;
    return;
  }
  update((node << 1), l, ((l + r) >> 1), idx, val);
  update(((node << 1) + 1), ((l + r) >> 1) + 1, r, idx, val);
  it[node] = max(it[(node << 1)], it[((node << 1) + 1)]);
}
int query(int node, int l, int r, int i, int j) {
  if (i > j) {
    return 0;
  }
  if (r < i || j < l) {
    return 0;
  }
  if (i <= l && r <= j) {
    return it[node];
  }
  int p1 = query((node << 1), l, ((l + r) >> 1), i, j);
  int p2 = query(((node << 1) + 1), ((l + r) >> 1) + 1, r, i, j);
  return max(p1, p2);
}
void read() {
  gi(n);
  for (int i = 1; i <= n; ++i) {
    gi(a[i]);
  }
}
void solve() {
  int i, j;
  stack<int> st;
  for (i = 1; i <= n; ++i) {
    while (!st.empty() && a[st.top()] <= a[i]) {
      st.pop();
    }
    while (!st.empty()) {
      j = st.top();
      int val = query(1, 1, n, j + 1, i - 1);
      int t = ans[j];
      if (t <= val) {
        st.pop();
      } else
        break;
    }
    if (!st.empty()) {
      j = st.top();
      ans[i] = query(1, 1, n, j + 1, i - 1) + 1;
      res = max(res, ans[i]);
    } else {
      ans[i] = 1e9;
    }
    st.push(i);
    update(1, 1, n, i, ans[i]);
  }
  cout << res;
}

```