#include #include #include #include #include #include #include #include #include #include #include #include #define ALL(g) (g).begin(),(g).end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define pb push_back using namespace std; typedef long long ll; typedef pair P; const int mod=1e9+7; const int INF=1<<30; const int MAX_N=100001; int main(){ int N; cin >> N ; ll ma=0,mi=0,a; rep(i,N){ cin >> a ; ll temp=mi; ma=max(max(ma+a,ma*a),max(ma-a,mi*a)); if(a) mi=min(min(mi+a,mi-a),min(mi/a,min(mi*a,temp*a))); } cout << ma << endl; return 0; }