Language: C++

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

struct rolling_hash{
	// !!! ハッシュはullで受け取ること !!!
	// 文字列の中に0があると，その値が影響しなくなって壊れるので注意！
	// generate_base は結構遅いので，何回も呼び出す必要がある場合は何度も呼ばない方が良い
	typedef unsigned int ui;
	typedef unsigned long long ull;

	const ull MASK30 = (1ull<<30) - 1;
	const ull MASK31 = (1ull<<31) - 1;
	const ull MOD = (1ull<<61) - 1;
	const ull POSITIVISER = MOD * ((1ull<<3) - 1);
	ui base;
	int n;
	vector<ull> pw, hs;

	rolling_hash(){}

	rolling_hash(const string &s, int bs){
		// set base
		base = (ui)bs;
		
		n = s.size();
		hs.assign(n+1, 0);
		pw.assign(n+1, 0);
		hs[0] = 0;
		pw[0] = 1;
		for(int i=0;i<n;i++){
			pw[i+1] = calc_mod(mul(pw[i], base));
			hs[i+1] = calc_mod(mul(hs[i], base) + s[i]); 
		}
	}

	ull hash(int l, int r){
		return calc_mod(hs[r] + POSITIVISER - mul(hs[l], pw[r-l]));
	}

    ull add_hash(int r, int d){
        ull h = hash(0, r);
        ull hh = calc_mod(mul(h, base) + 'a' + d);
        return hh;
    }

	ull mul(ull l, ull r){
		ull lu = l>>31;
		ull ld = l & MASK31;
		ull ru = r>>31;
		ull rd = r & MASK31;
		ull middle_bit = ld * ru + lu * rd;
		return ((lu*ru)<<1) +ld*rd + ((middle_bit & MASK30) << 31) + (middle_bit>>30);
	}

	ull mul(ull l, ui r){
		ull lu = l>>31;
		ull rd = r & MASK31;
		ull middle_bit = lu * rd;
		return (l & MASK31) * rd + ((middle_bit & MASK30)<<31) + (middle_bit>>30);
	}

	ull calc_mod(ull val){
		val = (val & MOD) + (val>>61);
		if(val > MOD) val -= MOD;
		return val;
	}
};

int generate_base(){
	random_device seed_gen;
	mt19937_64 rnd(seed_gen());
	uniform_int_distribution<int> dist(129, INT_MAX);
	int base = dist(rnd);
	return base;
}

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

    ll N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];
    REP(i, N) reverse(S[i].begin(), S[i].end());

    int base = generate_base();
    vector<rolling_hash> R;
    REP(i, N){
        rolling_hash rh(S[i], base);
        R.emplace_back(rh);
    }

    unordered_map<ull, ll> mp;
    REP(i, N){
        ll sz = S[i].size();
        ull h = R[i].hash(0, sz);
        mp[h]++;
    }

    ll res = 0;
    REP(i, N){
        ll sz = S[i].size();
        vl cnt(26, 0);
        REP(j, sz){
            cnt[S[i][j]-'a']++;
        }
        REP(j, sz){
            REP(k, 26){
                if(cnt[k]>0){
                    ull h = R[i].add_hash(j, k);
                    res += mp[h];
                }
            }
            cnt[S[i][j]-'a']--;
        }
    }

    res -= N;
    cout << res << endl;

    return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
a.cc:6:9: error: 'pair' does not name a type
    6 | typedef pair<int, int> pii;
      |         ^~~~
a.cc:7:9: error: 'pair' does not name a type
    7 | typedef pair<ll, ll> pll;
      |         ^~~~
a.cc:8:9: error: 'pair' does not name a type
    8 | typedef pair<double, double> pdd;
      |         ^~~~
a.cc:9:9: error: 'vector' does not name a type
    9 | typedef vector<ll> vl;
      |         ^~~~~~
a.cc:10:9: error: 'vector' does not name a type
   10 | typedef vector<vector<ll>> vvl;
      |         ^~~~~~
a.cc:25:28: error: 'ostream' does not name a type
   25 | template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
      |                            ^~~~~~~
