Language: C++

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
struct RH {
public:
    vector<unsigned long long> p,hash;
    unsigned long long m,q;
    int n;
    void init(const string s) {
        // m=1000000007;
        m = 67280421310721;
        q=1;
        n=(int)s.size();
        p.resize(n+1);hash.resize(n+1);p[0]=q;hash[0]=0;
        for(int i=0;i<n;i++){p[i+1]=p[i]*m;hash[i+1]=s[i]+hash[i]*m;}
    }
    void apply(const char c){
        p.push_back(p[n]*m);
        hash.push_back(c+hash[n]*m);
        n++;
    }
    unsigned long long h(int i)const{return hash[i];}
    unsigned long long h(int i,int j)const{return h(j)-h(i)*p[j-i];}
    unsigned long long back_h(int i)const { return h(n) - h(n-i)*p[n-(n-i)]; }
};

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<string> S(N); for(auto& in:S) cin >> in;
    
    map<char,int> one_alpha;
    map<ull,map<pair<char,char>,int>> mp;
    
    for(int i = 0; i < N;i++){
        if(S[i].length() == 1){
            one_alpha[S[i][0]]++;
        }else{
            // add
            RH rh; rh.init(S[i]);
            char a = S[i][0],b = S[i][1];
            mp[rh.h(2,(int)S[i].length())][make_pair(a,b)]++;
        }
    }
    for(int i = 0; i < N;i++){
        if(S[i].length() == 1){
            res += one_alpha[S[i][0]];
        }else{
            {
                set<char> alpha;
                for(auto& c:S[i]) alpha.emplace(c);
                
                int T = 0;
                for(auto& c:alpha){
                    T += one_alpha[c];
                }
                res += T;

            }
            {
                RH rh; rh.init(S[i]);
                // search
                multiset<char> st;
                for(int j = 0; j < (int)S[i].length();j++){
                    st.emplace(S[i][j]);
                }
                
                int T = 0;
                for(int j = (int)S[i].length(); j >= 2; j--){
                    st.erase(st.lower_bound(S[i][j-1]));
                    ull h = rh.h(j,(int)S[i].length());
                    
                    for(auto& p:mp[h]){
                        pair<char,char> ab;
                        int num;
                        tie(ab,num) = p;
                        
                        if(ab.second == S[i][j-1]){
                            if(st.find(ab.first) != st.end()){
                                T += num;
                            }
                        }
                    }
                }
                res += T;
                
            }
        }
    }
    res = res - N;
    
    return res;
}

int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Compiler output:
a.cc: In function 'Type solve(Type)':
a.cc:54:9: error: 'ull' was not declared in this scope; did you mean 'pll'?
   54 |     map<ull,map<pair<char,char>,int>> mp;
      |         ^~~
      |         pll
a.cc:54:36: error: template argument 1 is invalid
   54 |     map<ull,map<pair<char,char>,int>> mp;
      |                                    ^~
a.cc:54:36: error: template argument 3 is invalid
a.cc:54:36: error: template argument 4 is invalid
a.cc:63:15: error: invalid types 'int[long long unsigned int]' for array subscript
   63 |             mp[rh.h(2,(int)S[i].length())][make_pair(a,b)]++;
      |               ^
a.cc:92:24: error: expected ';' before 'h'
   92 |                     ull h = rh.h(j,(int)S[i].length());
      |                        ^~
      |                        ;
a.cc:94:36: error: 'h' was not declared in this scope
   94 |                     for(auto& p:mp[h]){
      |                                    ^