#include <bits/stdc++.h>
using namespace std;
int n, v[100000];
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
map<int, vector<int> > at;
set<int> vis;
vector<int> L;
bool lucky(int n) {
  while (n) {
    if (n % 10 != 4 && n % 10 != 7) return false;
    n /= 10;
  }
  return true;
}
long long way;
long long dp[100010][10];
long long nCk(int n, int k) {
  if (!k) return 1;
  if (n < k) return 0;
  long long &ret = dp[n][k];
  if (ret) return ret;
  return ret = nCk(n - 1, k - 1) + nCk(n - 1, k);
}
void split(int z) {
  if (!vis.insert(z).second) return;
  vector<int> &loc = at[z];
  for (int i = 0; i < loc.size(); ++i) {
    it = s.upper_bound(make_pair(loc[i], 1234567));
    if (it == s.begin()) continue;
    --it;
    if (it->first > loc[i] || it->second < loc[i]) continue;
    pair<int, int> cur = *it;
    way -= nCk(cur.second - cur.first + 2, 2);
    s.erase(it);
    pair<int, int> add(cur.first, loc[i] - 1);
    if (add.first <= add.second) {
      s.insert(add);
      way += nCk(add.second - add.first + 2, 2);
    }
    add = make_pair(loc[i] + 1, cur.second);
    if (add.first <= add.second) {
      s.insert(add);
      way += nCk(add.second - add.first + 2, 2);
    }
  }
}
int main() {
  for (int i = 1; i < 100000; i += 1000) nCk(i, 8);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v[i]);
    if (lucky(v[i])) {
      L.push_back(i);
      at[v[i]].push_back(i);
    }
  }
  if (L.empty()) {
    long long res = nCk(n, 3) * 2;
    res += nCk(n, 2);
    res += nCk(n, 4);
    cout << res << endl;
    return 0;
  }
  long long res = 0;
  for (int i = 0; i < L.size(); ++i) {
    int len = L[i];
    if (i) len -= L[i - 1] + 1;
    res += nCk(len + 1, 2) * nCk(n - L[i] + 1, 2);
    res += nCk(len + 1, 3) * (n - L[i]);
    s.clear();
    s.insert(make_pair(L[i] + 1, n - 1));
    way = 0;
    if (s.begin()->first == n) continue;
    vis.clear();
    way = nCk(s.begin()->second - s.begin()->first + 2, 2);
    for (int j = i; j < L.size(); ++j) {
      split(v[L[j]]);
      while (!s.empty() && s.begin()->first < L[j]) {
        way -= nCk(s.begin()->second - s.begin()->first + 2, 2);
        pair<int, int> cur = *s.begin();
        s.erase(s.begin());
        cur.first = L[j] + 1;
        if (cur.first <= cur.second) {
          way += nCk(cur.second - cur.first + 2, 2);
          s.insert(cur);
        }
      }
      if (!way) continue;
      int first = s.begin()->first;
      if (first != L[j] + 1) {
        long long before = L[i];
        if (i)
          before -= L[i - 1];
        else
          ++before;
        long long after =
            min(first, j + 1 < L.size() ? L[j + 1] : 123456) - L[j];
        res += before * after * way;
      } else {
        long long tmpWay =
            way - nCk(s.begin()->second - s.begin()->first + 2, 2);
        long long before = L[i];
        if (i)
          before -= L[i - 1];
        else
          ++before;
        long long after = 0;
        if (j + 1 < L.size())
          after = L[j + 1] - L[j];
        else
          after = n - L[j];
        res += before * after * tmpWay;
        if (j + 1 == L.size() || L[j + 1] > s.begin()->second) {
          int len = s.begin()->second - s.begin()->first + 1;
          res += before * nCk(len + 2, 3);
        } else {
          int len = s.begin()->second - s.begin()->first + 1;
          res += before * nCk(len + 1, 2);
          int len1 = L[j + 1] - L[j] - 1;
          int len2 = s.begin()->second - L[j + 1] + 1;
          res += before * len1 * nCk(len2 + 1, 2);
          res += before * nCk(len1, 2) * len2;
          res += before * nCk(len1 + 1, 3);
        }
      }
    }
  }
  L.push_back(n);
  for (int i = 0; i < L.size(); ++i) {
    int n = L[i];
    if (i) n -= L[i - 1] + 1;
    res += nCk(n, 3) * 2;
    res += nCk(n, 2);
    res += nCk(n, 4);
  }
  cout << res << endl;
  return 0;
}
