Language: C++

#include <bits/stdc++.h>
using namespace std;
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> (i)) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FORA(i, n) for (auto &&i : n)
#define POW(a, b) ((int)(pow(a, b) + .5))
#define MODULO(a, b) (((a) % (b)) < 0 ? (a) % (b) + (b) : (a) % (b))
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  REP(i, (int)vec.size())
  os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
  os << "}";
  return os;
}
// map
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  FORA(itr, map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  FORA(itr, set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if (sizeof...(Tail) > 0) DUMPOUT << ", ";
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#define PRINTARR(x, y)                                     \
  cerr << #x << "=\n";                                     \
  for (auto itr = x; itr != y; itr++) cerr << *itr << " "; \
  cerr << endl;
#define PRINTARR2(x, i0, i1)                                       \
  cerr << #x << "=\n";                                             \
  for (int ii0 = 0; ii0 < i0; ii0++) {                             \
    for (int ii1 = 0; ii1 < i1; ii1++) cerr << x[ii0][ii1] << " "; \
    cerr << endl;                                                  \
  }
#else
#define DEB if (false)
#define DUMP(...)
#define PRINTARR(x, y)
#define PRINTARR2(x, i0, i1)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define pdouble pair<double, double>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-7, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
/*
[&] { return; }();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる.
//*/
#define MAXN 1000100
int cnt[MAXN][26];
typedef pair<int, char> ic;
unordered_map<ic, vec<ic>> G;
#define MAXNN 200200
int t[MAXNN][26];
int numV = 0;
int nowIndex = 0;
int ans = 0;

void dfs(ic id, ic parent, string S, int pos) {
  if (pos == (int)S.size()) return;
  REP(i, 26) { cnt[id.fst][i] += t[nowIndex][i] >= pos; }
  bool flg = true;
  FORA(e, G[id]) {
    if (e != parent) {
      if (e.snd == S[pos]) {
        dfs(e, id, S, pos + 1);
        flg = false;
      }
    }
  }
  if (flg) {
    ic ele = mp(++numV, S[pos]);
    G[id].pb(ele);
    G[ele].pb(id);
    dfs(ele, id, S, pos + 1);
  }
}
void dfs2(ic id, ic parent, string S, int pos) {
  if (pos == (int)S.size() - 1) {
    ans += cnt[id.fst][S[pos] - 'a'];
    return;
  }
  FORA(e, G[id]) {
    if (e != parent) {
      if (e.snd == S[pos]) {
        dfs2(e, id, S, pos + 1);
      }
    }
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  int N;
  cin >> N;
  vec<string> S(N);
  REP(i, N) {
    cin >> S[i];
    //  S[i] += '-';
    reverse(ALL(S[i]));
  }
  fill(&t[0][0], &t[MAXNN][0], -1);
  REP(i, N) {
    REP(j, (int)S[i].size()) { chmax(t[i][S[i][j] - 'a'], j); }
  }
  nowIndex = 0;
  REP(i, N) {
    dfs(mp(0, '-'), mp(-1, '-'), S[i], 0);
    nowIndex++;
  }

  nowIndex = 0;
  REP(i, N) {
    dfs2(mp(0, '-'), mp(-1, '-'), S[i], 0);
    nowIndex++;
  }
  print(ans - N);
  // sort(ALL(S));
  // fill(&t[0][0], &t[MAXN][26], INF);
}

Compiler output:
a.cc:122:28: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long int, char>; _Tp = std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > >; _Hash = std::hash<std::pair<long long int, char> >; _Pred = std::equal_to<std::pair<long long int, char> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > > >]'
  122 | unordered_map<ic, vec<ic>> G;
      |                            ^
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<long long int, char>; _Tp = std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > >; _Hash = std::hash<std::pair<long long int, char> >; _Pred = std::equal_to<std::pair<long long int, char> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > > >]' is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _Alloc = std::allocator<std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > > >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, char> >; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/unordered_map.h:33:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _Alloc = std::allocator<std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > > >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, char> >; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, char> >; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<long long int, char> >; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<long long int, char> >]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::pair<long long int, char> >::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long int, char> >::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::pair<long long int, char>, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::pair<long long int, char>; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<long long int, char>; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long int, char>; _Value = std::pair<const std::pair<long long int, char>, std::vector<std::pair<long long int, char>, std::allocator<std::pair<long long int, char> > > >; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<long long int, char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long int, char> >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long int, char> >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::pair<long long int, char> >::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long int, char> >::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<long long int, char>; bool <anonymous> = false]' is private within this context
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~