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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<int> v(n);
	for(auto &x : v)cin>>x;
	v.insert(v.end(), v.begin(), v.end());
	deque<pair<int, int>> dq;
	reverse(v.begin(), v.end());
	int res = 0;
	for(int i=0; i<2*n; i++){
		while(!dq.empty() && dq.front().second + n <= i){
			dq.pop_front();
		}
		while(!dq.empty() && dq.back().first <= v[i]){
			dq.pop_back();
		}
		dq.push_back({v[i], i});
		res = max(res, (int)dq.size());
	}
	cout<<res<<"\n";
	return 0;
}