#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using PII = pair; using PDD = pair; using PLL = pair; using VPII = vector; template using VT = vector; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back template inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; const double EPS = 1e-9; const int MAX = 20; LL N, a[MAX]; LL dp[MAX][2]; LL mi, ma; int main() { cin >> N; REP(i, N) { cin >> a[i]; if (i == 0) mi = ma = a[i]; else { if (a[i] == 0) { chmax(ma, 0ll); chmin(mi, 0ll); } else if (a[i] > 0) { LL buf = max(ma + a[i], ma * a[i]); ma = buf; buf = min(mi - a[i], min(mi / a[i], min(mi * a[i], ma / a[i]))); mi = buf; } else { LL buf = max(ma - a[i], mi * a[i]); ma = buf; buf = min(mi + a[i], min(mi / a[i], min(ma / a[i], min(ma * a[i], mi * a[i])))); mi = buf; } } } cout << ma << endl; }