#include <bits/stdc++.h>
using namespace std;
map<int, int> uniques;
int V[1024];
int P[1024];
int used[1024];
vector<int> occ[1024];
int X[100010];
int N;
bool is_lucky(int n) {
  if (n == 0) return false;
  while (n > 0) {
    int x = n % 10;
    if (x != 4 && x != 7) return false;
    n /= 10;
  }
  return true;
}
unsigned long long nc2(unsigned long long n) {
  if (n < 2) return 0;
  return (n * (n - 1)) / 2;
}
unsigned long long nc3(unsigned long long n) {
  if (n < 3) return 0;
  unsigned long long ans = n * (n - 1) / 2;
  ans *= (n - 2);
  ans /= 3;
  return ans;
}
unsigned long long nc4(unsigned long long n) {
  if (n < 4) return 0;
  unsigned long long ans = n * (n - 1) / 2;
  ans *= (n - 2);
  ans /= 3;
  ans *= (n - 3);
  ans /= 4;
  return ans;
}
unsigned long long next_stuff(int b, bool u, int first_seen) {
  unsigned long long ans = 0;
  unsigned long long inner = P[b + 1] - P[b] - 1;
  assert(inner >= 0);
  ans += nc3(inner) + 2 * nc2(inner) + inner;
  if (!u) {
    unsigned long long y = first_seen - P[b + 1];
    assert(y >= 0);
    if (false) cout << first_seen << endl;
    if (false) cout << "ending y: " << y << endl;
    ans += (nc2(inner) + 2 * inner + 1) * y;
  }
  if (false) cout << "next_stuff: " << ans << endl;
  return ans;
}
int main() {
  cin >> N;
  int U = 0;
  int L = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (is_lucky(x)) {
      int u = uniques[x];
      if (u == 0) {
        ++U;
        u = uniques[x] = U;
      }
      ++L;
      assert(L < 1024);
      V[L] = u;
      P[L] = i;
      occ[V[L]].push_back(P[L]);
    }
  }
  V[0] = 0;
  P[0] = -1;
  V[L + 1] = 0;
  P[L + 1] = N;
  for (int v = 1; v <= U; v++) {
    occ[v].push_back(N);
  }
  if (false) cout << endl;
  unsigned long long ans = 0;
  for (int b = 1; b <= L; b++) {
    memset(used, false, sizeof(used[0]) * (U + 2));
    used[0] = true;
    set<int> C;
    unsigned long long intervals = 0;
    int vb = V[b];
    used[vb] = true;
    {
      for (unsigned int o = 0; o < occ[vb].size(); o++) {
        int p = occ[vb][o];
        if (p <= P[b]) continue;
        if (p == P[b + 1]) continue;
        C.insert(p);
      }
      C.insert(P[b + 1]);
      set<int>::iterator i = C.begin();
      set<int>::iterator j = C.begin();
      for (j++; j != C.end(); i++, j++) {
        unsigned long long dist = (*j) - (*i) - 1;
        assert(dist >= 0);
        intervals += nc2(dist) + dist;
      }
      assert(intervals >= 0);
      unsigned long long starts = ((unsigned long long)P[b] - P[b - 1]);
      unsigned long long ends = ((unsigned long long)P[b + 1] - P[b]);
      assert(starts >= 0);
      assert(ends >= 0);
      ans += starts * ends * intervals;
      int x = (*C.upper_bound(P[b + 1]));
      ans += starts * next_stuff(b, used[V[b + 1]], x);
    }
    for (int a = b - 1; a >= 1; a--) {
      int va = V[a];
      for (unsigned int o = 0; o < occ[va].size(); o++) {
        if (used[va]) break;
        int p = occ[va][o];
        if (p == P[b + 1]) continue;
        if (p <= P[b]) continue;
        if (p == P[L + 1]) continue;
        assert(p == P[L + 1] || C.find(p) == C.end());
        C.insert(p);
        set<int>::iterator Lp = C.lower_bound(p);
        Lp--;
        int L = (*Lp);
        int R = (*C.upper_bound(p));
        if (p < L || p > R) continue;
        unsigned long long x = p - L;
        unsigned long long y = R - p;
        if (false) cout << p << " " << x << " " << y << endl;
        assert(x >= 0 && y >= 0);
        intervals -= x * y;
        C.insert(p);
      }
      used[V[a]] = true;
      unsigned long long starts = ((unsigned long long)P[a] - P[a - 1]);
      unsigned long long ends = ((unsigned long long)P[b + 1] - P[b]);
      assert(starts >= 0);
      assert(ends >= 0);
      ans += starts * ends * intervals;
      int val = (*C.upper_bound(P[b + 1]));
      ans += starts * next_stuff(b, used[V[b + 1]], val);
    }
  }
  for (int a = 1; a <= L + 1; a++) {
    unsigned long long x = P[a] - P[a - 1] - 1;
    unsigned long long y = P[L + 1] - P[a];
    if (false) cout << a << " " << x << " " << y << endl;
    ans += nc4(x) + 2 * nc3(x) + nc2(x);
    if (false) cout << ans << endl;
    ans += (nc2(x) + x) * (nc2(y) + y);
    if (false) cout << ans << endl;
    ans += (nc3(x) + nc2(x)) * y;
    if (false) cout << ans << endl;
  }
  cout << ans << endl;
}
