#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], nxt[N];
long long ans, d;
vector<long long> l;
set<long long> s;
int chk(int x) {
  if (x == 0) return 1;
  if (x % 10 != 4 && x % 10 != 7) return 0;
  return chk(x / 10);
}
int main() {
  scanf("%d", &n);
  ans = 1ull * n * (n - 1) * (n + 1) / 6 * (n + 2) / 4;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (chk(a[i])) l.push_back(i);
  }
  l.push_back(n);
  for (int i = 0; i < (int)l.size(); i++) {
    nxt[i] = -1;
    for (int j = 0; j < i; j++)
      if (a[l[j]] == a[l[i]]) nxt[i] = j;
  }
  for (int i = 0; i < (int)l.size() - 2; i++) {
    long long d = 0;
    s.clear();
    s.insert(-1);
    for (int j = i + 1; j < (int)l.size() - 1; j++) {
      if (nxt[j] <= i)
        for (int k = nxt[j]; k >= 0; k = nxt[k]) {
          auto p = s.insert(l[k]).first, q = p;
          p--;
          q++;
          if (q == s.end())
            d += (l[k] - *p) * ((l[i + 1] - l[i]) * (l[i + 1] - l[i] + 1) / 2 +
                                (l[i + 1] - l[i]) * (l[i] - l[k]));
          else
            d += (l[k] - *p) * (*q - l[k]) * (l[i + 1] - l[i]);
        }
      ans -= d * (l[j + 1] - l[j]);
    }
  }
  printf("%lld\n", ans);
}
