Language: C++

# include <bits/stdc++.h>
using namespace std;
long long nxt[30][30*200005], cnt1[30*200005][30],created[30*200005],sz,cnt[30*200005][30],ans,n;
long long ans1;
string s1[100005];
pair <int, string> s[100005];
void insert(string &s)
{
    int v=0;
    for(int i=0;i<s.size();i++)
    {
        int c=s[i]-'a';
        if(!created[nxt[c][v]])
        {
            nxt[c][v]=++sz;
            created[sz]=1;
        } 
   //     cout<<v<<" "<<s<<endl;
	   for (int j=0; j<26; j++)
        {
            cnt1[v][j]+=cnt[i][j];
        }
        v=nxt[c][v];
        //cout<<v<<endl;
      //  cout<<v<<endl;
       
       // cout<<cnt1[1][0]<<endl;
    }
}
int search(string &tmp)
{
//cout<<tmp<<endl;
    long long ans=0;
    int v=0;
    for(int i=0;i<tmp.size()-1;i++)
    {
        int ty=tmp[i]-'a';
        if(created[nxt[ty][v]])
        {
            v=nxt[ty][v];
        }
        else
        {
            ans=-1;
            return 0;
        }
    }
    
   // cout<<v<<" "<<cnt1[v][tmp[tmp.size()-1]-'a']<<endl;
   // cout<<cnt1[2][2]<<" "<<v<<"  "<<tmp[tmp.size()-1]-'a'<<endl;
    return cnt1[v][tmp[tmp.size()-1]-'a'];
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>s[i].second;
        s[i].first=s[i].second.size();
    }
    sort(s+1, s+n+1);
    for (int i=1; i<=n; i++)
    {
        s1[i]=s[i].second;
        reverse(s1[i].begin(), s1[i].end());
    }
    reverse(s1+1, s1+n+1);
    for (int i=s1[1].size()-1; i>=0; i--)
    {
        for (int j=0; j<26; j++)
        {
            if (s1[1][i]-'a'==j && !cnt[i+1][j])
            cnt[i][j]=1;
            else cnt[i][j]=cnt[i+1][j];
        }
    }
    insert(s1[1]);
    for (int i=0; i<s1[1].size(); i++)
    {
        for (int j=0; j<26; j++)
        {
            cnt[i][j]=0;
        }
    }
    for (int i=2; i<=n; i++)
    {
        ans1+=search(s1[i]);
        //cout<<i<<" "<<ans1<<endl;
        for (int j=s1[i].size()-1; j>=0; j--)
        {
            for (int j1=0; j1<26; j1++)
            {
                if (s1[i][j]-'a'==j1 && !cnt[j+1][j1])
                cnt[j][j1]=1;
                else cnt[j][j1]=cnt[j+1][j1];
            }
        }
        insert(s1[i]);
        for (int j=0; j<s1[i].size(); j++)
        {
        for (int j1=0; j1<26; j1++)
        {
            cnt[j][j1]=0;
        }
        }
    }
    cout<<ans1<<endl;
}

Compiler output:
/tmp/ccF8zR48.o: in function `insert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
a.cc:(.text+0x74): relocation truncated to fit: R_X86_64_PC32 against symbol `created' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x84): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x96): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0xc6): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0xd5): relocation truncated to fit: R_X86_64_PC32 against symbol `created' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x143): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccF8zR48.o
/tmp/ccF8zR48.o: in function `search(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
a.cc:(.text+0x25e): relocation truncated to fit: R_X86_64_PC32 against symbol `created' defined in .bss section in /tmp/ccF8zR48.o
/tmp/ccF8zR48.o: in function `main':
a.cc:(.text+0x335): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x36e): relocation truncated to fit: R_X86_64_PC32 against symbol `s[abi:cxx11]' defined in .bss section in /tmp/ccF8zR48.o
a.cc:(.text+0x3a2): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status