#C10603. Maximum Pairwise Product Under Modulo
Maximum Pairwise Product Under Modulo
Maximum Pairwise Product Under Modulo
You are given an integer n and an array of n integers. Your task is to compute the maximum product of any two numbers in the array, and then output the result modulo \(10^9+7\). You should consider that the maximum product might come either from the two largest positive numbers or from the two smallest (most negative) numbers, because the product of two negative numbers is positive.
Note: If the size of the array is less than 2, output 0.
Input Format: The input is taken from stdin
and consists of two lines - the first line contains the integer n, and the second line contains n space-separated integers.
Output Format: The output, written to stdout
, is a single integer representing the maximum product modulo \(10^9+7\).
inputFormat
The input will consist of two lines:
- The first line contains an integer \(n\) (
n \ge 1
), representing the number of elements in the array. - The second line contains \(n\) space-separated integers.
outputFormat
Output a single integer to stdout
which is the maximum product of any two numbers in the array modulo \(10^9+7\). If there are less than 2 numbers in the array, output 0
.
5
1 2 3 4 5
20