#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; auto f = [N](vector A) { vector> v = {{0}}; for(int i = 1; i < N; i++) { if(v.back().size() == 1u) { v.back().push_back(i); } else { int a = v.back()[v.back().size() - 2]; int b = v.back()[v.back().size() - 1]; if(A[a] < A[b]) { if(A[b] < A[i]) { v.back().push_back(i); } else { v.push_back({i}); } } else { if(A[b] > A[i]) { v.back().push_back(i); } else { v.push_back({i}); } } } } int ans = 0; int n = v.size(); for(int i = 0; i + 1 < n; i++) { if(v[i].size() >= 2u) { if(A[v[i][0]] > A[v[i][1]]) { int L = v[i].size(); int R = v[i + 1].size(); if(L == R + 1) { ans = max(ans, R); } } } } return ans; }; int ans = f(A); for(auto &i : A) i *= -1; ans = max(ans, f(A)); cout << ans << endl; }