#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < (y);x++) #define LLI long long int #define FORR(x,arr) for(auto& x:arr) #define ALL(a) (a.begin()),(a.end()) #define _L(x) cout<<(x)<= 0) { return target; } target = 0; FOR(x, left) { if(A[x] < A[left] && A[left] - A[x] < A[right]-A[left]) { target = max(target,Left(x, left) + 1); } } return target; } int Right(int left, int right) { int& target = L[left][right]; if(target >= 0) { return target; } target = 0; for(int x = right + 1;x < N;x++) { if(A[x] < A[right] && A[right] - A[x] < A[left]-A[right]) { target = max(target,Right(right, x) + 1); } } return target; } int Calculate(int peakIndex) { int left = 0; int right = 0; FOR(x, peakIndex) { if(A[x] < A[peakIndex]) { left = max(left, Left(x,peakIndex) + 1); } } for(int x = peakIndex + 1;x < N;x++) { if(A[x] < A[peakIndex]) { right = max(right, Right(peakIndex, x) + 1); } } return left + right + 1; } int main() { cin>>N; FOR(i,N) cin>>A[i]; FOR(i,101) FOR(j,101) { L[i][j] = -1; R[i][j] = -1; } int maxLength = -1; FOR(i, N) { maxLength = max(maxLength, Calculate(i)); } cout << maxLength << endl; return 0; }