#include <bits/stdc++.h>
using namespace std;
void read(int& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
bool pd(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return 0;
    x /= 10;
  }
  return 1;
}
int num(int x) {
  int u = 1;
  while (x) {
    if (x % 10 == 4)
      u = u * 2;
    else
      u = u * 2 + 1;
    x /= 10;
  }
  return u;
}
int n, i, j, t, a[1000010], tot, L, R, rig, ttt;
long long firL, res, ans;
struct node {
  int wei, key;
};
node b[2010];
int V[2010][2010];
bool vis[2010];
set<int> S;
void jia(int x) {
  ttt = min(ttt, x - rig);
  set<int>::iterator pos = S.upper_bound(x);
  int p2 = *pos, p1 = *(--pos);
  res -= 1LL * (p2 - p1) * (p2 - p1 - 1);
  res += 1LL * (x - p1) * (x - p1 - 1);
  res += 1LL * (p2 - x) * (p2 - x - 1);
  S.insert(x);
}
void ins(int x) {
  if (!vis[x]) {
    vis[x] = 1;
    int i;
    for (i = 1; i <= V[x][0]; i++)
      if (V[x][i] >= rig) jia(V[x][i]);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  b[0] = (node){1, 0};
  for (i = 1; i <= n; i++)
    if (pd(a[i])) {
      t = num(a[i]);
      b[++tot] = (node){i, t};
      V[t][++V[t][0]] = i;
    }
  b[tot + 1] = (node){n + 1, 0};
  int ls, rs;
  for (R = 1; R <= tot + 1; R++) {
    rig = b[R].wei;
    memset(vis, 0, sizeof(vis));
    S.clear();
    S.insert(rig - 1);
    S.insert(n + 1);
    res = 1LL * (n - b[R].wei + 1) * (n - b[R].wei + 2);
    ttt = n - rig + 1;
    ls = b[R].wei - b[R - 1].wei - 1;
    for (i = b[R - 1].wei + 1; i <= b[R].wei - 1; i++) {
      ans += 1LL * (i - b[R - 1].wei) *
             (1LL * (n - i + 1) * ((n - i + 1) - 1) / 2);
    }
    for (L = R - 1; L >= 0; L--) {
      ins(b[L].key);
      ls = b[L].wei - b[L - 1].wei;
      rs = b[R].wei - b[R - 1].wei;
      ans += 1LL * ls * rs * (res / 2);
      ans += 1LL * ls * (1LL * (rs) * ((rs)-1) / 2) * ttt;
      ans += 1LL * ls * (1LL * (rs + 1) * ((rs + 1) - 1) * ((rs + 1) - 2) / 6);
    }
  }
  cout << ans << endl;
  return 0;
}
