#include <bits/stdc++.h>
using namespace std;
const int kInf = 1E9;
bool lucky(int n) {
  return !n ? true : (n % 10 == 4 || n % 10 == 7) && lucky(n / 10);
}
inline int getIndex(int num, map<int, int> &index) {
  int &ref = index[num];
  return (ref ? ref : ref = index.size()) - 1;
}
inline long long choose(int l, int r) {
  const long long len = r - l + 1;
  return len * (len + 1) / 2;
}
void addSingle(const vector<int> &occs, int &left, const int right) {
  int pos = lower_bound(occs.begin(), occs.end(), right + 1) - occs.begin();
  if (pos && occs[pos - 1] >= left) {
    left = occs[pos - 1] + 1;
  }
}
void addBorder(const vector<int> &occs, set<pair<int, int> > &segments,
               int base, long long &result) {
  int limit = lower_bound(occs.begin(), occs.end(), base) - occs.begin();
  for (int i = 0; i < limit; ++i) {
    set<pair<int, int> >::iterator it =
        --segments.lower_bound(make_pair(occs[i], kInf));
    int left = it->first, right = it->second;
    result -= choose(left, right);
    segments.erase(it);
    if (occs[i] > left) {
      segments.insert(make_pair(left, occs[i] - 1));
      result += choose(left, occs[i] - 1);
    }
    if (occs[i] < right) {
      segments.insert(make_pair(occs[i] + 1, right));
      result += choose(occs[i] + 1, right);
    }
  }
}
int main() {
  {
    int n;
    cin >> n;
  }
  vector<int> a((istream_iterator<int>(cin)), istream_iterator<int>());
  vector<int> next(a.size() + 1, -1), prev(a.size(), -1);
  vector<long long> partials(a.size()), ends(a.size());
  map<int, int> index;
  vector<vector<int> > occs(count_if(a.begin(), a.end(), lucky));
  for (int i = 0; i < a.size(); ++i)
    if (lucky(a[i])) {
      occs[getIndex(a[i], index)].push_back(i);
      prev[i] = i;
    } else if (i) {
      prev[i] = prev[i - 1];
    }
  for (int i = a.size() - 1; i > 0; --i) {
    if (lucky(a[i])) {
      next[i] = i;
      if (prev[i - 1] == -1) continue;
      const int right = prev[i - 1];
      int left = 0;
      long long current = choose(0, right);
      set<pair<int, int> > segments;
      set<int> luckies;
      luckies.insert(a[i]);
      segments.insert(make_pair(0, right));
      addBorder(occs[getIndex(a[i], index)], segments, right + 1, current);
      addSingle(occs[getIndex(a[i], index)], left, right);
      int nl, nl_prev = i;
      for (nl = next[i + 1]; nl != -1; nl = next[nl + 1]) {
        int inside = nl - nl_prev;
        partials[i] += current * inside;
        ends[i] += (long long)(right - left + 1) * inside;
        if (!luckies.count(a[nl])) {
          luckies.insert(a[nl]);
          addBorder(occs[getIndex(a[nl], index)], segments, right + 1, current);
          addSingle(occs[getIndex(a[nl], index)], left, right);
        }
        nl_prev = nl;
      }
      ends[i] += (long long)(a.size() - nl_prev) * (right - left + 1);
      partials[i] += (long long)(a.size() - nl_prev) * current;
      next[i] = i;
    } else {
      next[i] = next[i + 1];
    }
  }
  long long result = 0;
  for (int i = 1; i < a.size(); ++i) {
    if (lucky(a[i])) {
      if (prev[i - 1] == -1)
        result += choose(0, i - 1) * (a.size() - i);
      else
        result += partials[i] +
                  choose(prev[i - 1] + 1, i - 1) * (a.size() - i) +
                  ends[i] * (i - prev[i - 1] - 1);
    } else {
      if (prev[i - 1] == -1)
        result += choose(0, i - 1) * (a.size() - i);
      else {
        int right = next[i + 1] == -1 ? a.size() - 1 : next[i + 1] - 1;
        result += choose(0, i - 1) * (right - i + 1);
        if (next[i + 1] != -1) {
          result += partials[next[i + 1]];
          int left = prev[i - 1];
          result += ends[next[i + 1]] * (i - 1 - left);
          result += choose(prev[i - 1] + 1, i - 1) * (a.size() - next[i + 1]);
        }
      }
    }
  }
  cout << result << endl;
  return 0;
}
