#include <bits/stdc++.h>
using namespace std;
set<int> used;
set<pair<int, int> > S;
inline long long cnt(long long w) { return (w * (w + 1)) >> 1; }
long long ans;
void init(int f, int t) {
  ans = cnt(t - f + 1);
  S.clear();
  S.insert(pair<int, int>(f, t));
}
void split(int pos) {
  set<pair<int, int> >::iterator it =
      S.lower_bound(pair<int, int>(pos + 1, -1));
  if (it == S.begin()) return;
  --it;
  pair<int, int> T = *it;
  S.erase(T);
  ans -= cnt(T.second - T.first + 1);
  if (T.first < pos)
    S.insert(pair<int, int>(T.first, pos - 1)), ans += cnt(pos - T.first);
  if (pos < T.second)
    S.insert(pair<int, int>(pos + 1, T.second)), ans += cnt(T.second - pos);
}
inline long long get() { return ans; }
map<int, vector<int> > pos;
int N, in[100010];
bool lucky[100010];
vector<int> all;
bool is_lucky(int w) {
  while (w) {
    if (w % 10 != 4 && w % 10 != 7) return false;
    w /= 10;
  }
  return true;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &in[i]);
    lucky[i] = is_lucky(in[i]);
    if (lucky[i]) pos[in[i]].push_back(i), all.push_back(i);
  }
  long long out = 0;
  long long last_cnt, sub;
  for (int i = 0; i + 1 < N; ++i) {
    if (i == 0 || lucky[i]) {
      init(i + 1, N - 1);
      used.clear();
      last_cnt = sub = 0;
      int P = i, NP, ban = N;
      while (P >= 0) {
        vector<int>::iterator it = lower_bound(all.begin(), all.end(), P);
        if (it == all.begin())
          NP = -1;
        else
          NP = *(it - 1);
        if (lucky[P] && !used.count(in[P])) {
          used.insert(in[P]);
          vector<int>& U = pos[in[P]];
          for (vector<int>::iterator it =
                   lower_bound(U.begin(), U.end(), P + 1);
               it != U.end(); ++it)
            split(*it), ban = min(ban, *it);
        }
        last_cnt += (P - NP) * get();
        sub += (P - NP + 0LL) * (ban - i - 1);
        P = NP;
      }
      out += last_cnt;
    } else {
      last_cnt = last_cnt - sub + cnt(N - i - 1);
      sub = sub - i + N - i - 1;
      out += last_cnt;
    }
  }
  cout << out << '\n';
  return 0;
}
