#include <bits/stdc++.h>
using namespace std;
const int N0 = 100010;
const int N = 5010;
int a[N0], g[N][N], ct0, ct, cnt, h[N0], lal[N0];
long long f[N0];
pair<int, int> t[N0];
bool vis[N0];
map<int, int> mm;
set<pair<int, int> > s;
vector<int> t0[N0];
long long get0_(int l, int r) {
  if (l > r) return 0;
  int len = (r - l + 1);
  return 1ll * len * (len - 1) / 2 + len;
}
long long get_(int l, int r) {
  if (l > r) return 0;
  int len = (r - l + 1);
  long long ret = 1ll * len * (len - 1) / 2 + len;
  int tmp = lal[l];
  if (l == tmp) return ret - (f[r] - f[l - 1]);
  return ret - (f[r] - f[tmp] + get0_(l, tmp - 1));
}
void ins(pair<int, int> tmp) { s.insert(tmp); }
void era(pair<int, int> tmp) { s.erase(tmp); }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int tmp = x;
    bool flag = true;
    while (tmp) {
      if (tmp % 10 != 4 && tmp % 10 != 7) flag = false;
      tmp /= 10;
    }
    if (flag) {
      if (!mm[x]) mm[x] = ++cnt;
      a[i] = mm[x], t[++ct] = make_pair(i, a[i]);
      t0[a[i]].push_back(i);
    }
  }
  int la = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!a[i]) {
      f[i] = f[la] + get0_(la + 1, i);
      ans += 1ll * (i - la) * get0_(i + 1, n);
    } else
      la = i, f[i] = f[i - 1];
  }
  f[n + 1] = f[n];
  la = n + 1;
  for (int i = n; i; i--) {
    if (!a[i]) {
      ans -= 1ll * (la - i) * f[i - 1];
      ans += 1ll * (la - i) * get0_(1, i - 1);
    } else
      la = i;
    lal[i] = la;
  }
  t[ct + 1] = make_pair(n + 1, 0);
  for (int i = 1; i <= ct; i++) {
    long long sum = 0;
    s.clear();
    ins(make_pair(t[i].first, n));
    ins(make_pair(n + 1, n + 1));
    sum += get_(t[i].first, n);
    for (int j = 1; j <= cnt; j++) vis[j] = false;
    for (int j = i; j <= ct; j++) {
      set<pair<int, int> >::iterator it =
          s.upper_bound(make_pair(t[j + 1].first - 1, 1e9));
      if (it != s.begin()) {
        it--;
        pair<int, int> tmp = *it;
        era(tmp);
        sum -= get_(tmp.first, tmp.second);
        if (t[j + 1].first <= tmp.second)
          sum += get_(t[j + 1].first, tmp.second),
              ins(make_pair(t[j + 1].first, tmp.second));
      }
      int c = t[j].second;
      if (!vis[c]) {
        vis[c] = true;
        for (int k = 0; k < t0[c].size(); k++)
          if (t0[c][k] > t[j].first) {
            set<pair<int, int> >::iterator it =
                s.upper_bound(make_pair(t0[c][k], 1e9));
            if (it != s.begin()) {
              it--;
              pair<int, int> tmp = *it;
              era(tmp);
              sum -= get_(tmp.first, tmp.second);
              if (tmp.first <= t0[c][k] - 1)
                sum += get_(tmp.first, t0[c][k] - 1),
                    ins(make_pair(tmp.first, t0[c][k] - 1));
              if (t0[c][k] + 1 <= tmp.second)
                sum += get_(t0[c][k] + 1, tmp.second),
                    ins(make_pair(t0[c][k] + 1, tmp.second));
            }
          }
      }
      long long qaq1 = 0, qaq2 = 0;
      ans +=
          sum * (t[i].first - t[i - 1].first) * (t[j + 1].first - t[j].first);
      if (j < ct && (*s.begin()).first == t[j + 1].first) {
        long long len = t[j + 1].first - t[j].first;
        ans += len * (len - 1) / 2 * (t[i].first - t[i - 1].first) *
               ((*s.begin()).second - (*s.begin()).first + 1);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
