#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define rep(a,b,c) for(int a=b; a<c; a++)
#define rep2(a,b,c,d) for(ll a=b; a<c; a+=d)
#define repr(a,b,c) for(ll a=b-1; a>c-1; a--)
#define repa(a,b) for(const auto &a: b)
#define multicase() int t; cin>>t; while(t--)
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define valid(c) cout<<(c ? "YES" : "NO")<<endl;
#define valid2(c,a,b) cout<<(c ? a : b)<<endl;
#define ll long long
#define pq_min(a) priority_queue<a, vector<a>, greater<a>>
#define pq_max(a) priority_queue<a>
#define pb push_back
#define mid ((l+r)>>1)
#define flush endl<<flush;
using namespace std;
const ll mod=998244353;
int main(){
fastIO();
int n;
cin>>n;
string s;
set<string> st;
ll t[11][62][62]{};
map<char,int> val;
rep(i,0,26){
val[i+'a']=i;
val[i+'A']=i+26;
}
rep(i,0,10) val[i+'0']=i+52;
rep(i,0,n){
cin>>s;
st.insert(s);
reverse(s.begin(),s.end());
st.insert(s);
}
repa(e,st) t[e.size()][val[e[0]]][val[e.back()]]++;
ll ans=0, aux;
rep(z,3,11){
ll C[62][62][62]{};
rep(i,0,62) rep(j,i,62) rep(k,j,62){
rep(l,0,62){
aux=t[z][i][l]*t[z][j][l];
aux=(aux<mod ? aux : aux%mod);
aux*=t[z][k][l];
aux=(aux<mod ? aux : aux%mod);
C[i][j][k]+=aux;
C[i][j][k]=(C[i][j][k]<mod ? C[i][j][k] : C[i][j][k]%mod);
}
C[i][k][j]=C[j][i][k]=C[j][k][i]=C[k][i][j]=C[k][j][i]=C[i][j][k];
}
rep(i,0,62) rep(j,i,62) rep(k,j,62) rep(l,k,62){
int a[4]={1,1,1,1}, p;
if(i==j) a[1]+=a[0];
if(j==k) a[2]+=a[1];
if(k==l) a[3]+=a[2];
p=24/(a[0]*a[1]*a[2]*a[3]);
aux=C[i][j][k]*C[i][j][l];
aux=(aux<mod ? aux : aux%mod);
aux*=C[i][k][l];
aux=(aux<mod ? aux : aux%mod);
aux*=C[j][k][l];
aux=(aux<mod ? aux : aux%mod);
aux*=p;
aux=(aux<mod ? aux : aux%mod);
ans+=aux;
ans=(ans<mod ? ans : ans%mod);
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
16980 KB |
Output is correct |
2 |
Correct |
143 ms |
17748 KB |
Output is correct |
3 |
Correct |
136 ms |
17744 KB |
Output is correct |
4 |
Correct |
174 ms |
17968 KB |
Output is correct |
5 |
Correct |
136 ms |
17748 KB |
Output is correct |
6 |
Correct |
147 ms |
17744 KB |
Output is correct |
7 |
Correct |
133 ms |
17812 KB |
Output is correct |
8 |
Correct |
134 ms |
17748 KB |
Output is correct |
9 |
Correct |
143 ms |
17744 KB |
Output is correct |
10 |
Correct |
133 ms |
17908 KB |
Output is correct |
11 |
Correct |
134 ms |
17760 KB |
Output is correct |
12 |
Correct |
127 ms |
17740 KB |
Output is correct |
13 |
Correct |
136 ms |
17744 KB |
Output is correct |
14 |
Correct |
136 ms |
17764 KB |
Output is correct |
15 |
Correct |
143 ms |
17748 KB |
Output is correct |
16 |
Correct |
147 ms |
17748 KB |
Output is correct |
17 |
Correct |
155 ms |
17744 KB |
Output is correct |
18 |
Correct |
149 ms |
17752 KB |
Output is correct |
19 |
Correct |
135 ms |
17744 KB |
Output is correct |
20 |
Correct |
168 ms |
18224 KB |
Output is correct |
21 |
Correct |
136 ms |
17748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
16980 KB |
Output is correct |
2 |
Correct |
143 ms |
17748 KB |
Output is correct |
3 |
Correct |
136 ms |
17744 KB |
Output is correct |
4 |
Correct |
174 ms |
17968 KB |
Output is correct |
5 |
Correct |
136 ms |
17748 KB |
Output is correct |
6 |
Correct |
147 ms |
17744 KB |
Output is correct |
7 |
Correct |
133 ms |
17812 KB |
Output is correct |
8 |
Correct |
134 ms |
17748 KB |
Output is correct |
9 |
Correct |
143 ms |
17744 KB |
Output is correct |
10 |
Correct |
133 ms |
17908 KB |
Output is correct |
11 |
Correct |
134 ms |
17760 KB |
Output is correct |
12 |
Correct |
127 ms |
17740 KB |
Output is correct |
13 |
Correct |
136 ms |
17744 KB |
Output is correct |
14 |
Correct |
136 ms |
17764 KB |
Output is correct |
15 |
Correct |
143 ms |
17748 KB |
Output is correct |
16 |
Correct |
147 ms |
17748 KB |
Output is correct |
17 |
Correct |
155 ms |
17744 KB |
Output is correct |
18 |
Correct |
149 ms |
17752 KB |
Output is correct |
19 |
Correct |
135 ms |
17744 KB |
Output is correct |
20 |
Correct |
168 ms |
18224 KB |
Output is correct |
21 |
Correct |
136 ms |
17748 KB |
Output is correct |
22 |
Correct |
136 ms |
18404 KB |
Output is correct |
23 |
Correct |
138 ms |
18516 KB |
Output is correct |
24 |
Correct |
146 ms |
18528 KB |
Output is correct |
25 |
Correct |
139 ms |
18504 KB |
Output is correct |
26 |
Correct |
143 ms |
18512 KB |
Output is correct |
27 |
Correct |
145 ms |
18772 KB |
Output is correct |
28 |
Correct |
136 ms |
18516 KB |
Output is correct |
29 |
Correct |
142 ms |
18548 KB |
Output is correct |
30 |
Correct |
139 ms |
18512 KB |
Output is correct |
31 |
Correct |
145 ms |
18512 KB |
Output is correct |
32 |
Correct |
145 ms |
18484 KB |
Output is correct |
33 |
Correct |
136 ms |
18520 KB |
Output is correct |
34 |
Correct |
135 ms |
18308 KB |
Output is correct |
35 |
Correct |
140 ms |
18352 KB |
Output is correct |
36 |
Correct |
139 ms |
18472 KB |
Output is correct |
37 |
Correct |
124 ms |
18520 KB |
Output is correct |
38 |
Correct |
136 ms |
18512 KB |
Output is correct |
39 |
Correct |
138 ms |
18540 KB |
Output is correct |
40 |
Correct |
121 ms |
18436 KB |
Output is correct |
41 |
Correct |
150 ms |
18444 KB |
Output is correct |
42 |
Correct |
125 ms |
18512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
16980 KB |
Output is correct |
2 |
Correct |
143 ms |
17748 KB |
Output is correct |
3 |
Correct |
136 ms |
17744 KB |
Output is correct |
4 |
Correct |
174 ms |
17968 KB |
Output is correct |
5 |
Correct |
136 ms |
17748 KB |
Output is correct |
6 |
Correct |
147 ms |
17744 KB |
Output is correct |
7 |
Correct |
133 ms |
17812 KB |
Output is correct |
8 |
Correct |
134 ms |
17748 KB |
Output is correct |
9 |
Correct |
143 ms |
17744 KB |
Output is correct |
10 |
Correct |
133 ms |
17908 KB |
Output is correct |
11 |
Correct |
134 ms |
17760 KB |
Output is correct |
12 |
Correct |
127 ms |
17740 KB |
Output is correct |
13 |
Correct |
136 ms |
17744 KB |
Output is correct |
14 |
Correct |
136 ms |
17764 KB |
Output is correct |
15 |
Correct |
143 ms |
17748 KB |
Output is correct |
16 |
Correct |
147 ms |
17748 KB |
Output is correct |
17 |
Correct |
155 ms |
17744 KB |
Output is correct |
18 |
Correct |
149 ms |
17752 KB |
Output is correct |
19 |
Correct |
135 ms |
17744 KB |
Output is correct |
20 |
Correct |
168 ms |
18224 KB |
Output is correct |
21 |
Correct |
136 ms |
17748 KB |
Output is correct |
22 |
Correct |
136 ms |
18404 KB |
Output is correct |
23 |
Correct |
138 ms |
18516 KB |
Output is correct |
24 |
Correct |
146 ms |
18528 KB |
Output is correct |
25 |
Correct |
139 ms |
18504 KB |
Output is correct |
26 |
Correct |
143 ms |
18512 KB |
Output is correct |
27 |
Correct |
145 ms |
18772 KB |
Output is correct |
28 |
Correct |
136 ms |
18516 KB |
Output is correct |
29 |
Correct |
142 ms |
18548 KB |
Output is correct |
30 |
Correct |
139 ms |
18512 KB |
Output is correct |
31 |
Correct |
145 ms |
18512 KB |
Output is correct |
32 |
Correct |
145 ms |
18484 KB |
Output is correct |
33 |
Correct |
136 ms |
18520 KB |
Output is correct |
34 |
Correct |
135 ms |
18308 KB |
Output is correct |
35 |
Correct |
140 ms |
18352 KB |
Output is correct |
36 |
Correct |
139 ms |
18472 KB |
Output is correct |
37 |
Correct |
124 ms |
18520 KB |
Output is correct |
38 |
Correct |
136 ms |
18512 KB |
Output is correct |
39 |
Correct |
138 ms |
18540 KB |
Output is correct |
40 |
Correct |
121 ms |
18436 KB |
Output is correct |
41 |
Correct |
150 ms |
18444 KB |
Output is correct |
42 |
Correct |
125 ms |
18512 KB |
Output is correct |
43 |
Correct |
143 ms |
18512 KB |
Output is correct |
44 |
Correct |
133 ms |
18512 KB |
Output is correct |
45 |
Correct |
166 ms |
18524 KB |
Output is correct |
46 |
Correct |
148 ms |
18724 KB |
Output is correct |
47 |
Correct |
136 ms |
18516 KB |
Output is correct |
48 |
Correct |
137 ms |
18516 KB |
Output is correct |
49 |
Correct |
128 ms |
18728 KB |
Output is correct |
50 |
Correct |
139 ms |
18512 KB |
Output is correct |
51 |
Correct |
138 ms |
18512 KB |
Output is correct |
52 |
Correct |
142 ms |
18516 KB |
Output is correct |
53 |
Correct |
137 ms |
18692 KB |
Output is correct |
54 |
Correct |
146 ms |
18736 KB |
Output is correct |
55 |
Correct |
151 ms |
18516 KB |
Output is correct |
56 |
Correct |
142 ms |
18612 KB |
Output is correct |
57 |
Correct |
146 ms |
18512 KB |
Output is correct |
58 |
Correct |
136 ms |
18512 KB |
Output is correct |
59 |
Correct |
146 ms |
18496 KB |
Output is correct |
60 |
Correct |
130 ms |
18672 KB |
Output is correct |
61 |
Correct |
170 ms |
18516 KB |
Output is correct |
62 |
Correct |
135 ms |
18512 KB |
Output is correct |
63 |
Correct |
145 ms |
18716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
16980 KB |
Output is correct |
2 |
Correct |
143 ms |
17748 KB |
Output is correct |
3 |
Correct |
136 ms |
17744 KB |
Output is correct |
4 |
Correct |
174 ms |
17968 KB |
Output is correct |
5 |
Correct |
136 ms |
17748 KB |
Output is correct |
6 |
Correct |
147 ms |
17744 KB |
Output is correct |
7 |
Correct |
133 ms |
17812 KB |
Output is correct |
8 |
Correct |
134 ms |
17748 KB |
Output is correct |
9 |
Correct |
143 ms |
17744 KB |
Output is correct |
10 |
Correct |
133 ms |
17908 KB |
Output is correct |
11 |
Correct |
134 ms |
17760 KB |
Output is correct |
12 |
Correct |
127 ms |
17740 KB |
Output is correct |
13 |
Correct |
136 ms |
17744 KB |
Output is correct |
14 |
Correct |
136 ms |
17764 KB |
Output is correct |
15 |
Correct |
143 ms |
17748 KB |
Output is correct |
16 |
Correct |
147 ms |
17748 KB |
Output is correct |
17 |
Correct |
155 ms |
17744 KB |
Output is correct |
18 |
Correct |
149 ms |
17752 KB |
Output is correct |
19 |
Correct |
135 ms |
17744 KB |
Output is correct |
20 |
Correct |
168 ms |
18224 KB |
Output is correct |
21 |
Correct |
136 ms |
17748 KB |
Output is correct |
22 |
Correct |
136 ms |
18404 KB |
Output is correct |
23 |
Correct |
138 ms |
18516 KB |
Output is correct |
24 |
Correct |
146 ms |
18528 KB |
Output is correct |
25 |
Correct |
139 ms |
18504 KB |
Output is correct |
26 |
Correct |
143 ms |
18512 KB |
Output is correct |
27 |
Correct |
145 ms |
18772 KB |
Output is correct |
28 |
Correct |
136 ms |
18516 KB |
Output is correct |
29 |
Correct |
142 ms |
18548 KB |
Output is correct |
30 |
Correct |
139 ms |
18512 KB |
Output is correct |
31 |
Correct |
145 ms |
18512 KB |
Output is correct |
32 |
Correct |
145 ms |
18484 KB |
Output is correct |
33 |
Correct |
136 ms |
18520 KB |
Output is correct |
34 |
Correct |
135 ms |
18308 KB |
Output is correct |
35 |
Correct |
140 ms |
18352 KB |
Output is correct |
36 |
Correct |
139 ms |
18472 KB |
Output is correct |
37 |
Correct |
124 ms |
18520 KB |
Output is correct |
38 |
Correct |
136 ms |
18512 KB |
Output is correct |
39 |
Correct |
138 ms |
18540 KB |
Output is correct |
40 |
Correct |
121 ms |
18436 KB |
Output is correct |
41 |
Correct |
150 ms |
18444 KB |
Output is correct |
42 |
Correct |
125 ms |
18512 KB |
Output is correct |
43 |
Correct |
143 ms |
18512 KB |
Output is correct |
44 |
Correct |
133 ms |
18512 KB |
Output is correct |
45 |
Correct |
166 ms |
18524 KB |
Output is correct |
46 |
Correct |
148 ms |
18724 KB |
Output is correct |
47 |
Correct |
136 ms |
18516 KB |
Output is correct |
48 |
Correct |
137 ms |
18516 KB |
Output is correct |
49 |
Correct |
128 ms |
18728 KB |
Output is correct |
50 |
Correct |
139 ms |
18512 KB |
Output is correct |
51 |
Correct |
138 ms |
18512 KB |
Output is correct |
52 |
Correct |
142 ms |
18516 KB |
Output is correct |
53 |
Correct |
137 ms |
18692 KB |
Output is correct |
54 |
Correct |
146 ms |
18736 KB |
Output is correct |
55 |
Correct |
151 ms |
18516 KB |
Output is correct |
56 |
Correct |
142 ms |
18612 KB |
Output is correct |
57 |
Correct |
146 ms |
18512 KB |
Output is correct |
58 |
Correct |
136 ms |
18512 KB |
Output is correct |
59 |
Correct |
146 ms |
18496 KB |
Output is correct |
60 |
Correct |
130 ms |
18672 KB |
Output is correct |
61 |
Correct |
170 ms |
18516 KB |
Output is correct |
62 |
Correct |
135 ms |
18512 KB |
Output is correct |
63 |
Correct |
145 ms |
18716 KB |
Output is correct |
64 |
Correct |
188 ms |
18768 KB |
Output is correct |
65 |
Correct |
171 ms |
18768 KB |
Output is correct |
66 |
Correct |
182 ms |
18768 KB |
Output is correct |
67 |
Correct |
191 ms |
18772 KB |
Output is correct |
68 |
Correct |
189 ms |
18772 KB |
Output is correct |
69 |
Correct |
186 ms |
18908 KB |
Output is correct |
70 |
Correct |
179 ms |
18772 KB |
Output is correct |
71 |
Correct |
193 ms |
18768 KB |
Output is correct |
72 |
Correct |
212 ms |
18756 KB |
Output is correct |
73 |
Correct |
184 ms |
18772 KB |
Output is correct |
74 |
Correct |
198 ms |
18776 KB |
Output is correct |
75 |
Correct |
181 ms |
18704 KB |
Output is correct |
76 |
Correct |
180 ms |
18772 KB |
Output is correct |
77 |
Correct |
215 ms |
18752 KB |
Output is correct |
78 |
Correct |
184 ms |
18768 KB |
Output is correct |
79 |
Correct |
171 ms |
18772 KB |
Output is correct |
80 |
Correct |
221 ms |
18764 KB |
Output is correct |
81 |
Correct |
179 ms |
18772 KB |
Output is correct |
82 |
Correct |
183 ms |
18772 KB |
Output is correct |
83 |
Correct |
175 ms |
18768 KB |
Output is correct |
84 |
Correct |
175 ms |
18868 KB |
Output is correct |