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
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define vc vector
#define st first
#define nd second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)a.size()
#define pub push_back
#define pob pop_back

void program() {
	ll n;
	cin >> n;
	vc<ll> a(n);
	for (ll &ai : a)
		cin >> ai;
	
	deque<pll> dq;
	for (ll i = 0; i < n; i++)
		if (dq.empty() or a[i] > dq.back().nd)
			dq.pub({i, a[i]});

	ll ans = sz(dq);
	for (ll i = n - 1; i >= 0; i--) {
		if (dq.back().st == i)
			dq.pob();
		while (not dq.empty() and dq.front().nd <= a[i])
			dq.pop_front();
		dq.push_front({i, a[i]});
		ans = max(ans, sz(dq));
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	program();
	return 0;
}