Problem

18 /21


Satellite Voskhod -2

Problem

On Voskhod satellite installed a device designed to measure solar activity. Every minute the device transmits a natural number – the amount of solar radiation energy received in the last minute, measured in arbitrary units. The time during which the transfer occurs can be neglected. It is necessary to find in a given series the number of pairs of such readings of the device, the product of which is a multiple of 6 and between the moments of transmission of which at least three minutes have passed. 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, in any programming language, a program to solve the problem, in which the input data will be stored in an array, after which all possible pairs of elements are checked.

Problem B (4 points). Write a program to solve the given problem that is both time and memory efficient (or at least one of these characteristics) .


Input
The first line specifies the number N – the total number of instrument readings. It is guaranteed that \(N>3\). Each of the following N lines contains one natural number – another reading of the device.

 

 

Examples
# Input Output
1
5
6
2
4
1
3
3
In the given set of 5 numbers, there are three pairs (6, 3), (2, 3) and (6, 1) that satisfy the condition of the problem.