#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 1e5 + 5;
int N, M;
int A[MAXN];
int C[MAXN];
int nxt[MAXN];
bool IsLucky(int n) {
  while (n > 0) {
    if (n % 10 != 4 && n % 10 != 7) {
      return false;
    }
    n /= 10;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (IsLucky(A[i])) {
      C[++M] = i;
    }
  }
  C[M + 1] = N + 1;
  for (int i = 1; i <= M; i++) {
    nxt[i] = M + 1;
    for (int j = i + 1; j <= M; j++) {
      if (A[C[i]] == A[C[j]]) {
        nxt[i] = j;
        break;
      }
    }
  }
  lint ans = 1ull * (N + 2) * (N + 1) / 2 * N / 3 * (N - 1) / 4;
  for (int i = M; i >= 1; i--) {
    set<int> s;
    s.emplace(C[i]);
    s.emplace(N + 1);
    lint val = 0;
    for (int j = i; j >= 1; j--) {
      if (nxt[j] > i) {
        for (int k = nxt[j]; k <= M; k = nxt[k]) {
          s.emplace(C[k]);
          auto l = s.lower_bound(C[k]);
          auto r = l;
          l--, r++;
          if (*l == C[i]) {
            val += 1ll * (C[i + 1] - C[i]) * (C[i + 1] - C[i] + 1) / 2 *
                   (*r - C[k]);
            val += 1ll * (C[i + 1] - C[i]) * (C[k] - C[i + 1]) * (*r - C[k]);
          } else {
            val += 1ll * (C[i + 1] - C[i]) * (C[k] - *l) * (*r - C[k]);
          }
        }
      }
      ans -= 1ll * val * (C[j] - C[j - 1]);
    }
  }
  cout << ans << "\n";
  return 0;
}
