#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
const int maxn = 100005;
bool isLucky(int x) {
  while (x) {
    int d = x % 10;
    if (d != 4 && d != 7) {
      return false;
    }
    x /= 10;
  }
  return true;
}
vector<pair<int, int>> a;
vector<int> b;
int nxt[maxn];
unsigned long long dp[maxn];
int g[maxn];
void gen() {
  srand(time(NULL));
  int n = 100;
  ofstream out("a.in");
  out << n << endl;
  for (int i = 0; i < n; i++) {
    out << rand() % 100 + 1 << " ";
  }
  out.close();
}
unsigned long long brute(int n) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    set<int> s1;
    for (int j = i; j < n; j++) {
      if (isLucky(g[j])) {
        s1.insert(g[j]);
      }
      for (int l = j + 1; l < n; l++) {
        for (int r = l; r < n; r++) {
          if (s1.count(g[r])) {
            break;
          }
          ans++;
        }
      }
    }
  }
  return ans;
}
int main() {
  dp[1] = 1;
  for (unsigned long long i = 2; i < maxn; i++) {
    dp[i] = dp[i - 1] + (i) * (i + 1) / 2;
  }
  int n;
  scanf("%d", &n);
  unsigned long long ans = 0;
  unsigned long long c = 0;
  unsigned long long s = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    g[i] = x;
    if (isLucky(x)) {
      a.push_back(make_pair(x, c));
      b.push_back(i);
      for (unsigned long long j = 1; j <= c; j++) {
        ans += j * (n - i + c - j) * (n - i + c - j + 1) / 2;
      }
      c = 0;
    } else {
      c++;
    }
  }
  for (unsigned long long j = 1; j < c; j++) {
    ans += j * (c - j) * (c - j + 1) / 2;
  }
  map<int, int> nx;
  for (int i = a.size() - 1; i >= 0; i--) {
    nxt[i] = nx.count(a[i].first) ? nx[a[i].first] : -1;
    nx[a[i].first] = i;
  }
  for (int i = 0; i < a.size(); i++) {
    set<int> was;
    set<int> r;
    set<int, greater<int>> l;
    l.insert(b[i]);
    r.insert(n);
    unsigned long long fr = (i + 1 < a.size() ? a[i + 1].second : n - b[i] - 1);
    unsigned long long z = 0;
    for (int j = i; j >= 0; j--) {
      if (!was.count(a[j].first)) {
        was.insert(a[j].first);
        int v = nxt[j];
        while (v != -1) {
          int x = b[v];
          unsigned long long lb = *l.lower_bound(x);
          unsigned long long rb = *r.lower_bound(x);
          if (lb != b[i]) {
            z -= (rb - lb - 1) * (rb - lb) / 2;
            z += (rb - x - 1) * (rb - x) / 2;
            z += (x - lb - 1) * (x - lb) / 2;
          } else {
            z += (rb - x - 1) * (rb - x) / 2;
          }
          l.insert(x);
          r.insert(x);
          v = nxt[v];
        }
      }
      int y = *r.begin() - b[i] - 1;
      ans += (dp[y] - dp[max(0ULL, y - fr - 1)]) * (a[j].second + 1);
      ans += z * (a[j].second + 1) * (fr + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
