6049: Psychos in a Line

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:4

题目描述

B. Psychos in a Line
B、 排队的精神病患者
有n个精神病患者在排队。每一个疯子都被分配一个从1到n的唯一整数。在每一步中,每一个id大于他右边的疯子(如果存在)的疯子都会杀死他右边的邻居。注意,一个疯子可能会同时杀人和被杀。

你已经得到了队列中精神病患者的初步安排。计算到这一刻需要多少步,这样在那一刻之后就没有人杀死他的邻居了。查看笔记以更准确地理解陈述。




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.

输入格式

第一行输入包含整数n,表示精神病的数量,(1≤n≤105)。在第二行中,将有一个由n个空间分隔的不同整数组成的列表,每个整数的范围从1到n,包括从左到右一行中的精神病类。

输出格式

打印步骤数,以便之后行保持不变。

输入样例 复制

10
10 9 7 8 6 5 3 4 2 1

输出样例 复制

2