MOZSAM - Sharmeen And Multiplication
Sharmeen is a little girl who recently learned about multiplication. If she hears a number she multiplies it with the previous number. At first the multiplied result is 1. After that if anyone tells her a number she just multiplies it with the previous multiplied result. For example, at the beginning if someone tell 5, then she multiplies it with 1 and her multiplied result becomes 1*5 = 5. After that if anyone tells -2, she multiplies it with 5 and her result becomes 5 * (-2) = -10. This process continues. After doing this for several days Sharmeen thought how to get the maximum possible multiplied value? Then she realized that sometimes it is possible to get the maximum multiplied value if she skip some numbers to multiply and sometimes multiplying all the numbers is optimal to get the maximum multiplied value.
So, you have the authority to skip some numbers. For example, in the above you can skip the second number, then the result will be 5, which is the maximum possible multiplied value in that case. Can you find an optimal way of selecting numbers in which multiplying the selected numbers will give you the maximum multiplied value of all possible way of selecting? You can skip all the numbers, if you do that then the result will be 1. You don’t have to print the way of selecting the numbers, just print the maximum multiplied value of the optimal way.
Input
You will be given an integer number n (0 <= n <= 9) which indicates how many numbers Sharmeen will hear. Then there will be n numbers x (-10 <= x <= 10).
Output
Print the maximum possible multiplied value in a line. Don’t forget to print new line after your answer.
See the sample input output for better understanding.
Example
Input: 5 -3 2 -2 1 -3 Output: 18
Added by: | Mozahid |
Date: | 2019-05-26 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |