#include <bits/stdc++.h>
using namespace std;
int q[2005], a[2005], cum[2005];
int cnt = 1, n;
set<int> use;
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
map<int, vector<int> > mp;
long long diff(int dif) { return (dif * 1LL * (dif + 1)) / 2; }
int main() {
  scanf("%d", &n);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    int ti;
    scanf("%d", &ti);
    int ok = 1, ni = ti;
    while (ni > 0) {
      if (!(ni % 10 == 4 || ni % 10 == 7)) {
        ok = 0;
        break;
      }
      ni /= 10;
    }
    if (ok == 1) {
      if (cur > 0) {
        q[cnt] = cur;
        a[cnt] = 0;
        cnt++;
        cur = 0;
      }
      mp[ti].push_back(cnt);
      q[cnt] = 1;
      a[cnt] = ti;
      cnt++;
    } else
      cur++;
  }
  if (cur > 0) {
    q[cnt] = cur;
    a[cnt] = 0;
    cnt++;
  }
  cum[0] = 0;
  for (int i = 1; i < cnt; i++) {
    cum[i] = cum[i - 1] + q[i];
  }
  long long ret = 0;
  for (int i = 1; i < cnt; i++) {
    if (q[i] >= 2) {
      for (int j = 1; j < q[i]; j++) {
        ret += j * 1LL * (j + 1) / 2 * (q[i] - j);
      }
      for (int j = 1; j < q[i]; j++) {
        ret += j * 1LL * (cum[cnt - 1] - cum[i]) * 1LL * (q[i] - j);
        ret += (q[i] - j) * 1LL * (cum[i - 1]) * 1LL * j;
      }
    }
    s.clear();
    use.clear();
    long long sum = diff(cum[i - 1]);
    if (i > 1) s.insert(make_pair(1, i - 1));
    for (int j = i; j < cnt; j++) {
      if (a[j] == 0) {
        if (i != j) {
          ret += sum * 1LL * q[j] * 1LL * q[i];
        } else {
          ret += sum * 1LL * q[i] * 1LL * (q[i] + 1) / 2;
        }
      } else {
        if (use.find(a[j]) == use.end()) {
          int len = mp[a[j]].size();
          for (int k = 0; k < len; k++) {
            int pos = mp[a[j]][k];
            if (pos >= i) break;
            it = s.lower_bound(make_pair(pos + 1, 0));
            if (it != s.begin()) {
              it--;
              if ((*it).second >= pos) {
                int pa = (*it).second, pb = (*it).first;
                sum -= diff(cum[pa] - cum[pb - 1]);
                s.erase(*it);
                if (pa > pos) {
                  s.insert(make_pair(pos + 1, pa));
                  sum += diff(cum[pa] - cum[pos]);
                }
                if (pb < pos) {
                  s.insert(make_pair(pb, pos - 1));
                  sum += diff(cum[pos - 1] - cum[pb - 1]);
                }
              }
            }
          }
          use.insert(a[j]);
        }
        ret += sum * 1LL * q[i];
      }
      if (i != j) {
        if (!s.empty()) {
          it = s.end();
          it--;
          if ((*it).second == i - 1) {
            int pos = cum[i - 1] - cum[(*it).first - 1];
            ret += q[j] * 1LL * pos * 1LL * q[i] * 1LL * (q[i] - 1) / 2;
          }
        }
      }
    }
  }
  printf("%I64d\n", ret);
}
