#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } int main() { int N; while (~scanf("%d", &N)) { vector a(N); for (int i = 0; i < N; ++ i) scanf("%d", &a[i]); vector dpMax(N, -INFL); vector dpMin(N, INFL); dpMax[0] = dpMin[0] = a[0]; rep(i, N - 1) { for (ll x : {dpMax[i], dpMin[i]}) { int y = a[i + 1]; amax(dpMax[i + 1], max({ x + y, x - y, x * y, y == 0 ? -INFL : x / y })); amin(dpMin[i + 1], min({ x + y, x - y, x * y, y == 0 ? INFL : x / y })); } } ll ans = dpMax[N - 1]; printf("%lld\n", ans); } return 0; }