Language: C++

#pragma GCC optimize("O3")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
using namespace std;
   
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> pr;
typedef pair<LL, LL> lpr;
typedef pair<double, double> dpr;
typedef pair<long double, long double> ldpr;
typedef double db;
typedef long double ld;
// typedef complex<double> cp;
// typedef pair<ld,ld> pt;
   
#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)
  
#define mst(s, x) memset(s, x, sizeof(s))
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define all(x) x.begin(), x.end()
#define unq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define rg register
#define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (rg int i = (a), I = (b)-1; i > I; --i)
#define ub upper_bound
#define lb lower_bound
#define bitcount __builtin_popcount
#define sqr(x) ((x)*(x))
  
#define go(u) for (rg int i = pre[u], v = e[i].v; i; i = e[i].next, v = e[i].v)
#define gow(u) for (rg LL i = pre[u], v = e[i].v, w = e[i].w; i; i = e[i].next, v = e[i].v, w = e[i].w)
#define EDGE(N,M) struct edge{int u,v,w,next;}e[M];int pre[N],edge_cnt=0;void addedge(int u,int v,int w=0){edge_cnt=edge_cnt+1,e[edge_cnt].u=u,e[edge_cnt].v=v,e[edge_cnt].w=w,e[edge_cnt].next=pre[u],pre[u]=edge_cnt;}
#define CLEAR_EDGE(N) {edge_cnt=0,memset(pre,0,sizeof(int)*(N+1));}
  
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
  
#define MC int _CASE;scanf("%d",&_CASE);fp(case_num,1,_CASE)
   
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9+5;//7;
const LL linf = 1e18+5;
const double PI = acos(-1.0);
   
const int MAXN = 1e6+5;
const int N    = 200*200*2+5;
const int fix  = 500*500+5;
 
#define mid ((l+r)/2)
#define ls (cnt<<1)
#define rs (cnt<<1|1)
 
// #define ls ch[x][0]
// #define rs ch[x][1]
    
/*----------head----------*/

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<long long, int, custom_hash> safe_map;
// gp_hash_table<long long, int, custom_hash> safe_hash_table;

ULL base = 13331;
int n,cnt[26];
vector<ULL> h[MAXN];
map<ULL,custom_hash> v[26],vis;
char s[MAXN],f[MAXN];
LL ans=0; 
int work()
{
    scanf("%d",&n);
    fp(i,1,n)
    {
        scanf("%s",s);
        int len=strlen(s);
        h[i].resize(len+1);
        fd(j,len-1,0)
            h[i][j]=h[i][j+1]*base+s[j];
        mst(cnt,0);
        fp(j,0,len)
        {
            fp(k,0,25)if(cnt[k])v[k][h[i][j]]++;
            if(j<len)cnt[s[j]-'a']=1;
        }
        // h[i].resize(2);
        f[i]=s[0];
    }
    fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
    return 0*printf("%lld\n",ans);
}

// 小数 二分/三分 注意break条件
// 浮点运算 sqrt(a^2-b^2) 可用 sqrt(a+b)*sqrt(a-b) 代替，避免精度问题
// long double -> %Lf 别用C11 (C14/16)
// 控制位数 cout << setprecision(10) << ans;
// reverse vector 注意判空 不然会re
// 分块注意维护块上标记 来更新块内数组a[]
// vector+lower_bound常数 < map/set
// map.find不会创建新元素 map[]会 注意空间
// 别对指针用memset
// 用位运算表示2^n注意加LL 1LL<<20
// 注意递归爆栈
// 注意边界
// 注意memset 多组会T
   
//#define ONLINE_JUDGE
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef ONLINE_JUDGE
    // freopen("triatrip.in", "r",stdin );
    // freopen("triatrip.out","w",stdout);
#endif // ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    int size = 512 << 20; // 512MB  
    char *p = (char*)malloc(size) + size;  
    __asm__("movl %0, %%esp\n" :: "r"(p)); 
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    work();
#ifndef ONLINE_JUDGE
    cout << "time:" << clock() << "ms" << endl;
    freopen("CON", "r", stdin);
    freopen("CON", "w", stdout);
    system("pause");
    fflush(stdout);
#endif
    return 0;
}

Compiler output:
a.cc: In function 'int work()':
a.cc:97:8: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   97 |     fp(i,1,n)
      |        ^
a.cc:35:33: note: in definition of macro 'fp'
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                 ^
a.cc:35:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                          ^
a.cc:97:5: note: in expansion of macro 'fp'
   97 |     fp(i,1,n)
      |     ^~
a.cc:102:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  102 |         fd(j,len-1,0)
      |            ^
a.cc:36:33: note: in definition of macro 'fd'
   36 | #define fd(i, a, b) for (rg int i = (a), I = (b)-1; i > I; --i)
      |                                 ^
a.cc:36:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 | #define fd(i, a, b) for (rg int i = (a), I = (b)-1; i > I; --i)
      |                                          ^
a.cc:102:9: note: in expansion of macro 'fd'
  102 |         fd(j,len-1,0)
      |         ^~
a.cc:105:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  105 |         fp(j,0,len)
      |            ^
a.cc:35:33: note: in definition of macro 'fp'
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                 ^
a.cc:35:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                          ^
a.cc:105:9: note: in expansion of macro 'fp'
  105 |         fp(j,0,len)
      |         ^~
a.cc:107:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  107 |             fp(k,0,25)if(cnt[k])v[k][h[i][j]]++;
      |                ^
a.cc:35:33: note: in definition of macro 'fp'
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                 ^
a.cc:35:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                          ^
a.cc:107:13: note: in expansion of macro 'fp'
  107 |             fp(k,0,25)if(cnt[k])v[k][h[i][j]]++;
      |             ^~
a.cc:107:46: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
  107 |             fp(k,0,25)if(cnt[k])v[k][h[i][j]]++;
a.cc:113:8: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |        ^
a.cc:35:33: note: in definition of macro 'fp'
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                 ^
a.cc:35:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 | #define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
      |                                          ^
a.cc:113:5: note: in expansion of macro 'fp'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |     ^~
a.cc:113:39: error: no match for 'operator-' (operand types are 'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} and 'int')
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::reverse_iterator<_Iterator>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::move_iterator<_IteratorL>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/complex:370:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const complex<_Tp>&)'
  370 |     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:370:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::complex<_Tp>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/complex:379:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const _Tp&)'
  379 |     operator-(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:379:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::complex<_Tp>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/complex:388:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const _Tp&, const complex<_Tp>&)'
  388 |     operator-(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:388:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   mismatched types 'const std::complex<_Tp>' and 'int'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/complex:465:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&)'
  465 |     operator-(const complex<_Tp>& __x)
      |     ^~~~~~~~
/usr/include/c++/14/complex:465:5: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   'std::map<long long unsigned int, custom_hash>::mapped_type' {aka 'custom_hash'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:113:40: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
  113 |     fp(i,1,n)ans+=v[f[i]-'a'][h[i][1]]-1-(vis[h[i][0]]++);
      |                                        ^
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typena