#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int MOD = 1e9 + 7;
int n, a[N], nxt[1007];
vector<int> pos;
bool isLucky(int x) {
  while (x > 0) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
long long tmp[5];
const long long x[] = {2, 3, 2, 2};
long long C(int n, int m) {
  for (int i = (0); i < (m); ++i) tmp[i] = n - i;
  int t = (m <= 3 ? m - 1 : m);
  for (int i = (0); i < (t); ++i)
    for (int j = (0); j < (m); ++j)
      if (tmp[j] % x[i] == 0) {
        tmp[j] /= x[i];
        break;
      }
  long long r = 1;
  for (int i = (0); i < (m); ++i) r *= tmp[i];
  return r;
}
set<int> S;
set<int>::iterator L, R;
int main() {
  scanf("%d", &n);
  pos.push_back(-1);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &a[i]);
    if (isLucky(a[i])) pos.push_back(i);
  }
  for (int i = (1); i < (((int)(pos).size())); ++i) {
    nxt[i] = ((int)(pos).size());
    for (int j = (i + 1); j < (((int)(pos).size())); ++j)
      if (a[pos[i]] == a[pos[j]]) {
        nxt[i] = j;
        break;
      }
  }
  long long ans = C(n, 4) + 2 * C(n, 3) + C(n, 2);
  for (int i = (1); i < (((int)(pos).size()) - 1); ++i) {
    S.clear();
    S.insert(pos[i]), S.insert(n);
    long long cnt = 0, ext = pos[i + 1] - pos[i];
    for (int j = i; j >= 1; --j) {
      if (nxt[j] > i) {
        for (int k = nxt[j]; k < ((int)(pos).size()); k = nxt[k]) {
          L = R = S.insert(pos[k]).first;
          --L, ++R;
          if (L == S.begin()) {
            cnt += (*R - pos[k]) *
                   (ext * (ext + 1) / 2 + ext * (pos[k] - pos[i + 1]));
          } else {
            cnt += (*R - pos[k]) * (pos[k] - *L) * ext;
          }
        }
      }
      ans -= cnt * (pos[j] - pos[j - 1]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
