#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
int n;
int cnt[15][155][155];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n;
set<string> l;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
l.insert(s);
reverse(s.begin(), s.end());
l.insert(s);
}
vector<char> ch;
for(auto it=l.begin();it!=l.end();it++)
{
string s = *it;
++cnt[s.size()][s.front()][s.back()];
ch.push_back(s.front());
ch.push_back(s.back());
}
sort(ch.begin(), ch.end());
vector<char> aux;
for(auto it : ch)
{
if(aux.empty() || it != aux.back())
{
aux.push_back(it);
}
}
ch = aux;
long long rez = 0;
for(int len=3;len<=10;len++)
{
for(auto a : ch)
{
for(auto b : ch)
{
for(auto c : ch)
{
for(auto d : ch)
{
for(auto e : ch)
{
for(auto f : ch)
{
for(auto g : ch)
{
for(auto h : ch)
{
rez += 1LL * cnt[len][a][b] * cnt[len][b][c] % Mod * cnt[len][c][d] % Mod * cnt[len][e][f] % Mod * cnt[len][f][g] % Mod * cnt[len][g][h] % Mod * cnt[len][a][e] % Mod * cnt[len][b][f] % Mod * cnt[len][c][g] % Mod * cnt[len][d][h] % Mod * cnt[len][d][a] % Mod * cnt[len][h][e] % Mod;
rez %= Mod;
}
}
}
}
}
}
}
}
}
cout<<rez<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |