#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
int a[maxn], nxt[maxn], n;
vector<int> pos;
set<int> s;
long long ans;
bool lucky(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int(i) = (0); (i) <= ((n)-1); (i)++) scanf("%d", a + i);
  pos.push_back(-1);
  for (int(i) = (0); (i) <= ((n)-1); (i)++)
    if (lucky(a[i])) pos.push_back(i);
  for (int(i) = (1); (i) <= (int(pos.size()) - 1); (i)++) {
    nxt[i] = pos.size();
    for (int(j) = (i + 1); (j) <= (int(pos.size()) - 1); (j)++)
      if (a[pos[j]] == a[pos[i]]) {
        nxt[i] = j;
        break;
      }
  }
  ans = (unsigned long long)(n + 2) * (n + 1) / 2 * n / 3 * (n - 1) / 4;
  for (int(i) = (1); (i) <= (int(pos.size()) - 1); (i)++) {
    s.clear();
    s.insert(pos[i]);
    s.insert(n);
    long long now = 0, seg = pos[i + 1] - pos[i];
    for (int(j) = (i); (j) >= (1); (j)--) {
      if (nxt[j] > i)
        for (int k = nxt[j]; k < pos.size(); k = nxt[k]) {
          decltype(s.begin()) pre, nex;
          pre = nex = s.insert(pos[k]).first;
          pre--, nex++;
          if (pre == s.begin())
            now += (seg * (seg + 1) / 2 + seg * (pos[k] - pos[i + 1])) *
                   (*nex - pos[k]);
          else
            now += seg * (*nex - pos[k]) * (pos[k] - *pre);
        }
      ans -= now * (pos[j] - pos[j - 1]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
