#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; constexpr ll INF = (1LL << 60); int main(){ int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; vector dp(2); dp[0] = a[0]; dp[1] = a[0]; auto f = [&](ll a, ll b, int c) { if (c) return min(a, b); return max(a, b); }; for (int i = 1; i < n; i++) { vector next(2); next[0] = -INF, next[1] = INF; for (int j = 0; j < 2; j++) { next[j] = f(next[j], dp[j] + a[i], j); next[j] = f(next[j], dp[j] * a[i], j); next[j] = f(next[j], dp[j] - a[i], j); next[j] = f(next[j], dp[(j+1)%2] + a[i], j); next[j] = f(next[j], dp[(j+1)%2] * a[i], j); next[j] = f(next[j], dp[(j+1)%2] - a[i], j); if (a[i] != 0) { next[j] = f(next[j], dp[j] % a[i], j); next[j] = f(next[j], dp[(j+1)%2] % a[i], j); } } dp = next; } cout << dp[0] << endl; return 0; }