#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int a[MaxN], n, m;
long long C[MaxN][5];
vector<int> id;
set<int> b, vst;
map<int, vector<int> > mp;
bool Lucky(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return 0;
    x /= 10;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (Lucky(a[i])) {
      id.push_back(i);
      mp[a[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n + 2; i++) {
    C[i][0] = 1;
    if (i <= 4) C[i][i] = 1;
    for (int j = 1; j <= min(4, i - 1); j++)
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  long long ret = C[n + 2][4];
  m = id.size();
  for (int i = 0; i < m - 1; i++) {
    b.clear();
    vst.clear();
    b.insert(id[i]);
    b.insert(n);
    long long sum = 0;
    for (int j = i; j >= 0; j--) {
      if (vst.find(a[id[j]]) == vst.end()) {
        int x = a[id[j]];
        vst.insert(x);
        int N = mp[x].size();
        for (int k = 0; k < N; k++)
          if (mp[x][k] > id[i]) {
            b.insert(mp[x][k]);
            set<int>::iterator it = b.find(mp[x][k]), L, R;
            L = R = it;
            L--;
            R++;
            if (L == b.begin()) {
              sum += (long long)(*R - *it) *
                     ((long long)(id[i + 1] - id[i] + 1) * (id[i + 1] - id[i]) /
                          2 +
                      (id[i + 1] - id[i]) * (*it - id[i + 1]));
            } else {
              sum += (long long)(id[i + 1] - id[i]) * (*it - *L) * (*R - *it);
            }
          }
      }
      if (j == 0)
        ret -= sum * (id[j] + 1);
      else
        ret -= sum * (id[j] - id[j - 1]);
    }
  }
  printf("%I64d\n", ret);
  return 0;
}
