Language: C++

#include<iostream>
#include<cstring>
using namespace std;
struct Trie{
    int next[26];
    int cnt;
    int type;
    void init(){
        cnt=0;
        memset(next,-1,sizeof next);
    }
}T[1000005];
int dp[100005][26],size[1000005];
int le;
void Insert(string s){
    int p=0,len=s.size();
    for (int i=len-1;i>=0;i--){
        int r=s[i]-'a';
        if(T[p].next[r]==-1){
            T[le].init();
            T[le].type=r;
            T[p].next[r]=le++;
        }
        p=T[p].next[r];
        T[p].cnt++;  
    }
	size[p]++;
}
void dfs(int x){
	for(int i=0,v;i<26;i++){
		v=T[x].next[i];
		if(v==-1) continue;
		dfs(v);
		size[x]+=size[v];
		for(int j=0;j<26;j++){
			dp[x][j]+=dp[v][j];
		}
	}
	dp[x][T[x].type]=size[x];
}
long long query(string s){
	long long xx=0;
    int p=0,len=s.size();
    for (int i=len-1;i>=1;i--) {
        int r=s[i]-'a';
        if(T[p].next[r]==-1) {
            return 0;
        }
        p=T[p].next[r];
    }
   	for(int i=0,v;i<26;i++){
   		v=T[p].next[i];
   		if(v==-1) continue;
   		xx+=dp[v][s[0]-'a'];
	}
	return xx;
}
string s[100005];
int n;
long long ans;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    T[0].init();
    le=1;
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>s[i];
    	Insert(s[i]);
	}
	dfs(0);
    for(int i=1;i<=n;i++){
    	ans+=query(s[i]);
	}
	cout<<ans-n;
}


Compiler output:
a.cc: In function 'void Insert(std::string)':
a.cc:27:9: error: reference to 'size' is ambiguous
   27 |         size[p]++;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:20: note:                 'int size [1000005]'
   13 | int dp[100005][26],size[1000005];
      |                    ^~~~
a.cc: In function 'void dfs(int)':
a.cc:34:17: error: reference to 'size' is ambiguous
   34 |                 size[x]+=size[v];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:20: note:                 'int size [1000005]'
   13 | int dp[100005][26],size[1000005];
      |                    ^~~~
a.cc:34:26: error: reference to 'size' is ambiguous
   34 |                 size[x]+=size[v];
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:20: note:                 'int size [1000005]'
   13 | int dp[100005][26],size[1000005];
      |                    ^~~~
a.cc:39:26: error: reference to 'size' is ambiguous
   39 |         dp[x][T[x].type]=size[x];
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:20: note:                 'int size [1000005]'
   13 | int dp[100005][26],size[1000005];
      |                    ^~~~