#include <bits/stdc++.h>
using namespace std;
struct KMP {
  vector<int> b;
  string p;
  string t;
  vector<pair<int, int> > match;
  void kmpPreprocess() {
    int i = 0, j = -1;
    b[i] = j;
    while (i < ((int)p.size())) {
      while (j >= 0 && p[i] != p[j]) j = b[j];
      i++;
      j++;
      b[i] = j;
    }
  }
  void kmpSearch() {
    int i = 0, j = 0;
    while (i < ((int)t.size())) {
      while (j >= 0 && t[i] != p[j]) j = b[j];
      i++;
      j++;
      if (j == ((int)p.size())) {
        match.push_back(make_pair((i - j), (j)));
        j = b[j];
      }
      if (i == ((int)t.size())) {
        while (j) {
          match.push_back(make_pair((i - j), (j)));
          j = b[j];
        }
      }
    }
  }
  KMP(string p, string t) : p(p), t(t) {
    b.resize(1 + ((int)p.size()));
    match.clear();
    kmpPreprocess();
    kmpSearch();
  }
};
int gid;
int id[3300000];
int lo[3300000];
stack<int> stk;
int onStack[3300000];
int nsc;
vector<int> sc[3300000];
int scOf[3300000];
int loop[3300000];
vector<pair<int, int> > adj[330000];
int l, r;
int sloop;
void dfs(int u) {
  id[u] = lo[u] = gid++;
  stk.push(u);
  onStack[u] = 1;
  int v;
  if (loop[u]) sloop = 1;
  for (pair<int, int> p : adj[u]) {
    if (p.second < l || p.second > r) continue;
    v = p.first;
    if (!id[v]) {
      dfs(v);
      lo[u] = min(lo[u], lo[v]);
    } else if (onStack[v]) {
      lo[u] = min(lo[u], id[v]);
    }
  }
  if (lo[u] == id[u]) {
    sc[nsc].clear();
    do {
      v = stk.top();
      stk.pop();
      onStack[v] = 0;
      sc[nsc].push_back(v);
      scOf[v] = nsc;
    } while (v != u);
    nsc++;
  }
}
int n;
int beg[33];
string s[33];
int src;
int good() {
  for (int(i) = (0); (i) < (src + 1); (i)++) id[i] = 0;
  nsc = 0;
  gid = 1;
  sloop = 0;
  for (int(i) = (0); (i) < (src + 1); (i)++) {
    if (!id[i] && ((i == src) || (beg[l] <= i && i < beg[r + 1]))) dfs(i);
  }
  if (sloop) return 0;
  return (nsc == beg[r + 1] - beg[l] - (r - l) &&
          ((int)sc[scOf[src]].size()) == (r - l + 2));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  src = 0;
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> s[i];
    beg[i] = src;
    src += ((int)s[i].size());
  }
  beg[n] = src;
  for (int(i) = (0); (i) < (src + 1); (i)++) loop[i] = 0;
  for (int(i) = (0); (i) < (n); (i)++) {
    adj[src].push_back(make_pair((beg[i]), (i)));
    for (int(j) = (0); (j) < (n); (j)++) {
      KMP k(s[i], s[j]);
      for (pair<int, int> z : k.match) {
        int pos = z.first;
        int len = z.second;
        if (len == ((int)s[i].size())) {
          if (pos + len == ((int)s[j].size())) {
            adj[beg[j] + pos].push_back(make_pair((src), (i)));
          } else {
            adj[beg[j] + pos].push_back(make_pair((beg[j] + pos + len), (i)));
          }
        } else {
          if (i == j && pos == len)
            loop[beg[j] + pos] = 1;
          else
            adj[beg[j] + pos].push_back(make_pair((beg[i] + len), (i)));
        }
      }
    }
  }
  long long ans = 0;
  r = 0;
  for (l = 0; l < n; l++) {
    while (good() && r < n) {
      r++;
      ans += (r - l);
    }
  }
  cout << ans << endl;
  return 0;
}
