#include <bits/stdc++.h>
using namespace std;
bool check(int x) {
  for (; x; x /= 10)
    if (x % 10 != 4 && x % 10 != 7) return 0;
  return 1;
}
const int N = 100005;
int a[N], n;
vector<int> pos;
int nxt[N];
int main() {
  scanf("%d", &n);
  pos.push_back(0);
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%d", &a[i]);
    if (check(a[i])) pos.push_back(i);
  }
  long long ans = 1ull * (n + 2) * (n + 1) / 2 * n / 3 * (n - 1) / 4;
  for (int i = (int)(1); i <= (int)(pos.size() - 1); i++) {
    nxt[i] = pos.size();
    for (int j = (int)(pos.size() - 1); j >= (int)(i + 1); j--)
      if (a[pos[i]] == a[pos[j]]) nxt[i] = j;
  }
  for (int i = (int)(1); i <= (int)(pos.size() - 2); i++) {
    set<int> S;
    S.insert(pos[i]);
    S.insert(n + 1);
    long long cur = 0, R = pos[i + 1] - pos[i];
    for (int j = (int)(i); j >= (int)(1); j--) {
      if (nxt[j] > i)
        for (int k = nxt[j]; k < pos.size(); k = nxt[k]) {
          set<int>::iterator pre, nxt;
          pre = nxt = S.insert(pos[k]).first;
          --pre;
          ++nxt;
          if (pre == S.begin())
            cur += 1ll * (*nxt - pos[k]) *
                   (1ll * R * (R + 1) / 2 + 1ll * (pos[k] - pos[i + 1]) * R);
          else
            cur += 1ll * (*nxt - pos[k]) * (pos[k] - *pre) * R;
        }
      ans -= cur * (pos[j] - pos[j - 1]);
    }
  }
  printf("%lld\n", ans);
}
