#include <bits/stdc++.h>
using namespace std;
int arr[100001];
int n;
int numLuckies;
int luckyLocations[1001];
map<int, vector<int> > luckyAppearances;
unsigned long long helper1(unsigned long long tmpGoodCombinations,
                           unsigned long long lastGroupLen, int k) {
  return k * (tmpGoodCombinations -
              lastGroupLen * (lastGroupLen + 1ULL) / 2ULL +
              (lastGroupLen - k) * (lastGroupLen - k + 1ULL) / 2ULL) +
         k * (k - 1ULL) / 2ULL * (3ULL * lastGroupLen - 2ULL * k + 1) / 3ULL;
}
unsigned long long countGoodIntervalsForFixedI(int i) {
  unsigned long long sumGoodCombinations, tmpGoodCombinations;
  int tmp, val, startIndex, endIndex;
  map<int, int> startPoints;
  set<int> foundLuckies;
  startPoints.insert(make_pair(luckyLocations[i] - 1, 0));
  sumGoodCombinations = 0;
  tmpGoodCombinations =
      luckyLocations[i] * (unsigned long long)(luckyLocations[i] + 1) / 2;
  for (int j = i; j < numLuckies; ++j) {
    if (j > i && luckyLocations[j] - luckyLocations[j - 1] > 1) {
      tmp = luckyLocations[j] - luckyLocations[j - 1] - 1;
      sumGoodCombinations += tmpGoodCombinations * tmp;
      map<int, int>::reverse_iterator it = startPoints.rbegin();
      unsigned long long lastGroupLen, toBeAdded;
      int tmp2;
      if (it != startPoints.rend()) {
        lastGroupLen = it->first - it->second + 1, toBeAdded;
        tmp2 = luckyLocations[i] - luckyLocations[i - 1] - 1;
      } else {
        lastGroupLen = 0;
        tmp2 = 0;
      }
      toBeAdded = helper1(tmpGoodCombinations, lastGroupLen, tmp2);
      sumGoodCombinations += tmp * toBeAdded;
    }
    val = arr[luckyLocations[j]];
    if (foundLuckies.find(val) == foundLuckies.end()) {
      const vector<int> &appearances = luckyAppearances[val];
      for (int k = 0;
           k < appearances.size() && appearances[k] < luckyLocations[i]; ++k) {
        endIndex = startPoints.lower_bound(appearances[k])->first;
        startIndex = startPoints[endIndex];
        tmp = endIndex - startIndex + 1;
        tmpGoodCombinations -= tmp * (tmp + 1ULL) / 2ULL;
        if (appearances[k] < endIndex) {
          startPoints[endIndex] = (appearances[k] + 1);
          tmp = endIndex - appearances[k];
          tmpGoodCombinations += tmp * (tmp + 1ULL) / 2ULL;
        } else {
          startPoints.erase(endIndex);
        }
        if (appearances[k] > startIndex) {
          startPoints.insert(make_pair(appearances[k] - 1, startIndex));
          tmp = appearances[k] - startIndex;
          tmpGoodCombinations += tmp * (tmp + 1ULL) / 2ULL;
        }
      }
      foundLuckies.insert(val);
    }
    sumGoodCombinations += tmpGoodCombinations;
    map<int, int>::reverse_iterator it = startPoints.rbegin();
    unsigned long long lastGroupLen, toBeAdded;
    int tmp2;
    if (it != startPoints.rend()) {
      lastGroupLen = it->first - it->second + 1, toBeAdded;
      tmp2 = luckyLocations[i] - luckyLocations[i - 1] - 1;
    } else {
      lastGroupLen = 0;
      tmp2 = 0;
    }
    toBeAdded = helper1(tmpGoodCombinations, lastGroupLen, tmp2);
    sumGoodCombinations += toBeAdded;
  }
  if (n - luckyLocations[numLuckies - 1] > 1) {
    tmp = n - luckyLocations[numLuckies - 1] - 1ULL;
    sumGoodCombinations += tmpGoodCombinations * tmp;
    map<int, int>::reverse_iterator it = startPoints.rbegin();
    unsigned long long lastGroupLen, toBeAdded;
    int tmp2;
    if (it != startPoints.rend()) {
      lastGroupLen = it->first - it->second + 1, toBeAdded;
      tmp2 = luckyLocations[i] - luckyLocations[i - 1] - 1;
    } else {
      lastGroupLen = 0;
      tmp2 = 0;
    }
    toBeAdded = helper1(tmpGoodCombinations, lastGroupLen, tmp2);
    sumGoodCombinations += tmp * toBeAdded;
  }
  return sumGoodCombinations;
}
unsigned long long helper2(int P, int R) {
  unsigned long long r[4] = {1ULL}, p[4] = {1ULL};
  for (int i = 1; i < 4; ++i) {
    r[i] = r[i - 1] * (unsigned long long)R;
    p[i] = p[i - 1] * (unsigned long long)P;
  }
  unsigned long long tmp, tmp2, result, remFactor,
      factors[7] = {2, 3, 4, 6, 8, 12, 24}, toMultiply[5] = {};
  remFactor = 24;
  tmp = 1;
  for (int i = 0; i < 4; ++i) {
    toMultiply[i] = R + i;
  }
  for (int i = 0; i < 4; ++i) {
    tmp2 = toMultiply[i];
    for (int j = 6; j >= 0; --j) {
      if (!(remFactor % factors[j]) && !(tmp2 % factors[j])) {
        tmp2 /= factors[j];
        remFactor /= factors[j];
        break;
      }
    }
    tmp *= tmp2;
  }
  result = tmp;
  toMultiply[1] = P * (P - 1ULL);
  toMultiply[0] = (4ULL * R * (P + 1ULL) + 6ULL - 3ULL * P * (P - 1ULL));
  remFactor = 24;
  tmp = 1;
  for (int i = 0; i < 2; ++i) {
    tmp2 = toMultiply[i];
    for (int j = 6; j >= 0; --j) {
      if (!(remFactor % factors[j]) && !(tmp2 % factors[j])) {
        tmp2 /= factors[j];
        remFactor /= factors[j];
        break;
      }
    }
    tmp *= tmp2;
  }
  result -= tmp;
  return result;
  return result / 2ULL;
  return (tmp - P * (P - 1ULL) / 2ULL *
                    (4ULL * R * (P + 1ULL) + 6ULL - 3ULL * P * (P - 1ULL)) /
                    6ULL) /
         2ULL;
  return (R * (R + 1ULL) / 2ULL * (R + 2ULL) / 3ULL * (R + 3ULL) / 2ULL -
          P * (P - 1ULL) / 2ULL *
              (4ULL * R * (P + 1ULL) + 6ULL - 3ULL * P * (P - 1ULL)) / 6ULL) /
         2ULL;
  return ((r[1] - p[1]) * (r[3] + p[1] * r[2] + p[2] * r[1] - 3ULL * p[3] +
                           6ULL * p[2] + 6ULL * p[1] * r[1] + 6ULL * r[2]) +
          11ULL * r[2] - 6ULL * p[2] + 4ULL * p[1] * r[1] - 3ULL * p[2] +
          6ULL * p[1] + 6 * r[1]) /
         24ULL;
}
unsigned long long solve() {
  int i, p, r, tmp, tmpP, tmpR;
  unsigned long long result = 0, tmp2;
  for (int i = 0; i < numLuckies; ++i) {
    tmp2 = countGoodIntervalsForFixedI(i);
    result += tmp2;
  }
  unsigned long long maxVal = 0, maxInd = -1;
  for (int i = 1; i < numLuckies; ++i) {
    p = luckyLocations[i - 1] + 1;
    r = luckyLocations[i] - 1;
    if (p <= r) {
      tmp2 = helper2(p, r);
      result += tmp2;
    }
  }
  if (numLuckies) {
    p = 0;
    r = luckyLocations[0] - 1;
    if (p <= r) {
      tmp2 = helper2(p, r);
      result += tmp2;
    }
    p = luckyLocations[numLuckies - 1] + 1;
    r = n - 1;
    if (p <= r) {
      tmp2 = helper2(p, r);
      result += tmp2;
    }
  } else {
    p = 0;
    r = n - 1;
    if (p <= r) {
      tmp2 = helper2(p, r);
      result += tmp2;
    }
  }
  return result;
}
bool isLucky(int n) {
  int tmp;
  while (n) {
    tmp = n % 10;
    if (tmp != 4 && tmp != 7) return false;
    n /= 10;
  }
  return true;
}
int main() {
  numLuckies = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", arr + i);
    if (isLucky(arr[i])) {
      luckyLocations[numLuckies++] = i;
      if (luckyAppearances.find(arr[i]) == luckyAppearances.end()) {
        luckyAppearances.insert(make_pair(arr[i], vector<int>()));
      }
      luckyAppearances[arr[i]].push_back(i);
    }
  }
  cout << solve() << endl;
  return 0;
}
