#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> g[MAXN * 30];
int lw[MAXN], idx[MAXN], qidx, cmp[MAXN], qcmp;
stack<int> st;
void tjn(int u) {
  lw[u] = idx[u] = ++qidx;
  st.push(u);
  cmp[u] = -2;
  for (int v : g[u]) {
    if (!idx[v] || cmp[v] == -2) {
      if (!idx[v]) tjn(v);
      lw[u] = min(lw[u], lw[v]);
    }
  }
  if (lw[u] == idx[u]) {
    int x;
    do {
      x = st.top();
      st.pop();
      cmp[x] = qcmp;
    } while (x != u);
    qcmp++;
  }
}
void scc(int n) {
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) idx[i] = 0, cmp[i] = -1;
  qidx = 0;
  qcmp = 0;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i)
    if (!idx[i]) tjn(i);
}
vector<int> z_function(string& s) {
  int l = 0, r = 0, n = s.size();
  vector<int> z(s.size(), 0);
  for (int i = 1, ThxDem = n; i < ThxDem; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
string v[MAXN];
int wh[31][MAXN];
bool can(int l, int r) {
  if (l >= r) return 1;
  int id = 0;
  for (int i = l, ThxDem = r; i < ThxDem; ++i)
    for (int j = 0, ThxDem = int(v[i].size()); j < ThxDem; ++j) wh[i][j] = id++;
  for (int i = 0, ThxDem = id + 1; i < ThxDem; ++i) g[i].clear();
  for (int x = l, ThxDem = r; x < ThxDem; ++x) {
    vector<int> mp(id + 40, -1), he(id + 40, -1);
    for (int i = 0, ThxDem = int(v[x].size()); i < ThxDem; ++i)
      mp[i] = wh[x][i], he[i] = x;
    string s = v[x] + "#";
    for (int i = l, ThxDem = r; i < ThxDem; ++i)
      if (x != i) {
        for (int j = 0, ThxDem = int(v[i].size()); j < ThxDem; ++j)
          mp[int(s.size()) + j] = wh[i][j], he[int(s.size()) + j] = i;
        s += v[i] + "$";
      }
    auto z = z_function(s);
    g[id].push_back(mp[0]);
    for (int i = 1, ThxDem = int(v[x].size()); i < ThxDem; ++i)
      if (z[i] == int(v[x].size()) - i) {
        g[mp[i]].push_back(mp[z[i]]);
      }
    int pos = 0;
    for (int i = int(v[x].size()) + 1, ThxDem = int(s.size()); i < ThxDem;
         ++i) {
      if (he[i] < 0) {
        pos = 0;
        continue;
      }
      if (z[i] == int(v[he[i]].size()) - pos) {
        if (z[i] == int(v[x].size()) && pos) g[mp[i]].push_back(id);
        if (z[i] < int(v[x].size())) g[mp[i]].push_back(mp[0] + z[i]);
      } else if (z[i] == int(v[x].size())) {
        g[mp[i]].push_back(mp[i] + z[i]);
      }
      pos++;
    }
  }
  scc(id + 1);
  for (int i = 0, ThxDem = id; i < ThxDem; ++i)
    for (auto x : g[i])
      if (cmp[x] == cmp[i]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) cin >> v[i];
  long long ans = 0, now = 0;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    while (now < n && can(i, now + 1)) now++;
    ans += now - i;
  }
  cout << ans << "\n";
}
