#include <bits/stdc++.h>
const int N = 1010, M = 100010;
int tt, t, w[N], pos[N], next[N], last[N], k[N], left[N], right[N], s[N],
    key[N];
long long get[M];
bool p[N];
bool check(int x) {
  while (x != 0) {
    if (x % 10 != 4 && x % 10 != 7) return (false);
    x = x / 10;
  }
  return (true);
}
long long sigma(int a) {
  long long temp = a;
  temp *= (a + 1);
  temp /= 2;
  return (temp);
}
void left_rotate(int &t) {
  int k = right[t];
  right[t] = left[k];
  left[k] = t;
  s[k] = s[t];
  s[t] = s[left[t]] + s[right[t]] + 1;
  t = k;
}
void right_rotate(int &t) {
  int k = left[t];
  left[t] = right[k];
  right[k] = t;
  s[k] = s[t];
  s[t] = s[left[t]] + s[right[t]] + 1;
  t = k;
}
void maintain(int &t, bool flag) {
  if (!flag)
    if (s[left[left[t]]] > s[right[t]])
      right_rotate(t);
    else if (s[right[left[t]]] > s[right[t]]) {
      left_rotate(left[t]);
      right_rotate(t);
    } else
      return;
  else if (s[right[right[t]]] > s[left[t]])
    left_rotate(t);
  else if (s[left[right[t]]] > s[left[t]]) {
    right_rotate(right[t]);
    left_rotate(t);
  } else
    return;
  maintain(left[t], false);
  maintain(right[t], true);
  maintain(t, false);
  maintain(t, true);
}
void insert(int &t, int w) {
  if (t == 0) {
    t = ++tt;
    left[t] = right[t] = 0;
    key[t] = w;
    s[t] = 1;
    return;
  } else {
    s[t]++;
    if (w < key[t])
      insert(left[t], w);
    else
      insert(right[t], w);
    maintain(t, (w >= key[t]));
  }
}
int findmin(int t, int w) {
  if (t == 0) return (0);
  if (key[t] > w)
    return (findmin(left[t], w));
  else {
    int temp = findmin(right[t], w);
    if (temp == 0) temp = key[t];
    return (temp);
  }
}
int findmax(int t, int w) {
  if (t == 0) return (0);
  if (key[t] < w)
    return (findmax(right[t], w));
  else {
    int temp = findmax(left[t], w);
    if (temp == 0) temp = key[t];
    return (temp);
  }
}
int main() {
  int n, m = 0, sum = 0, i, j, l, x, b;
  long long ans = 0, ss;
  memset(next, 0, sizeof(next));
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (check(x)) {
      m++;
      pos[m] = i;
      k[m] = -1;
      for (j = 1; j <= sum; j++)
        if (w[j] == x) {
          k[m] = j;
          next[last[j]] = m;
          last[j] = m;
          break;
        }
      if (k[m] == -1) {
        sum++;
        w[sum] = x;
        k[m] = sum;
        last[sum] = m;
      }
    }
  }
  pos[0] = 0;
  pos[m + 1] = n + 1;
  get[0] = 0;
  for (i = 1; i <= n; i++) get[i] = get[i - 1] + sigma(i);
  for (i = 1; i <= m; i++) {
    memset(s, 0, sizeof(s));
    memset(left, 0, sizeof(left));
    memset(right, 0, sizeof(right));
    memset(key, 0, sizeof(k));
    memset(p, false, sizeof(p));
    tt = t = 0;
    insert(t, i);
    insert(t, m + 1);
    b = m + 1;
    ss = 0;
    p[k[i]] = true;
    for (j = next[i]; j != 0; j = next[j]) {
      int t1 = findmin(t, j), t2 = findmax(t, j);
      if (t1 != i) {
        ss -= sigma(pos[t2] - pos[t1] - 1);
        ss += sigma(pos[j] - pos[t1] - 1);
      }
      ss += sigma(pos[t2] - pos[j] - 1);
      insert(t, j);
      if (j < b) b = j;
    }
    if (b != i + 1)
      ans += (ss * (pos[i + 1] - pos[i]) + get[pos[b] - pos[i] - 1] -
              get[pos[b] - pos[i + 1] - 1]) *
             (pos[i] - pos[i - 1]);
    else
      ans += (ss * (pos[i + 1] - pos[i]) + get[pos[b] - pos[i] - 1]) *
             (pos[i] - pos[i - 1]);
    for (j = i - 1; j > 0; j--) {
      if (!p[k[j]]) {
        for (l = next[j]; l != 0; l = next[l]) {
          int t1 = findmin(t, l), t2 = findmax(t, l);
          if (t1 != i) {
            ss -= sigma(pos[t2] - pos[t1] - 1);
            ss += sigma(pos[l] - pos[t1] - 1);
          }
          ss += sigma(pos[t2] - pos[l] - 1);
          insert(t, l);
          if (l < b) b = l;
        }
        p[k[j]] = true;
      }
      if (b != i + 1)
        ans += (ss * (pos[i + 1] - pos[i]) + get[pos[b] - pos[i] - 1] -
                get[pos[b] - pos[i + 1] - 1]) *
               (pos[j] - pos[j - 1]);
      else
        ans += (ss * (pos[i + 1] - pos[i]) + get[pos[b] - pos[i] - 1]) *
               (pos[j] - pos[j - 1]);
    }
  }
  for (i = 1; i <= m + 1; i++)
    for (j = 1; j <= pos[i] - pos[i - 1] - 1; j++)
      ans += sigma(n - pos[i - 1] - j) * j;
  printf("%I64d", ans);
  return (0);
}
