#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int i, j, k, N, M = 0, x, a[MAXN], b[MAXN], l[MAXN], c[MAXN];
map<int, vector<int> > L;
long long ans, sum, f[4];
void init() {
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    bool LUCKY = true;
    for (x = a[i]; x; x /= 10)
      if ((x % 10 != 4) && (x % 10 != 7)) LUCKY = false;
    if (LUCKY) l[M++] = i, L[a[i]].push_back(i);
  }
}
void work() {
  f[0] = N - 1, f[1] = N, f[2] = N + 1, f[3] = N + 2, j = 3, k = 1;
  for (i = 0; i < 4; i++) {
    while (j && f[i] % 2 == 0) f[i] /= 2, j--;
    while (k && f[i] % 3 == 0) f[i] /= 3, k--;
  }
  ans = f[0] * f[1] * f[2] * f[3];
  for (i = 0; i + 1 < M; i++) {
    set<int> t, q;
    sum = 0;
    t.insert(l[i]), t.insert(N);
    for (j = i; j >= 0; j--) {
      if (q.find(a[l[j]]) == q.end()) {
        x = a[l[j]], q.insert(a[l[j]]);
        for (k = 0; k < L[x].size(); k++)
          if (L[x][k] > l[i]) {
            set<int>::iterator po = t.insert(L[x][k]).first, pred = po,
                               succ = po;
            pred--, succ++;
            if (pred != t.begin())
              sum +=
                  (long long)(*po - *pred) * (*succ - *po) * (l[i + 1] - l[i]);
            else {
              sum += (long long)(*succ - *po) * (l[i + 1] - l[i] + 1) *
                     (l[i + 1] - l[i]) / 2;
              sum += (long long)(*succ - *po) * (*po - l[i + 1]) *
                     (l[i + 1] - l[i]);
            }
          }
      }
      if (j > 0)
        ans -= sum * (l[j] - l[j - 1]);
      else
        ans -= sum * (l[j] + 1);
    }
  }
  cout << ans << endl;
}
int main() {
  init();
  work();
  return 0;
}
