#pragma GCC optimize("O3")
#pragma GCC target("popcnt,lzcnt,bmi,bmi2,abm")
#include <iostream>
#include <vector>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
// #include <limits.h>
// #include<bits/stdc++.h>
using namespace std;

// template < typename A, typename B > ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
// template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// void dbg_out() { cerr << '\n'; }
// template<typename Head, typename... Tail>
// void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
// #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) 

#define PI 3.141592653589793116
// PI = acos(-1)
#define ll long long
#define ld long double
#define fi first
#define se second
#define nl '\n'
#define all(x) x.begin(), x.end()
#define no cout << "NO" << nl
#define yes cout << "YES" << nl
#define siu ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(x,y) memset(x,y,sizeof(x));
#define pb push_back

const ll mod = 1e9 + 7;
const int inf = 1e9;
const int lim = 1e6 + 5;
const int base = 311;
const ll gh = 1005;

void file()
{
    siu
//    #ifdef ONLINE_JUDGE
//    freopen("tongnn.INP","r",STdin);
//    freopen("tongnn.OUT","w",STdout);
//    #endif // ONLINE_JUDGE
    #ifndef ONLINE_JUDGE
    freopen("ahihi.INP","r",stdin);
    freopen("ahihi.OUT","w",stdout);
    #endif // ONLINE_JUDGE
}

ll n,m,i,j,k,t,kq=0;
ll x,y,z,maxa=-1e9,mina=1e9,l=1,r=1e9;
ll a[lim],f[lim];

void solve()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]%=5;
        if(a[i]==0) a[i]=5; 
        f[a[i]]++;
    }
    kq+=(f[1]*(f[1]-1)/2)*f[3];
    // cout<<kq<<nl;
    kq+=f[1]*(f[2]*(f[2]-1)/2);
    // cout<<kq<<nl;
    // kq+=f[1]*f[2]*f[3];
    // cout<<kq<<nl;
    kq+=f[1]*f[4]*f[5];
    // cout<<kq<<nl;
    kq+=f[2]*f[3]*f[5];
    // cout<<kq<<nl;
    kq+=f[2]*(f[4]*(f[4]-1)/2);
    // cout<<kq<<nl;
    kq+=f[4]*(f[3]*(f[3]-1)/2);
    // cout<<kq<<nl;
    kq+=(f[5]*(f[5]-1)*(f[5]-2))/6;
    cout<<kq;
}

int main()
{
    siu;
    // file();
    int casemiro=1;
    // cin>>casemiro;
    while(casemiro--)
    {
        solve();
    }
}