#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
int n;
vector<string>isi[11];
int ganti(char a){
if(a-'A'>=0 && a-'A'<26)return 1+(a-'A');
if(a-'a'>=0 && a-'a'<26)return 27+(a-'a');
return 53+(a-'0');
}
int sum(int a,int b){
a%=mod;
b%=mod;
return (a+b)%mod;
}
int mul(int a,int b){
a%=mod;
b%=mod;
return (a*b)%mod;
}
int permu(int a,int b,int c,int d){
if(a!=b && b!=c && c!=d)return 24;
if(a==b && b!=c && c!=d)return 12;
if(a!=b && b==c && c!=d)return 12;
if(a!=b && b!=c && c==d)return 12;
if(a==b && b!=c && c==d)return 6;
if(a!=b && b==c && c==d)return 4;
if(a==b && b==c && c!=d)return 4;
return 1;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int q=1;q<=n;q++){
string a;
cin>>a;
isi[a.length()].push_back(a);
}
int ans=0;
for(int leng=3;leng<=10;leng++){
set<string>con;
int cnt[63][63];
memset(cnt,0,sizeof cnt);
for(auto r : isi[leng]){
con.insert(r);
reverse(r.begin(),r.end());
con.insert(r);
}
for(auto r : con){
cnt[ganti(r[0])][ganti(r.back())]++;
}
int dp[63][63][63];
for(int q=1;q<=62;q++){
for(int w=1;w<=62;w++){
for(int e=1;e<=62;e++){
dp[q][w][e]=0;
for(int x=1;x<=62;x++){
int hmm=mul(cnt[q][x],mul(cnt[w][x],cnt[e][x]));
dp[q][w][e]=sum(dp[q][w][e],hmm);
}
}
}
}
int tmp=0;
for(int a=1;a<=62;a++){
for(int b=a;b<=62;b++){
for(int c=b;c<=62;c++){
for(int d=c;d<=62;d++){
int hmm=mul(dp[a][b][c],mul(dp[a][b][d],mul(dp[a][c][d],dp[b][c][d])));
hmm=mul(hmm,permu(a,b,c,d));
tmp=sum(tmp,hmm);
}
}
}
}
ans=sum(ans,tmp);
}
cout<<ans<<endl;
}
# | 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... |