This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* not my code (obviously i don't code like this wtf) */
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char, int> mp;
int c[11][62][62][62];
int prod[11][62][62][62];
int aa[11][63][63];
const int mod = 998244353;
const int msq = mod * mod;
inline int mul(int x, int y){
if((x*y)>mod) return x*y%mod;
return x*y;
}
void solve(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int cnt=0;
for(int i='a'; i<='z'; i++) mp[i]=cnt++;
for(int i='A'; i<='Z'; i++) mp[i]=cnt++;
for(int i='0'; i<='9'; i++) mp[i]=cnt++;
int n; cin>>n;
vector<string> s(n), x;
for(auto &i: s){
cin >> i;
string x = i;
reverse(x.begin(), x.end());
if(x<i) i=x;
}
sort(s.begin(), s.end());
for(int i=0; i<n; i++){
if(i==0||s[i]!=s[i-1]) x.push_back(s[i]);
}
memset(aa, 0, sizeof aa);
memset(c, 0, sizeof c);
s=x;
n = s.size();
for(int i=0; i<n; i++){
string x=s[i];
reverse(x.begin(), x.end());
if(x==s[i]) aa[x.size()][mp[x[0]]][mp[x.back()]]++;
else aa[x.size()][mp[x[0]]][mp[x.back()]]++, aa[x.size()][mp[x.back()]][mp[x[0]]]++;
}
for(int i=3; i<=10; i++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
for(int j=0; j<62; j++){
if ((c[i][a][b][cc] += aa[i][a][j] * aa[i][b][j] * aa[i][cc][j]) >= msq) c[i][a][b][cc] -= msq;
}
c[i][a][b][cc] %= mod;
}
}
}
}
int ans=0;
for(int i=3; i<=10; i++){
for(int a=0; a<62; a++){
for(int b=a; b<62; b++){
for(int cc=b; cc<62; cc++){
for(int d=cc; d<62; d++){
int val = 0;
if(d==a) val = 291154603;
else if(d==b) val=166374059;
else if(cc==a) val= 166374059;
else if(b==a && d==cc) val=748683265;
else if(d==cc || b==a) val= 499122177;
else if(cc==b) val = 499122177;
else val=1;
if (val != 1) {
if ((ans += val * mul(mul(c[i][a][b][cc], c[i][a][b][d]), mul(c[i][b][cc][d], c[i][a][cc][d]))) >= msq) ans -= msq;
} else {
if ((ans += mul(c[i][a][b][cc], c[i][a][b][d]) * mul(c[i][b][cc][d], c[i][a][cc][d])) >= msq) ans -= msq;
}
}
ans %= mod;
}
}
}
}
ans = (ans * 24) % mod;
cout<<ans<<'\n';
}
signed main() {
int t = 1;
#ifdef galen_colin_local
cin >> t;
#endif
while (t--) solve();
}
# | 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... |