#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long p) {
  if (b < 0) return 0;
  long long res = 1;
  a %= p;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % p;
    a = a * a % p;
  }
  return res;
}
set<int> st;
unsigned long long ans;
int a[101000], id[101000], pre[101000];
void init(int n) {
  ans += 1uLL * (n - 1) * n / 2;
  ans += 1uLL * (n - 1) * n * (n - 2) / 3;
  ans += 1uLL * (n - 1) * n / 2 * (n - 2) / 3 * (n - 3) / 4;
}
bool Lucky(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  init(n);
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (Lucky(a[i])) id[cnt++] = i;
  }
  id[cnt] = n + 1;
  for (int i = 1; i < cnt; i++) {
    pre[i] = 0;
    for (int j = 1; j < i; j++)
      if (a[id[i]] == a[id[j]]) {
        pre[i] = j;
      }
  }
  for (int i = 2; i < cnt; i++) {
    st.clear();
    st.insert(0);
    unsigned long long tmp = 0;
    for (int j = i; j < cnt; j++) {
      if (pre[j] < i) {
        for (int k = pre[j]; k; k = pre[k]) {
          set<int>::iterator l, r;
          l = st.lower_bound(id[k]);
          r = l, l--;
          if (r != st.end()) {
            tmp += 1uLL * (id[k] - *l) * (*r - id[k]) * (id[i] - id[i - 1]);
          } else {
            tmp +=
                1uLL * (id[k] - *l) * (id[i - 1] - id[k]) * (id[i] - id[i - 1]);
            tmp += 1uLL * (id[k] - *l) * (id[i] - id[i - 1] + 1) *
                   (id[i] - id[i - 1]) / 2;
          }
          st.insert(id[k]);
        }
      }
      ans -= tmp * (id[j + 1] - id[j]);
    }
  }
  cout << ans << '\n';
  return 0;
}
