#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], li[100005];
map<int, vector<int> > mm;
bool isLucky(int num) {
  for (; num > 0; num /= 10)
    if ((num % 10) != 4 && (num % 10) != 7) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  long long nn[4] = {n - 1, n, n + 1, n + 2};
  for (int i = 4; i >= 2; i--)
    for (int j = 0; j < 4; j++)
      if (nn[j] % i == 0) {
        nn[j] /= i;
        break;
      }
  long long res = nn[0] * nn[1] * nn[2] * nn[3];
  m = 0;
  li[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (isLucky(a[i])) {
      mm[a[i]].push_back(i);
      li[++m] = i;
    }
  }
  set<int> visit, seg;
  set<int>::iterator itL, it, itR;
  for (int i = 1; i <= m; i++) {
    visit.clear();
    seg.clear();
    seg.insert(li[i]);
    seg.insert(n + 1);
    long long sum = 0;
    for (int j = i; j >= 1; j--) {
      if (visit.find(a[li[j]]) == visit.end()) {
        int num = a[li[j]];
        visit.insert(num);
        vector<int> que = mm[num];
        for (int k = 0, up_k = que.size(); k < up_k; k++)
          if (que[k] > li[i]) {
            it = seg.insert(que[k]).first;
            itL = itR = it;
            itL--;
            itR++;
            if (itL == seg.begin()) {
              sum += (long long)(li[i + 1] - li[i]) * (li[i + 1] - li[i] - 1) /
                     2 * (*itR - *it);
              sum += (long long)(li[i + 1] - li[i]) * (*it - li[i + 1] + 1) *
                     (*itR - *it);
            } else {
              sum +=
                  (long long)(li[i + 1] - li[i]) * (*it - *itL) * (*itR - *it);
            }
          }
      }
      res -= (long long)(li[j] - li[j - 1]) * sum;
    }
  }
  cout << res << endl;
}
