#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
inline bool lucky(int x) {
  while (x > 0) {
    int t = x % 10;
    if (t != 4 && t != 7) return false;
    x /= 10;
  }
  return true;
}
int n, a[MAXN], used[1100], cu, stsize, v[MAXN], vsize;
long long k1[MAXN], k2[MAXN];
vector<int> p[MAXN];
map<int, int> ids;
inline int getID(int x) {
  if (!ids.count(x)) {
    int ans = (int)ids.size();
    ids[x] = ans;
  }
  return ids[x];
}
inline long long change(set<int> &st, int x) {
  set<int>::iterator i = st.lower_bound(x);
  long long r = *i, l = *(--i);
  st.insert(x);
  long long ans = (r - l - 1) * (r - l) / 2;
  ans -= (x - l - 1) * (x - l) / 2;
  ans -= (r - x - 1) * (r - x) / 2;
  return ans;
}
inline int get2(set<int> &st) {
  set<int>::iterator i = st.begin();
  return *(++i) - *st.begin() - 1;
}
int main() {
  cin >> n;
  memset(a, 255, sizeof a);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d", &a[i]);
    if (lucky(a[i])) {
      a[i] = getID(a[i]);
      p[a[i]].push_back(i);
    } else
      a[i] = -1;
  }
  v[vsize++] = -1;
  long long ans = 0, last = -1, add = 0;
  for (int x = 0; x < (int)(n); x++)
    if (x == 0 || a[x] != -1) {
      cu++;
      add = 0;
      v[vsize++] = x;
      last = x;
      stsize = 0;
      set<int> bad;
      bad.insert(x);
      bad.insert(n);
      long long l = n - x - 1, cur = l * (l + 1) / 2;
      for (int i = vsize - 1; i > 0; i--) {
        int y = v[i];
        if (a[y] != -1 && used[a[y]] != cu) {
          for (int j = 0; j < (int)(p[a[y]].size()); j++)
            if (x < p[a[y]][j]) cur -= change(bad, p[a[y]][j]);
          used[a[y]] = cu;
        }
        long long l = get2(bad);
        k1[stsize] = l;
        k2[stsize] = v[i] - v[i - 1];
        add += (cur - l * (l + 1) / 2) * k2[stsize];
        ans += cur * k2[stsize];
        stsize++;
      }
      if (a[x] == -1) vsize--;
    } else {
      for (int i = 0; i < (int)(stsize); i++) {
        k1[i]--;
        ans += k2[i] * k1[i] * (k1[i] + 1) / 2;
      }
      ans += (x - last) * (n - x - 1) * (n - x) / 2 + add;
    }
  cout << ans << endl;
  return 0;
}
