#include <iostream>
#include <cstdlib>
using namespace std;
int min(int a, int b){
return a>b?b:a;
}
int max(int a, int b){
return a>b?a:b;
}
int maxProduct(int A[], int n) {
if (n == 0 ){
return 0;
}
if (n == 1 )
{
return A[0];
}
int maxproduct = A[0];
int minproduct = A[0];
int result = maxproduct;
int i = 0;
for(i = 1; i < n; i++){
int tmp = maxproduct;
maxproduct = max(max(maxproduct*A[i], A[i]), minproduct*A[i] );
minproduct = min(min(tmp*A[i], A[i]), minproduct*A[i] );
result = max(maxproduct,result);
}
return result;
}
int main(int argc, char** argv) {
int A[] = {2,3,-2,4};
int n = 4;
cout<<maxProduct(A,n)<<endl;
return 0;
}