Problem

8 /23


Sum of numbers in pairs

Problem

The input of the program is a sequence of natural numbers A. The number of elements in the sequence is greater than 7. It is necessary to determine the number of such pairs of elements of the sequence Ai and Aj ,\( j - i > 4\), where i and j – the numbers of the elements of the sequence, where the sum of the numbers in each of these pairs is a multiple of 3.  

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


Input
In each line of the input  one natural number is written, not exceeding 30000.  Numeric input ends in zero.

Imprint
As an answer, the program should output a single number – the number of pairs of elements that satisfy the condition.
 
 
Examples
# Input Output
1
10
12
81
2
7
33
99
21
11
121
10
0
6