ICPC Central B

View as PDF



Problem types
Points: 1400 Time limit: 1.0s Memory limit: 256M Input: stdin Output: stdout

Given array \(A\) consisting of \(n\) integers \(a_i\). Tuan wants to remove at most 1 element
in array \(A\) so that the product of all remaining elements in that array is the largest.
Please help Tuan do it!
You task is to calculate the product of all remaining elements in that array after
removed at most 1 element.

Input

  • The first line contains a positive integer \(n (2 \le n \le 1000)\).
  • Next line contains n integers ai separated by a space \(( -10 ^9 \le a_i \le 10^ 9 )\).

Output

  • Print the result of the problem. Since it may be too big, print it after taking modulo
    \(10^9+7\).

Example

Test 1

Input
4
4 2 3 5
Output
120
Note
  • Without dropping any elements, the product of 4 elements is 4 × 2 × 3 × 5 = 120.

Test 2

Input
5
-1 -2 -4 1 2
Output
16
Note
  • Remove -1, the product of the remaining 4 elements is -2 × (-4) × 1 × 2 = 16

Comments

There are no comments at the moment.