#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <vector>
using u64 = unsigned long long;

struct hash_bases {
  static const u64 MOD = (1ull << 61) - 1;
  const int N;
  std::vector<std::vector<u64>> bases;
  
  inline static u64 mod(u64 x) {
    x = (x >> 61) + (x & MOD);
    if(x >= MOD) {
      x -= MOD;
    }
    return x;
  }

  inline static u64 mul(u64 a, u64 b) {
    u64 ac = a >> 31;
        a  = a & ((1ull << 31) - 1);
    u64 bc = b >> 31;
        b  = b & ((1ull << 31) - 1);
    u64 x = ac * b + bc * a;;
    x = ac * bc * 2 + (x >> 30) + ((x & ((1ull << 30) - 1)) << 31) + a * b;
    return mod(x);
  }
  
  hash_bases(std::vector<u64> bs, int M) : N(bs.size()), bases(M, std::vector<u64>(N, 1)) {
    for(int i = 1; i < M; i++) {
      for(int j = 0;j < N; j++){
        bases[i][j] = mul(bases[i - 1][j], bs[j]);
      }
    }
  }

  u64 operator()(int i, int r) {
    return bases[r][i];
  }
} bases(std::vector<u64> { 9973, 10007 }, 202020);

struct rhash {
  static const u64 MOD = hash_bases::MOD;
  std::vector<u64> h;
  u64 len;

  rhash() : h(bases.N), len(0) {}
  rhash(u64 x): h(bases.N), len(1) {
    x = hash_bases::mod(x);
    for(int i = 0; i < bases.N; i++) {
      h[i] = x;
    }
  }

  rhash next(u64 r) const {
    rhash ans;
    for(int i = 0;i < bases.N; i++) { 
      ans.h[i] = hash_bases::mul(h[i], bases(i, r));
    }
    ans.len = len + r;
    return ans;
  }

  rhash& operator+=(const rhash& r) {
    for(int i = 0;i < bases.N; i++) {
      h[i] += r.h[i];
      if(h[i] >= MOD) h[i] -= MOD;
    }
    len = std::max(len, r.len);
    return (*this);
  }

  rhash& operator-=(const rhash& r) {
    for(int i = 0;i < bases.N; i++) {
      if(h[i] < r.h[i]) {
        h[i] = h[i] + MOD - r.h[i];
      }
      else {
        h[i] = h[i] - r.h[i];
      }
    }
    return (*this);
  }

  rhash operator+(const rhash& r) const { return rhash(*this) += r; }
  rhash operator-(const rhash& r) const { return rhash(*this) -= r; }
  bool operator==(const rhash& r) const {
    bool OK = true;
    for(int i = 0;i < bases.N; i++){
      OK &= h[i] == r.h[i];
    }
    return OK;
  }
};

int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 N;
  cin >> N;
  vector<string> S(N);
  rep(i,0,N) cin >> S[i];
  sort(all(S), [](const string& a, const string& b){ return a.size() < b.size(); });
  vector<vector<i64>> cnt(N, vector<i64>(26));
  vector<rhash> hs(N);
  map<u64, vector<int>> sum;
  rep(i,0,N) {
    for(auto c: S[i]) cnt[i][c - 'a']++;
    if(S[i].size() == 1) continue;
    sum[hs[i].h[0]].resize(26);
    rep(c,0,26) {
      sum[hs[i].h[0]][c] += !!cnt[i][c];
    }
  }
  i64 now_len = 0;
  i64 ans = 0;
  for(int i = 0;i < N;) {
    i64 len = S[i].size();
    i64 j = i + 1;
    while(j < N && S[j].size() == len) j++;
    while(now_len < len - 1) {
      sum.clear();
      rep(k,j,N) {
        hs[k] = hs[k].next(1) + rhash(S[k][S[k].size() - 1 - now_len]);
        cnt[k][S[k][S[k].size() - 1 - now_len] - 'a']--;
        sum[hs[k].h[0]].resize(26);
        rep(c,0,26) {
            sum[hs[k].h[0]][c] += !!cnt[k][c];
        }
      }
      now_len++;
    }
    map<u64, int> here;
    while(hs[i].len < len - 1) {
      i64 now = hs[i].len;
      rep(k,i,j) {
        hs[k] = hs[k].next(1) + rhash(S[k][S[k].size() - 1 - now]);
      }
    }
    /*
    debug(now_len);
    rep(k,0,N) {
      cout << k << " = " << hs[k].h[0] << endl;
      debug(sum[hs[k].h[0]]);
    }
    */
    rep(k,i,j) {
      sum[hs[k].h[0]].resize(26);
      ans += sum[hs[k].h[0]][S[k][0] - 'a'];
      //debug(k);
      //debug(ans);
      hs[k] = hs[k].next(1) + rhash(S[k][0]);
      ans += here[hs[k].h[0]];
      //debug(k);
      //debug(ans);
      here[hs[k].h[0]]++;
    }
    i = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 105800