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
44
45
46
47
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;





signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; cin>>n;
    vector<int>a(n);
    int pos_maxi = -1, maxi = -1;
    for(int i=0; n>i; i++){
        cin>>a[i];
        if(a[i] > maxi){
            maxi = a[i];
            pos_maxi = i;
        }
    }    
    int res = 1;
    vector<int>vec_res;
    vec_res.push_back(maxi);
    for(int j=1; n>j; j++){
        int i = (pos_maxi - j + n) % n;
        while(!vec_res.empty() && vec_res.back() <= a[i]){
            vec_res.pop_back();
        }
        vec_res.push_back(a[i]);
        res = max(res, (int)vec_res.size());
    }
    cout<<res;
}


/*
7
1 7 2 3 7 2 9


*/