#include #include void push(int a, int *top, int stack[]) { stack[*top] = a; ++*top; } int compare(const void *x, const void *y) { return *(int*)y - *(int*)x; } int main(void) { int N, a, top = 0, stack[16], ans = 0, tmp = 1, i; scanf("%d", &N); for (i = 0; i < N; ++i) { scanf("%d", &a); if (a < -1) push(a, &top, stack); else if (a + ans > a * ans) ans += a; else ans *= a; } qsort(stack, top, sizeof(int), compare); if (top % 2) { for (i = 0; i < top - 1; ++i) tmp *= stack[i]; } else { for (i = 0; i < top; ++i) tmp *= stack[i]; } if (ans > 1) ans *= tmp; else ans += tmp; printf("%d", ans); return 0; }