n = int(input()) A = list(map(int, input().split())) INF = 10**18 DP = [[0 for _ in range(4)] for _ in range(n + 1)] for i in range(n): a = A[i] for j in range(4): if DP[i][j] == -INF: continue DP[i + 1][0] = max(DP[i + 1][0], DP[i][j] + a) DP[i + 1][1] = max(DP[i + 1][1], DP[i][j] - a) DP[i + 1][2] = max(DP[i + 1][2], DP[i][j] * a) if a == 0: DP[i + 1][3] = -INF else: DP[i + 1][3] = max(DP[i + 1][3], DP[i][j] // a) print(max(DP[n]))