#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
const int M = 1e3 + 13;
int a[N], pos[M], val[M];
vector<int> g[M];
int mp1[M], mp2[M];
bool isLucky(int n) {
  while (n) {
    if (n % 10 != 4 && n % 10 != 7) return false;
    n /= 10;
  }
  return true;
}
void read(int n) {
  map<int, int> mp;
  int ind = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (isLucky(a[i])) {
      if (mp.count(a[i])) {
        a[i] = mp[a[i]];
      } else {
        mp[a[i]] = ++ind;
        a[i] = mp[a[i]];
      }
    } else {
      a[i] = 0;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  int n;
  cin >> n;
  read(n);
  int m = 0;
  {
    for (int i = 1; i <= n; i++) {
      if (a[i] > 0) {
        ++m;
        pos[m] = i;
        val[m] = a[i];
      }
    }
    if (m <= 1) {
      long long ans = 0;
      for (int i = 1; i <= n; i++) {
        long long tmp = i * 1LL * (n - i) * (n - i + 1) / 2;
        ans += tmp;
      }
      cout << ans << '\n';
      exit(0);
    }
    pos[0] = 0;
    pos[m + 1] = n + 1;
    for (int i = 1; i <= m; i++) {
      g[val[i]].push_back(pos[i]);
    }
  }
  memset(mp1, 0, sizeof(mp1));
  memset(mp2, 0, sizeof(mp2));
  long long ans = 0;
  for (int i = 1; i + 1 <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      mp2[val[j]]++;
    }
    for (int l = i, r = m; l >= 1; l--) {
      mp1[val[l]]++;
      while (r >= i + 1 && mp2[val[l]] > 0) {
        mp2[val[r]]--;
        r--;
      }
      if (r >= i + 1) {
        long long tmp = (pos[l] - pos[l - 1]) * 1LL * (pos[r + 1] - pos[i + 1]);
        tmp *= (pos[i + 1] - pos[i]) * 1LL * (pos[i + 1] - pos[i] + 1) / 2;
        ans += tmp;
      }
      long long tmp = (pos[l] - pos[l - 1]);
      tmp *= (pos[i + 1] - pos[i] - 1) * 1LL * (pos[i + 1] - pos[i]) *
             (pos[i + 1] - pos[i] + 1) / 6;
      ans += tmp;
    }
    for (int j = 1; j <= i; j++) {
      mp1[val[j]] = 0;
    }
    for (int j = i + 1; j <= m; j++) {
      mp2[val[j]] = 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    long long tmp = 0;
    for (int j = pos[i - 1] + 1; j < pos[i]; j++) {
      tmp += (j - pos[i - 1]) * 1LL * (n - j) * (n - j + 1) / 2;
    }
    ans += tmp;
    if (i == 1) continue;
    long long cur = (n - pos[i]) * 1LL * (n - pos[i] + 1) / 2;
    set<int> st;
    st.insert(pos[i]);
    st.insert(n + 1);
    for (int j = i - 1; j >= 1; j--) {
      if (mp1[val[j]] == 0) {
        for (auto x : g[val[j]]) {
          if (x > pos[i]) {
            auto it = st.lower_bound(x);
            int hi = *it;
            --it;
            int lo = *it;
            cur -= (x - lo) * 1LL * (hi - x);
            st.insert(x);
          }
        }
      }
      mp1[val[j]]++;
      ans += cur * (pos[i] - pos[i - 1]) * (pos[j] - pos[j - 1]);
    }
    for (int j = i - 1; j >= 1; j--) {
      mp1[val[j]] = 0;
    }
  }
  long long tmp = 0;
  for (int j = pos[m]; j < pos[m + 1]; j++) {
    tmp += j * 1LL * (n - j) * (n - j + 1) / 2;
  }
  ans += tmp;
  cout << ans << '\n';
  return 0;
}
