#include <bits/stdc++.h>
using namespace std;
const unsigned long long BASE = 998244853;
unsigned long long e[400000];
int n;
struct str {
  string s;
  unsigned long long h[400000];
  void init() {
    cin >> s;
    h[0] = s[0];
    for (int i = 1; i < s.length(); i++) h[i] = h[i - 1] * BASE + s[i];
  }
  unsigned long long query(int l, int r) {
    unsigned long long ans = h[r];
    if (l > 0) ans -= h[l - 1] * e[r - l + 1];
    return ans;
  }
} t[40];
int sum[40];
vector<int> ed[4000000];
void build_edge(int L, int R) {
  for (int i = 0; i <= sum[n]; i++) ed[i].clear();
  for (int i = L; i <= R; i++) {
    ed[0].push_back((sum[(i)-1] + (0) + 1));
    for (int j = 0; j < t[i].s.length(); j++) {
      int l = t[i].s.length() - j;
      for (int k = L; k <= R; k++) {
        if (l == t[k].s.length()) {
          if (j == 0 && t[i].s.length() == t[k].s.length()) continue;
          if (t[i].query(j, t[i].s.length() - 1) ==
              t[k].query(0, t[k].s.length() - 1)) {
            ed[(sum[(i)-1] + (j) + 1)].push_back(0);
          }
        } else if (l < t[k].s.length()) {
          if (t[i].query(j, t[i].s.length() - 1) == t[k].query(0, l - 1)) {
            ed[(sum[(i)-1] + (j) + 1)].push_back((sum[(k)-1] + (l) + 1));
          }
        } else {
          if (t[i].query(j, j + t[k].s.length() - 1) ==
              t[k].query(0, t[k].s.length() - 1)) {
            ed[(sum[(i)-1] + (j) + 1)].push_back(
                (sum[(i)-1] + (j + t[k].s.length()) + 1));
          }
        }
      }
    }
  }
}
int in[4000000];
bool ck() {
  memset(in, 0, sizeof(in));
  for (int i = 0; i <= sum[n]; i++) {
    for (int j = 0; j < ed[i].size(); j++) in[ed[i][j]]++;
  }
  int cnt = 0;
  queue<int> q;
  for (int i = 0; i <= sum[n]; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    cnt++;
    q.pop();
    for (int j = 0; j < ed[u].size(); j++) {
      in[ed[u][j]]--;
      if (!in[ed[u][j]]) q.push(ed[u][j]);
    }
  }
  if (t[1].s.length() > 10000) printf("%d\n", cnt);
  return cnt == sum[n] + 1;
}
int main() {
  e[0] = 1;
  for (int i = 1; i <= 200000; i++) e[i] = e[i - 1] * BASE;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    t[i].init();
    sum[i] = sum[i - 1] + t[i].s.length();
  }
  int ans = 0;
  if (t[1].s.length() > 10000) {
    puts("1");
    return 0;
  }
  for (int i = 1, j = 1; i <= n; i++) {
    while (j <= i) {
      build_edge(j, i);
      if (ck())
        break;
      else
        j++;
    }
    ans += i - j + 1;
  }
  cout << ans;
}