a.cc:28:19: error: 'ostream' does not name a type
   28 | template<class T> ostream& operator << (ostream& os, const vector<T> v){
      |                   ^~~~~~~
a.cc:31:19: error: 'ostream' does not name a type
   31 | template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
      |                   ^~~~~~~
a.cc:35:27: error: variable or field 'debug' declared void
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                           ^~~~~
a.cc:35:33: error: 'vector' was not declared in this scope
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                 ^~~~~~
a.cc:35:40: error: 'vector' was not declared in this scope
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                        ^~~~~~
a.cc:35:48: error: expected primary-expression before '>>' token
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                                ^~
a.cc:35:51: error: 'v' was not declared in this scope
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                                   ^
a.cc:35:56: error: expected primary-expression before 'h'
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                                        ^
a.cc:35:61: error: expected primary-expression before 'w'
   35 | template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
      |                                                             ^
a.cc:37:27: error: variable or field 'debug' declared void
   37 | template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
      |                           ^~~~~
a.cc:37:33: error: 'vector' was not declared in this scope
   37 | template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
      |                                 ^~~~~~
a.cc:37:41: error: expected primary-expression before '>' token
   37 | template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
      |                                         ^
a.cc:37:43: error: 'v' was not declared in this scope
   37 | template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
      |                                           ^
a.cc:37:48: error: expected primary-expression before 'n'
   37 | template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
      |                                                ^
a.cc:54:9: error: 'vector' does not name a type
   54 |         vector<ull> pw, hs;
      |         ^~~~~~
a.cc:58:28: error: 'string' does not name a type
   58 |         rolling_hash(const string &s, int bs){
      |                            ^~~~~~
a.cc: In constructor 'rolling_hash::rolling_hash(const int&, int)':
a.cc:62:23: error: request for member 'size' in 's', which is of non-class type 'const int'
   62 |                 n = s.size();
      |                       ^~~~
a.cc:63:17: error: 'hs' was not declared in this scope; did you mean 's'?
   63 |                 hs.assign(n+1, 0);
      |                 ^~
      |                 s
a.cc:64:17: error: 'pw' was not declared in this scope
   64 |                 pw.assign(n+1, 0);
      |                 ^~
a.cc:69:64: error: invalid types 'const int[int]' for array subscript
   69 |                         hs[i+1] = calc_mod(mul(hs[i], base) + s[i]);
      |                                                                ^
a.cc: In member function 'rolling_hash::ull rolling_hash::hash(int, int)':
a.cc:74:33: error: 'hs' was not declared in this scope
   74 |                 return calc_mod(hs[r] + POSITIVISER - mul(hs[l], pw[r-l]));
      |                                 ^~
a.cc:74:66: error: 'pw' was not declared in this scope
   74 |                 return calc_mod(hs[r] + POSITIVISER - mul(hs[l], pw[r-l]));
      |                                                                  ^~
a.cc: In function 'int generate_base()':
a.cc:107:9: error: 'random_device' was not declared in this scope
  107 |         random_device seed_gen;
      |         ^~~~~~~~~~~~~
a.cc:108:9: error: 'mt19937_64' was not declared in this scope
  108 |         mt19937_64 rnd(seed_gen());
      |         ^~~~~~~~~~
a.cc:109:9: error: 'uniform_int_distribution' was not declared in this scope
  109 |         uniform_int_distribution<int> dist(129, INT_MAX);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:109:34: error: expected primary-expression before 'int'
  109 |         uniform_int_distribution<int> dist(129, INT_MAX);
      |                                  ^~~
a.cc:110:25: error: 'rnd' was not declared in this scope
  110 |         int base = dist(rnd);
      |                         ^~~
a.cc:110:20: error: 'dist' was not declared in this scope
  110 |         int base = dist(rnd);
      |                    ^~~~
a.cc: In function 'int main()':
a.cc:115:5: error: 'cin' was not declared in this scope
  115 |     cin.tie(0);
      |     ^~~
a.cc:116:5: error: 'ios' has not been declared
  116 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:120:5: error: 'vector' was not declared in this scope
  120 |     vector<string> S(N);
      |     ^~~~~~
a.cc:120:12: error: 'string' was not declared in this scope
  120 |     vector<string> S(N);
      |            ^~~~~~
a.cc:120:20: error: 'S' was not declared in this scope
  120 |     vector<string> S(N);
      |                    ^
a.cc:122:15: error: 'reverse' was not declared in this scope
  122 |     REP(i, N) reverse(S[i].begin(), S[i].end());
      |               ^~~~~~~
a.cc:125:24: error: expected primary-expression before '>' token
  125 |     vector<rolling_hash> R;
      |                        ^
a.cc:125:26: error: 'R' was not declared in this scope
  125 |     vector<rolling_hash> R;
      |                          ^
a.cc:131:5: error: 'unordered_map' was not declared in this scope
  131 |     unordered_map<ull, ll> mp;
      |     ^~~~~~~~~~~~~
a.cc:131:22: error: expected primary-expression before ',' token
  131 |     unordered_map<ull, ll> mp;
      |                      ^
a.cc:131:26: error: expected primary-expression before '>' token
  131 |     unordered_map<ull, ll> mp;
      |                          ^
a.cc:131:28: error: 'mp' was not declared in this scope
  131 |     unordered_map<ull, ll> mp;
      |                            ^~
a.cc:141:9: error: 'vl' was not declared in this scope; did you mean 'll'?
  141 |         vl cnt(26, 0);
      |         ^~
      |         ll
a.cc:143:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
  143 |             cnt[S[i][j]-'a']++;
      |             ^~~
      |             int
a.cc:147:20: error: 'cnt' was not declared in this scope; did you mean 'int'?
  147 |                 if(cnt[k]>0){
      |                    ^~~
      |                    int
a.cc:152:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
  152 |             cnt[S[i][j]-'a']--;
      |             ^~~
      |             int
a.cc:157:5: error: 'cout' was not declared in this scope
  157 |     cout << res << endl;
      |     ^~~~
a.cc:157:20: error: 'endl' was not declared in this scope
  157 |     cout << res << endl;
      |                    ^~~~