#include <bits/stdc++.h>
#pragma GCC target("pclmul")
using ul = std::uint32_t;
using ull = std::uint64_t;
using li = std::int32_t;
using ll = std::int64_t;
using llf = long double;
using uss = std::uint8_t;
ul n;
const ul maxn = 30;
std::string s[maxn + 1];
const ul maxlen = 1e5;
char str[1 + maxlen + 1 + maxlen];
ul tmpz[1 + maxlen + 1 + maxlen];
std::vector<ul> z[maxn + 1][maxn + 1];
void getz(const char str[], ul z[], ul len) {
  z[1] = len;
  for (ul i = 2, l = 1, r = 1; i <= len; ++i) {
    ul tar = i - l + 1, mx = std::max(i, r + 1) - i;
    z[i] = std::min(z[tar], mx);
    while (i + z[i] <= len && str[i + z[i]] == str[z[i] + 1]) {
      ++z[i];
    }
    if (i + z[i] - 1 > r) {
      r = i + z[i] - 1;
      l = i;
    }
  }
}
std::vector<ul> id[maxn + 1];
ul tim;
ul sid[maxlen + 2];
ul pid[maxlen + 2];
std::vector<ul> edges[maxlen + 2];
ul deg[maxlen + 2];
std::deque<ul> queue;
bool check(ul a, ul b) {
  tim = 1;
  sid[1] = 0;
  pid[1] = 0;
  id[0][0] = 1;
  edges[1].resize(0);
  deg[1] = 0;
  for (ul it = a; it <= b; ++it) {
    id[it][0] = 1;
    for (ul i = 1; i <= s[it].size() - 2; ++i) {
      ++tim;
      edges[tim].resize(0);
      deg[tim] = 0;
      sid[tim] = it;
      pid[tim] = i;
      id[it][i] = tim;
    }
  }
  for (ul it = a; it <= b; ++it) {
    for (ul it2 = a; it2 <= b; ++it2) {
      for (ul i = 0; i <= s[it].size() - 2; ++i) {
        ul tmp = z[it2][it][i + 1];
        ul p = id[it][i];
        ul q;
        if (tmp < s[it2].size() - 1 && tmp < s[it].size() - 1 - i) {
          continue;
        }
        if (tmp < s[it2].size() - 1 && tmp == s[it].size() - 1 - i) {
          q = id[it2][tmp];
        }
        if (tmp == s[it2].size() - 1 && tmp < s[it].size() - 1 - i) {
          q = id[it][tmp + i];
        }
        if (tmp == s[it2].size() - 1 && tmp == s[it].size() - 1 - i) {
          q = id[0][0];
        }
        if (p != 1 || q != 1) {
          edges[p].push_back(q);
          ++deg[q];
        }
      }
    }
  }
  ul cnt = 0;
  for (ul i = 1; i <= tim; ++i) {
    if (!deg[i]) {
      queue.push_back(i);
      ++cnt;
    }
  }
  while (queue.size()) {
    ul curr = queue.front();
    queue.pop_front();
    for (ul next : edges[curr]) {
      --deg[next];
      if (!deg[next]) {
        queue.push_back(next);
        ++cnt;
      }
    }
  }
  return cnt == tim;
}
int main() {
  id[0].resize(1);
  std::scanf("%u", &n);
  for (ul i = 1; i <= n; ++i) {
    std::scanf("%s", str + 1);
    str[0] = '0';
    s[i] = str;
    id[i].resize(s[i].size() - 1);
  }
  for (ul i = 1; i <= n; ++i) {
    for (ul j = 1; j <= n; ++j) {
      std::memcpy(str + 1, s[i].data() + 1, s[i].size() - 1);
      str[s[i].size()] = 0;
      std::memcpy(str + s[i].size() + 1, s[j].data() + 1, s[j].size() - 1);
      getz(str, tmpz, s[i].size() - 1 + 1 + s[j].size() - 1);
      z[i][j].resize(s[j].size());
      for (ul k = 1; k <= s[j].size() - 1; ++k) {
        z[i][j][k] = tmpz[s[i].size() - 1 + 1 + k];
      }
    }
  }
  ul ans = 0;
  for (ul i = 1, j = 0; i <= n; ++i) {
    while (j + 1 <= n && check(i, j + 1)) {
      ++j;
    }
    ans += j - i + 1;
  }
  std::printf("%u\n", ans);
  return 0;
}
