1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define BOOST ios_base::sync_with_stdio(0), cin.tie(0)
template<typename T>
using vc = vector<T>;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;

int main(){
	BOOST;
	int n;
	cin >> n;
	vc<int> t(2*n);
	for(int i=0; i<n; i++) cin >> t[i];
	for(int i=0; i<n; i++) t[n+i] = t[i];

	int ans = 0;
	stack<int> q;
	for(int i=2*n-1; i>=0; i--){
		while(q.size() && q.top() <= t[i]) q.pop();
		q.push(t[i]);
		ans = max(ans, (int)q.size());
	}

	cout << ans << "\n";
}