#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
const int MaxM = 1005;
map<int, list<int> > mp;
long long DP[MaxN][5];
int id[MaxM], idn;
int a[MaxN];
int main() {
  int N;
  DP[0][0] = 1;
  for (int i = 1; i < MaxN; i++) {
    for (int j = 0; j <= 4 && j <= i; j++) {
      if (i == j || j == 0)
        DP[i][j] = 1;
      else
        DP[i][j] = DP[i - 1][j - 1] + DP[i - 1][j];
    }
  }
  while (scanf("%d", &N) == 1) {
    idn = 0;
    mp.clear();
    for (int i = 0; i < N; i++) {
      scanf("%d", &a[i]);
      try {
        int x = a[i];
        while (x) {
          int y = x % 10;
          if (y != 4 && y != 7) throw 0;
          x /= 10;
        }
        mp[a[i]].push_back(i);
        id[idn++] = i;
      } catch (...) {
      }
    }
    long long ret = DP[N + 2][4];
    idn--;
    for (int i = 0; i < idn; i++) {
      set<int> ax, vst;
      ax.insert(id[i]);
      ax.insert(N);
      long long s = 0;
      for (int j = i; j >= 0; j--) {
        if (vst.find(a[id[j]]) == vst.end()) {
          int x = a[id[j]];
          vst.insert(x);
          list<int>& lst = mp[x];
          for (list<int>::iterator it = lst.begin(); it != lst.end(); it++) {
            if (*it > id[i]) {
              set<int>::iterator cur, L, R;
              cur = L = R = ax.insert(*it).first;
              L--;
              R++;
              if (L == ax.begin()) {
                s += (long long)(*R - *cur) *
                     ((long long)(id[i + 1] - id[i] + 1) * (id[i + 1] - id[i]) /
                          2 +
                      (id[i + 1] - id[i]) * (*cur - id[i + 1]));
              } else {
                s += (long long)(id[i + 1] - id[i]) * (*cur - *L) * (*R - *cur);
              }
            }
          }
        }
        if (j == 0)
          ret -= s * (id[j] + 1);
        else
          ret -= s * (id[j] - id[j - 1]);
      }
    }
    printf("%I64d\n", ret);
  }
  return 0;
}
