#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int N = 100000 + 1000;
int a[N];
int bit[20][20][20];
int main(){
int n;
//cout << 1996000 % 7 << " " << 127 % 7 << endl;
while(cin >> n){
memset(bit,0,sizeof(bit));
for(int i = 0; i < n; i++)cin>>a[i];
long long ans = 0;
for(int i = 0; i < n; i++){
long long tmp = 1;
long long tt = 1LL * tmp * a[i];
int t1 = a[i]; int c = 0;
while(t1){
t1 /= 10;
c++;
}
//cout << "t1:" << ans <<endl;
for(int j = 0; j < 10; j++)
ans += bit[j][c][(7 - tt % 7) % 7];
for(int j = 0; j < 10; j++){
tt = a[i] * tmp;
ans += bit[j][0][(7 - tt % 7) % 7];
tmp *= 10;
}
tmp = 1;
for(int j = 0; j < 10; j++){
tt = a[i] * tmp;
//ans += bit[j][0][(7 - tt % 7) % 7];
bit[c][j][tt % 7]++;
tmp *= 10;
}
//cout << "t2:" << ans << " " << bit[3][0][1] <<endl;
}
cout << ans << endl;
}
return 0;
}