#include <bits/stdc++.h>
using namespace std;
inline bool happy(int x) {
  while (x) {
    int cnt = x % 10;
    if (cnt != 4 && cnt != 7) return 0;
    x /= 10;
  }
  return 1;
}
int main() {
  int n;
  while (scanf("%d", &n) >= 1) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    vector<int> b;
    vector<bool> h;
    for (int i = 0; i < n;) {
      int cnt = 0;
      while (i < n && !happy(a[i])) cnt++, i++;
      if (cnt) {
        b.push_back(cnt);
        h.push_back(0);
      }
      if (i < n) {
        b.push_back(a[i]);
        h.push_back(1);
        i++;
      }
    }
    int m = b.size();
    vector<int> pr(m + 2, 0);
    for (int i = 1; i <= m; i++) pr[i] = pr[i - 1] + (h[i - 1] ? 1 : b[i - 1]);
    pr[m + 1] = pr[m];
    vector<int> next(m, m);
    for (int i = m - 1; i >= 0; i--) {
      if (!h[i]) continue;
      for (int j = i + 1; j < m; j++)
        if (h[j] && b[i] == b[j]) {
          next[i] = j;
          break;
        }
    }
    long long ans = 0;
    set<int> s;
    vector<bool> taken;
    for (int l = 0; l < m; l++) {
      taken = vector<bool>(m, 0);
      s.clear();
      s.insert(m);
      s.insert(l - 1);
      long long now = ((long long)(pr[m] - pr[l])) * (pr[m] - pr[l] + 1) / 2;
      long long ansp = 0;
      for (int r = l; r < m; r++) {
        if (!taken[r]) {
          for (int v = r; v < m; v = next[v]) {
            assert(!taken[v]);
            taken[v] = 1;
            set<int>::iterator iter = s.lower_bound(v);
            assert(iter != s.begin());
            int right = (*iter);
            iter--;
            int left = (*iter);
            now -= ((long long)(pr[right] - pr[left + 1])) *
                   (pr[right] - pr[left + 1] + 1) / 2;
            now += ((long long)(pr[right] - pr[v + 1])) *
                   (pr[right] - pr[v + 1] + 1) / 2;
            now += ((long long)(pr[v] - pr[left + 1])) *
                   (pr[v] - pr[left + 1] + 1) / 2;
            s.insert(v);
          }
        }
        assert(now >= 0ll);
        if (l == r)
          ans += now * (h[l] ? 1 : (((long long)b[l]) * (b[l] + 1) / 2));
        else
          ansp += now * (h[r] ? 1 : b[r]);
        if (!h[r]) {
          int number = b[r];
          set<int>::iterator iter = s.lower_bound(r + 1);
          int right = (*iter);
          int over = pr[right] - pr[r + 1];
          if (l == r) {
            long long cnt =
                ((((long long)number) * (number - 1) * (number - 2)) / 6);
            if (cnt & 1)
              cnt *= ((number - 3) / 4);
            else {
              if (cnt & 2) {
                cnt /= 2;
                cnt *= (number - 3) / 2;
              } else
                cnt /= 4, cnt *= number - 3;
            }
            ans += cnt;
            cnt = ((((long long)number) * (number - 1) * (number - 2)) / 6);
            ans += cnt * (over + 2);
            ans += (((long long)number) * (number - 1) / 2) * (1 + over);
          } else {
            ansp += (((long long)number) * (number - 1) * (number - 2)) / 6;
            ansp += (((long long)number) * (number - 1) / 2);
            ansp += (((long long)number) * (number - 1) / 2) * over;
          }
        }
      }
      ans += ansp * (h[l] ? 1 : b[l]);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
