#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 9;
int n, a[N];
bool isLucky(int x) {
  while (x > 0) {
    int d = x % 10;
    if (d != 4 && d != 7) return false;
    x /= 10;
  }
  return true;
}
vector<int> pos;
int m, nxt[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  pos.emplace_back(-1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (isLucky(a[i])) pos.push_back(i);
  }
  m = pos.size();
  for (int i = 1; i < m; ++i) {
    nxt[i] = m;
    for (int j = i + 1; j < m; ++j)
      if (a[pos[i]] == a[pos[j]]) {
        nxt[i] = j;
        break;
      }
  }
  long long ans =
      (unsigned long long)(n + 2) * (n + 1) / 2 * n / 3 * (n - 1) / 4;
  for (int i = 1; i + 1 < m; ++i) {
    set<int> s;
    s.insert(pos[i]), s.insert(n);
    long long cur = 0;
    int rC = pos[i + 1] - pos[i];
    for (int j = i; j > 0; --j) {
      if (nxt[j] > i) {
        for (int k = nxt[j]; k < m; k = nxt[k]) {
          set<int>::iterator pre, nxt;
          pre = nxt = s.insert(pos[k]).first;
          --pre, ++nxt;
          if (pre == s.begin()) {
            cur += (long long)(*nxt - pos[k]) *
                   ((long long)rC * (rC + 1) / 2 +
                    (long long)(pos[k] - pos[i + 1]) * rC);
          } else {
            cur += (long long)(*nxt - pos[k]) * (pos[k] - *pre) * rC;
          }
        }
      }
      ans -= cur * (pos[j] - pos[j - 1]);
    }
  }
  cout << ans;
}
