Điểm:
1400
Thời gian:
1.0s
Bộ nhớ:
256M
Input:
bàn phím
Output:
màn hình
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
Bình luận
Bay hơn 20 đấm vì 2 test 😢
3 bình luận nữa