#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
int a[maxn];
bool isLucky(int x) {
  while (x > 0) {
    int last = x % 10;
    if (last != 4 && last != 7) return false;
    x /= 10;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> v, prev;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (isLucky(a[i])) {
      v.push_back(i);
      prev.push_back(-1);
    }
  }
  int m = (int)(v).size();
  v.push_back(n);
  for (int i = 0; i < m; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (a[v[i]] == a[v[j]]) {
        prev[i] = j;
        break;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < m; i++) {
    set<int> lucky;
    set<pair<int, int> > st;
    st.insert(make_pair(0, v[i]));
    long long cur = v[i] * 1ULL * (v[i] + 1) / 2;
    for (int j = i; j < m; j++) {
      if (lucky.count(a[v[j]]) == 0) {
        lucky.insert(a[v[j]]);
        for (int k = prev[j]; k >= 0; k = prev[k]) {
          assert(!st.empty());
          set<pair<int, int> >::iterator it =
              st.lower_bound(make_pair(v[k], n + 1));
          --it;
          int lf = (*it).first;
          int rg = (*it).second;
          assert(lf <= v[k] && v[k] < rg);
          int len = rg - lf;
          cur -= (len + 1) * 1ULL * len / 2;
          st.erase(it);
          if (lf != v[k]) {
            st.insert(make_pair(lf, v[k]));
            cur += (v[k] - lf) * 1ULL * (v[k] - lf + 1) / 2;
          }
          if (v[k] + 1 != rg) {
            st.insert(make_pair(v[k] + 1, rg));
            cur += (rg - v[k]) * 1ULL * (rg - v[k] - 1) / 2;
          }
        }
      }
      if (st.empty()) break;
      long long after = v[j + 1] - v[j];
      res += cur * after;
      if (i > 0) {
        set<pair<int, int> >::iterator it = st.end();
        --it;
        int lf = (*it).first;
        int rg = (*it).second;
        if (rg != v[i]) continue;
        int len1 = v[i] - v[i - 1] - 1;
        int len2 = v[i - 1] - lf + 1;
        res += len1 * 1ULL * len2 * (len2 + 1) / 2 * after;
        res += len2 * 1ULL * len1 * (len1 - 1) / 2 * after;
        res += (len1 + 1) * 1ULL * len1 * (len1 - 1) / 2 / 3 * after;
        res += (cur - (rg - lf) * 1ULL * (rg - lf + 1) / 2) * len1 * after;
      } else {
        res += (v[i] + 1) * 1ULL * (v[i] - 1) * v[i] / 2 / 3 * after;
      }
    }
  }
  int last = n;
  for (int i = n - 1; i > 0; i--) {
    if (isLucky(a[i])) {
      last = i;
      continue;
    }
    res += i * 1ULL * (i + 1) / 2 * (last - i);
  }
  cout << res << endl;
  return 0;
}
