Language: C++

    #include<cstdio>
    #include<map>
    #include<cstring>
    #include<iostream>
    using namespace std;
    #define N 1000005
    #define ll long long
    int n,ans,tmp[N];
    int ch[N][30],fa[N],sum[N][30],cnt[N],tot=1,end[N];
//    void update(int x){
////    	for(int i=0;i<26;i++) sum[x][i]=0;
//    	for(int i=0;i<26;i++){
//    		int y=ch[x][i];
//    		if(!y) continue;
//    		sum[x][i]+=cnt[y];
//    		for(int j=0;j<26;j++)
//    			sum[x][j]+=sum[y][j];
//    	}
//    }
    void insert(string s){
    	int len=s.length(),cur=1;
    	for(int i=0;i<len;i++){
    		int y=ch[cur][s[i]-'a'];
    		if(!y) y=ch[cur][s[i]-'a']=++tot,fa[y]=cur;
    		cur=ch[cur][s[i]-'a'];
    		cnt[cur]++;
    	}
    	end[cur]++;
//    	while(cur){
//    		update(cur);
//			cur=fa[cur];
//		}
    }
    void pushdown(int x){
    	for(int i=0;i<26;i++){
    		int y=ch[x][i];
    		if(!y) continue;
    		pushdown(y);
//    		sum[x][i]+=cnt[y];
			if(end[y]) sum[x][i]+=end[y];
    		for(int j=0;j<26;j++)
    			sum[x][j]+=sum[y][j];
    	}
	}
//    void print(int x){
//    	printf("%d\n",x);
//    	for(int i=0;i<26;i++){
//    		if(sum[x][i]) printf("%c %d\n",'a'+i,sum[x][i]);
//		}
//		for(int i=0;i<26;i++)
//			if(ch[x][i]) print(ch[x][i]);
//	}
    void calc(string s){
    	int cur=1,len=s.length();
    	for(int i=0;i<26;i++) tmp[i]=0;
    	for(int i=0;i<len;i++)
    		tmp[s[i]-'a']++;
    	
    	for(int i=0;i<len;i++){
    		if(!ch[cur][s[i]-'a']) return;
    		for(int j=0;j<26;j++)
				if(tmp[j])
    				ans+=end[ch[cur][j]];
    		tmp[s[i]-'a']--;
    		cur=ch[cur][s[i]-'a'];
		}
//		cout<<s<<" "<<sum[cur][s[len-1]-'a']<<endl; 
		ans+=sum[cur][s[len-1]-'a'];
	}
//    char s[N];
    string S[N];
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++){
    		cin>>S[i];
    		int len=S[i].length();
    		for(int j=0;j<len-j-1;j++)
    			swap(S[i][j],S[i][len-j-1]);
//    		cout<<"insert "<<S[i]<<endl;
    		insert(S[i]);
    	}
//    	pushdown(1);
//    	print(1);
//    	puts("");
    	for(int i=1;i<=n;i++)
    		calc(S[i]);
    	printf("%d",ans-n);
    }

Compiler output:
a.cc: In function 'void insert(std::string)':
a.cc:28:9: error: reference to 'end' is ambiguous
   28 |         end[cur]++;
      |         ^~~
In file included from /usr/include/c++/14/map:65,
                 from a.cc:2:
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/stl_map.h:62,
                 from /usr/include/c++/14/map:63:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:9:49: note:                 'int end [1000005]'
    9 |     int ch[N][30],fa[N],sum[N][30],cnt[N],tot=1,end[N];
      |                                                 ^~~
a.cc: In function 'void pushdown(int)':
a.cc:40:28: error: reference to 'end' is ambiguous
   40 |                         if(end[y]) sum[x][i]+=end[y];
      |                            ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:9:49: note:                 'int end [1000005]'
    9 |     int ch[N][30],fa[N],sum[N][30],cnt[N],tot=1,end[N];
      |                                                 ^~~
a.cc:40:47: error: reference to 'end' is ambiguous
   40 |                         if(end[y]) sum[x][i]+=end[y];
      |                                               ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:9:49: note:                 'int end [1000005]'
    9 |     int ch[N][30],fa[N],sum[N][30],cnt[N],tot=1,end[N];
      |                                                 ^~~
a.cc: In function 'void calc(std::string)':
a.cc:63:38: error: reference to 'end' is ambiguous
   63 |                                 ans+=end[ch[cur][j]];
      |                                      ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:9:49: note:                 'int end [1000005]'
    9 |     int ch[N][30],fa[N],sum[N][30],cnt[N],tot=1,end[N];
      |                                                 ^~~