#include <bits/stdc++.h>
using namespace std;
long long qp[100008];
const long long hp = 2333;
char tmp[100008];
long long tot;
void moni(string &s, vector<long long> &h, vector<long long> &id) {
  scanf("%s", tmp);
  long long n = strlen(tmp);
  s = "=";
  h.push_back(0);
  long long lst = 0;
  id.push_back(0);
  for (long long i = 0; i < n; ++i) {
    s += tmp[i];
    id.push_back(++tot);
    lst = (lst * hp + tmp[i]) % 1000000033;
    h.push_back(lst);
  }
}
long long ask(long long l, long long r, vector<long long> &h) {
  return ((h[r] - h[l - 1] * qp[r - l + 1]) % 1000000033 + 1000000033) %
         1000000033;
}
string str[33];
vector<long long> h[33], id[33];
long long n;
vector<long long> v[3300008];
long long dfn[3300008], low[3300008], st[3300008], vis[3300008], size, circle;
long long DFN;
void tarjan(long long x) {
  dfn[x] = low[x] = ++DFN;
  st[++size] = x;
  vis[x] = 1;
  for (long long i = 0; i < v[x].size(); i++) {
    long long y = v[x][i];
    if (!dfn[y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (vis[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (low[x] == dfn[x]) {
    long long ct = 0;
    do {
      ct++;
      long long y = st[size--];
      vis[y] = 0;
    } while (st[size + 1] != x);
    if (ct >= 2) circle = 1;
  }
}
void add(long long x, long long y) {
  v[x].push_back(y);
  if (x == y) circle = 1;
}
long long able[3300008];
long long chk(long long l, long long r) {
  for (long long i = 0; i < 3300008; i++) v[i].clear(), dfn[i] = low[i] = 0;
  circle = DFN = 0;
  set<long long> s;
  memset(able, 0, sizeof able);
  for (long long i = l; i <= r; i++) {
    long long hhh = h[i][h[i].size() - 1];
    if (s.count(hhh))
      able[i] = 0;
    else
      able[i] = 1;
    s.insert(hhh);
  }
  for (long long i = l; i <= r; i++)
    if (able[i]) {
      for (long long j = 1; j < str[i].size(); j++) {
        if (j == 1) add(0, id[i][j]);
        for (long long k = l; k <= r; k++)
          if (able[k]) {
            if (j == 1 and k == i) continue;
            long long c =
                min((long long)str[i].size() - j, (long long)str[k].size() - 1);
            if (ask(j, j + c - 1, h[i]) != ask(1, c, h[k])) continue;
            if (str[i].size() - j == str[k].size() - 1)
              add(id[i][j], 0);
            else if (str[i].size() - j > str[k].size() - 1)
              add(id[i][j], id[i][j + c]);
            else
              add(id[i][j], id[k][c + 1]);
          }
      }
    }
  for (long long i = 0; i < 3300008; i++)
    if (!dfn[i]) tarjan(i);
  return !circle;
}
signed main() {
  scanf("%d", &n);
  qp[0] = 1;
  for (long long i = 1; i < 100008; i++) qp[i] = qp[i - 1] * hp % 1000000033;
  for (long long i = 1; i <= n; i++) moni(str[i], h[i], id[i]);
  long long r = 0;
  long long ans = 0;
  for (long long l = 1; l <= n; l++) {
    r = max(r, l - 1);
    while (r < n and chk(l, r + 1)) r++;
    ans += r - l + 1;
  }
  printf("%d\n", ans);
  return 0;
}
