Problem

7 /21


Voskhod satellite

Problem

On Voskhod satellite installed a device designed to measure solar activity. Every minute the device transmits a non-negative integer number – the amount of solar radiation energy received in the last minute, measured in arbitrary units. The time during which the transmission takes place can be neglected. 

It is necessary to find in the given series of readings of the device the maximum even product of two readings, between the moments of transmission of which at least 9 minutes have passed. If such a product cannot be obtained, the answer is considered equal to –1. The amount of energy received by the device per minute does not exceed 1000 conventional units. The total number of instrument readings in a series does not exceed 10,000.

Problem A (2 points). 

Write a program in any programming language to solve the given problem, in which the input data will be stored in an array, after which all possible pairs of elements will be checked.

Problem B (4 points). 

Write a program to solve the problem that is both time and memory efficient (or at least one of those characteristics). 

Input
The first line specifies the number N – the total number of instrument readings. It is guaranteed that \(N > 9\). Each of the following N lines specifies one non-negative integer – another reading of the instrument.
 

Imprint
The program should output one number – the work described in the condition.



Examples
# Input Output
1
11
12
45
5
3
17
23
21
20
19
12
26
1170