#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long val;
  int pref, suff;
};
int n;
int a[100010];
Node st[400010];
bitset<1010> vis;
map<int, int> mp;
int sz, id;
int pos[1010];
int b[1010];
int nxt[100010];
vector<int> positions[1010];
long long ans = 0;
Node merge(Node a, Node b, int m) {
  Node ret;
  ret.val = a.val + b.val + 1LL * (m - a.suff + 1) * (b.pref - m);
  ret.pref = (a.pref == m) ? b.pref : a.pref;
  ret.suff = (b.suff == m + 1) ? a.suff : b.suff;
  return ret;
}
void build(int l, int r, int i) {
  if (l > r) return;
  if (l == r) {
    st[i].val = 1;
    st[i].pref = st[i].suff = l;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, i << 1);
  build(m + 1, r, 1 | (i << 1));
  st[i] = merge(st[i << 1], st[1 | (i << 1)], m);
}
void update(int l, int r, int pt, bool keep, int i) {
  if (r < pt || pt < l) return;
  if (l == r && l == pt) {
    if (!keep) {
      st[i].val = 0;
      st[i].pref = l - 1;
      st[i].suff = r + 1;
    } else {
      st[i].val = 1;
      st[i].pref = st[i].suff = l;
    }
    return;
  }
  int m = (l + r) >> 1;
  update(l, m, pt, keep, i << 1);
  update(m + 1, r, pt, keep, 1 | (i << 1));
  st[i] = merge(st[i << 1], st[1 | (i << 1)], m);
}
Node query(int l, int r, int ls, int rs, int i) {
  if (ls > n) return Node({0, 0, 0});
  if (ls <= l && r <= rs) return st[i];
  int m = (l + r) >> 1;
  if (m + 1 <= ls)
    return query(m + 1, r, ls, rs, 1 | (i << 1));
  else if (rs <= m)
    return query(l, m, ls, rs, 1 | (i << 1));
  else
    return merge(query(l, m, ls, rs, i << 1),
                 query(m + 1, r, ls, rs, 1 | (i << 1)), m);
}
bool IsLucky(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
long long f[100010];
long long Choose2(int x) { return 1LL * x * (x - 1) / 2; }
void Generate() {
  f[0] = 0;
  for (int i = 1; i <= n; i++) f[i] = 1LL * i * (i + 1) / 2;
  for (int i = 1; i <= n; i++) f[i] += f[i - 1];
}
void Solve() {
  for (int i = 1; i <= id; i++) {
    for (int j = 1; j < (int)positions[i].size(); j++) {
      nxt[positions[i][j - 1]] = positions[i][j];
    }
    nxt[positions[i].back()] = n + 1;
  }
  int last = 1;
  for (int i = 1; i <= n; i++) {
    if (IsLucky(a[i])) {
      last = i + 1;
      continue;
    } else {
      ans += (i - last + 1) * (Choose2(n - i) + n - i);
    }
  }
  pos[0] = 0;
  pos[sz + 1] = n + 1;
  build(1, n, 1);
  for (int i = 1; i <= sz; i++) {
    for (int j = 1; j <= id; j++) {
      if (vis[j]) {
        for (auto &k : positions[j]) update(1, n, k, 1, 1);
        vis[j] = false;
      }
    }
    int r = nxt[pos[i]];
    for (int j = i; j; j--) {
      if (!vis[b[j]]) {
        r = min(r, nxt[pos[j]]);
        for (auto &k : positions[b[j]]) update(1, n, k, 0, 1);
      }
      vis[b[j]] = true;
      ans += 1LL * (pos[j] - pos[j - 1]) *
             (f[r - pos[i] - 1] - f[r - pos[i + 1]] -
              Choose2(r - pos[i + 1] + 1) * (pos[i + 1] - pos[i] - 1));
      ans += 1LL * (pos[j] - pos[j - 1]) * (pos[i + 1] - pos[i]) *
             query(1, n, pos[i + 1], n, 1).val;
    }
  }
}
void Debug() {
  cin >> n;
  build(1, n, 1);
  while (true) {
    int cmd, l, r, pt;
    cin >> cmd;
    if (cmd <= 1) {
      cin >> pt;
      update(1, n, pt, cmd, 1);
    } else if (cmd == 2) {
      cin >> l >> r;
      cout << "interval = " << query(1, n, l, r, 1).val << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (IsLucky(a[i])) {
      pos[++sz] = i;
      if (!mp.count(a[i])) mp[a[i]] = ++id;
      b[sz] = mp[a[i]];
      positions[b[sz]].emplace_back(i);
    }
  }
  Generate();
  Solve();
  cout << ans << "\n";
  return 0;
}
