#include <bits/stdc++.h>
using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) static_cast<int>((x).size())

template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
      : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
      : vector<T>(args...) {}
};

template<class T>
inline bool Minimize(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool Maximize(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int Next(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int Prev(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count()));

constexpr int kMod1 = 1e9 + 9, kMod2 = 1e9 + 7;

int Mod = kMod1;
struct ModInt {
  int a;
  ModInt(int t_a = 0) {
    a = (t_a < Mod ? (t_a < 0 ? t_a + Mod : t_a) : t_a - Mod);
  }
  friend istream& operator>>(istream& in_stream, ModInt& o) {
    in_stream >> o.a;
    o.a = (o.a < Mod ? (o.a < 0 ? o.a + Mod : o.a) : o.a - Mod);
    return in_stream;
  }
  friend ostream& operator<<(ostream& out_stream, const ModInt& o) {
    out_stream << o.a;
    return out_stream;
  }

  bool operator!() const { return !a; }
  explicit operator bool() const { return !!a; }

  ModInt operator-() const { return ModInt() - *this; }
  ModInt operator+(const ModInt& o) const { return ModInt(a + o.a); }
  ModInt operator-(const ModInt& o) const { return ModInt(a - o.a); }
  ModInt operator*(const ModInt& o) const { return ModInt(static_cast<int>(static_cast<int64_t>(a) * o.a % Mod)); }
  ModInt operator/(const ModInt& o) const { return *this * o.Inverse(); }
  ModInt& operator+=(const ModInt& o) { return *this = *this + o; }
  ModInt& operator-=(const ModInt& o) { return *this = *this - o; }
  ModInt& operator*=(const ModInt& o) { return *this = *this * o; }
  ModInt& operator/=(const ModInt& o) { return *this = *this / o; }
  ModInt& operator++() { return *this = *this + ModInt(1); }
  ModInt& operator--() { return *this = *this - ModInt(1); }
  ModInt Inverse() const { return Power(Mod - 2); }
  template<class T>
  ModInt Power(T exp) const {
    ModInt ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) {
      if (exp & 1) {
        ret *= c;
      }
    }
    return ret;
  }
};
ModInt base(311);

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  int n_strings; cin >> n_strings;
  vec<string, 1> strings(n_strings);
  for (auto& i : strings) {
    cin >> i;
  }

  sort(ALL(strings), [&](const auto& i, const auto& j) { return SZ(i) < SZ(j); });

  int64_t answer = 0;
  map<pair<int, int>, set<char>> f;
  for (auto& i : strings) {
    vec<int, 1> first_index_characters(26);
    for (int j = 0; j < 26; ++j) {
      first_index_characters[j] = static_cast<int>(find(ALL(i), static_cast<char>(j + 'a')) - i.begin());
    }

    ModInt value_1, value_2;
    for (int j = SZ(i); j; --j) {
      for (int k = 0; k < 26; ++k) {
        answer += first_index_characters[k] < j && f[make_pair(value_1.a, value_2.a)].count(static_cast<char>(k + 'a'));
      }
      if (j - 1) {
        value_1 = value_1 * base + ModInt(i[j - 1]);
        Mod = kMod2;
        value_2 = value_2 * base + ModInt(i[j - 1]);
        Mod = kMod1;
      }
    }
    f[make_pair(value_1.a, value_2.a)].emplace(i[0]);
  }

  cout << answer << '\n';

  return 0;
}

Measured memory_bytes: 98256