#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)2e18
#define _ <<' '<<
#define nl '\n'
const int mod = 998244353, N = 62;
int c[N][N], d[N][N][N];
int f(char ch){
if(ch >= 'a' and ch <= 'z') return ch - 'a';
if(ch >= 'A' and ch <= 'Z') return ch - 'A' + 26;
return ch - '0' + 52;
}
int solve(set<string> st){
for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) for(int k = 0; k < N; k++) c[i][j] = d[i][j][k] = 0;
for(string s : st){
c[f(s[0])][f(s.back())]++;
}
for(int w = 0; w < N; w++){
for(int x = 0; x < N; x++){
for(int y = 0; y < N; y++){
for(int z = 0; z < N; z++){
d[x][y][z] += c[w][x] * c[w][y] % mod * c[w][z];
d[x][y][z] %= mod;
}
}
}
}
int ans = 0;
for(int w = 0; w < N; w++){
for(int x = 0; x < N; x++){
for(int y = 0; y < N; y++){
for(int z = 0; z < N; z++){
ans += d[w][x][y] * d[w][x][z] % mod * d[w][y][z] % mod * d[x][y][z];
ans %= mod;
}
}
}
}
return ans;
}
void solve(){
int n;
cin>>n;
set<string> st[11];
for(int i = 0; i < n; i++){
string s;
cin>>s;
st[s.size()].insert(s);
reverse(s.begin(), s.end());
st[s.size()].insert(s);
}
int ans = 0;
for(int i = 3; i <= 10; i++){
ans += solve(st[i]);
ans %= mod;
}
cout<<ans<<nl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);cout.tie(NULL);
int t = 1;
//cin>>t;
while(t--) solve();
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... |