const int INF = 1000000000; const double eps = 1e-8; const int maxn = 301000; typedef pair<int,int> ii; int a[maxn]; int next[maxn];//链表指针 int main() { //freopen("in.txt","r",stdin); int n; while(cin>>n) { queue<ii> q; rep(i,0,n) { scanf("%d",&a[i]); next[i] = i+1; } repd(i,n-2,0) { if(a[i] > a[i+1]) q.push(ii(i,0)); } int ans = 0; while(!q.empty()) { int pos = q.front().first; int cas = q.front().second; ans = max(ans,cas); q.pop(); if(next[pos] != n && a[pos] > a[next[pos]]) { q.push(ii(pos,cas+1)); next[pos] = next[next[pos]]; } } cout<<ans<<endl; } return 0; }