from itertools import pairwise def accum_dp(xs: list, f, op, e, init: dict): dp = init.copy() for x in xs: pp = {} dp, pp = pp, dp for fm_key, fm_val in pp.items(): for to_key, to_val in f(fm_key, fm_val, x): dp[to_key] = op(dp.get(to_key, e), to_val) return dp def div(a, b): if (a < 0) ^ (b < 0): return -(-a // b) return a // b def f(k, v, x): # k : 計算結果 res = [k+x, k-x, k*x] if x != 0: # res.append(div(k, x)) res.append(k // x) yield min(res), True yield max(res), True INF = 1 << 62 N = int(input()) A = list(map(int, input().split())) init = {A[0]: True} dp = accum_dp(A[1:], f, max, -INF, init) ans = max(dp.keys()) print(ans)