#include <bits/stdc++.h>
using namespace std;
set<int> S;
map<int, int> P;
int n, m, nxt[100005];
int A[100005], data[3005], sum[3005];
unsigned long long ans;
bool check(int a) {
  for (; a;) {
    if (a % 10 != 4 && a % 10 != 7) return 0;
    a /= 10;
  }
  return 1;
}
void Add(int a, unsigned long long &x) {
  S.insert(a);
  set<int>::iterator it = S.find(a);
  it--;
  int l = *it;
  it++;
  it++;
  int r = *it;
  x -= 1ll * (sum[r - 1] - sum[l]) * (sum[r - 1] - sum[l] + 1) / 2;
  x += 1ll * (sum[r - 1] - sum[a]) * (sum[r - 1] - sum[a] + 1) / 2;
  x += 1ll * (sum[a - 1] - sum[l]) * (sum[a - 1] - sum[l] + 1) / 2;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    if (!check(A[i])) A[i] = 1;
    if (A[i - 1] != A[i] || A[i] != 1)
      data[++m] = A[i], sum[m] = 1;
    else
      sum[m]++;
    if (A[i] != 1) {
      if (P[A[i]] != 0)
        nxt[P[A[i]]] = P[A[i]] = m;
      else
        P[A[i]] = m;
    }
  }
  for (int i = 1; i <= m + 1; i++) sum[i] += sum[i - 1];
  for (int i = 1; i <= m; i++) {
    unsigned long long now =
        1ull * (sum[m] - sum[i]) * (sum[m] - sum[i] + 1) / 2;
    S.clear();
    S.insert(i);
    S.insert(m + 1);
    int z = sum[i] - sum[i - 1];
    if (data[i] == 1) {
      ans += 1ull * z * (z - 1) / 2 * (z - 2) / 3 * (z - 3) / 4;
      ans += 1ull * z * (z - 1) * (z - 2) / 3;
      ans += 1ull * z * (z - 1) / 2;
    }
    for (int j = i; j >= 1; j--) {
      if (data[j] != 1)
        for (int k = nxt[j]; k; k = nxt[k])
          if (k > i)
            Add(k, now);
          else
            break;
      if (j != i)
        ans += 1ull * (sum[j] - sum[j - 1]) * z * now;
      else
        ans += 1ull * z * (z + 1) / 2 * now;
      if (data[i] == 1) {
        set<int>::iterator it = S.begin();
        it++;
        int a = *it;
        if (j != i) {
          ans += 1ull * (sum[j] - sum[j - 1]) * z * (z - 1) / 2 *
                 (sum[a - 1] - sum[i]);
          ans += 1ull * z * (z - 1) / 2 * (z - 2) / 3 * (sum[j] - sum[j - 1]);
          ans += 1ull * (sum[j] - sum[j - 1]) * z * (z - 1) / 2;
        } else {
          ans += 1ll * z * (z - 1) / 2 * (z - 2) / 3 * (sum[a - 1] - sum[i]);
          ans += 1ll * z * (z - 1) / 2 * (sum[a - 1] - sum[i]);
        }
      }
    }
  }
  printf("%I64d\n", ans);
}
