#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 ll f(ll x, ll y, int ope) { if (ope == 0) return x + y; else if (ope == 1) return x - y; else if (ope == 2) return x*y; else return x / y; } int a[16]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) cin >> a[i]; ll up = a[0]; ll bottom = a[0]; for (int i = 1; i < N; i++) { ll tmpup = -LLINF; ll tmpbottom = LLINF; for (int j = 0; j < 3; j++) { tmpup = max(tmpup, f(up, a[i], j)); tmpup = max(tmpup, f(bottom, a[i], j)); tmpbottom = min(tmpbottom, f(up, a[i], j)); tmpbottom = min(tmpbottom, f(bottom, a[i], j)); } if (a[i] != 0) { tmpup = max(tmpup, f(up, a[i], 3)); tmpup = max(tmpup, f(bottom, a[i], 3)); tmpbottom = min(tmpbottom, f(up, a[i], 3)); tmpbottom = min(tmpbottom, f(bottom, a[i], 3)); } up = tmpup; bottom = tmpbottom; } cout << up << endl; return 0; }