#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010, maxm = 1010;
int n, m;
int a[maxn], b[maxn];
int pre[maxn], suc[maxn];
long long C[maxn], Sc[maxn];
vector<int> A[maxm];
set<pair<int, int> > S;
bool v[maxm];
long long s, ans;
void init() {
  int w, t, i, u;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &u);
    for (w = u; w; w /= 10)
      if (t = w % 10, t != 4 && t != 7) break;
    if (w) u = 0;
    a[i] = b[i] = u;
  }
  sort(b, b + n + 1);
  m = unique(b, b + n + 1) - b;
  for (i = 0; i < n; ++i) {
    a[i] = lower_bound(b, b + m, a[i]) - b;
    A[a[i]].push_back(i);
  }
  for (u = n, i = n - 1; i; --i)
    if (suc[i] = u, a[i]) u = i;
  for (u = -1, i = 0; i < n; ++i)
    if (pre[i] = u, a[i]) u = i;
  for (i = 1; i <= n; ++i)
    C[i] = (long long)i * (i + 1) / 2, Sc[i] = C[i] + Sc[i - 1];
}
void del(int x) {
  set<pair<int, int> >::iterator it = S.upper_bound(pair<int, int>(x + 1, 0));
  it--;
  int l = it->first, r = it->second;
  s -= C[r - l + 1];
  S.erase(it);
  if (l != x) S.insert(pair<int, int>(l, x - 1)), s += C[x - l];
  if (x != r) S.insert(pair<int, int>(x + 1, r)), s += C[r - x];
}
void sol() {
  int l, r, i, len;
  long long ts;
  for (l = 1; l < n; ++l)
    if (a[l]) {
      S.clear();
      S.insert(pair<int, int>(0, l - 1)), s = C[l];
      memset(v, 0, sizeof(v));
      for (r = l; r < n; r = suc[r]) {
        if (!v[a[r]] && a[r]) {
          v[a[r]] = 1;
          vector<int> &V = A[a[r]];
          for (i = 0; i < V.size(); ++i)
            if (V[i] < l)
              del(V[i]);
            else
              break;
        }
        if (pre[l] + 1 != l) {
          len = S.rbegin()->second - S.rbegin()->first + 1;
          ts = s + (s - C[len]) * (l - pre[l] - 1) + Sc[len - 1] -
               Sc[len - l + pre[l]];
        } else
          ts = s;
        ans += ts * (suc[r] - r);
      }
    }
  for (i = 1; i < n; ++i)
    if (!a[i]) ans += C[i] * (suc[i] - i);
  printf("%I64d", ans);
}
int main() {
  init();
  sol();
  return 0;
}
