Triplets Divisible by 5
By Kay Akashi
Time: 1000 ms
Memory: 256000 kB
Loading account information...
Loading account information...
Problem Statement
You are given a list of non-negative numbers, a1,a2,a3,...,an. You want to choose i, j, k (1≤i<j<k≤n) in such a way that ai+aj+ak is divisible by 5. How many possible pairs of (i,j,k) are there in total?
In the first example, (1,2,3) is the only set of indices that satisfies the condition. Hence the answer is 1.
In the second example, (1,2,3), (1,2,4), (1,3,5), and (1,4,5) satisfy the condition. Hence the answer is 4.
Constraints
3≤n≤105,
0≤ai≤105 (1≤i≤n).
Subtask 1 (20%)
3≤n<100.
Subtask 2 (80%)
100≤n≤105.
Input
The first line contains one number n, the length of a.
Following is the sequence of n numbers, separated by single spaces, that compose a.
Output
Output the answer.
Examples