#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back
const int N=1e6 + 5 ;
const int inf = 1e18 + 7;
const int mod = 998244353;
int g[11][33][33][33];
int v[11][33][33];
int ans = 0;
int n,m,k;
map<char,int>mps;
vector<int>vs;
int ii(char ch){
return mps[ch];
}
void dfs(int i){
}
int cnt = 0;
void solve(){
cin >> n;
map<string,int>mp;
for(int i = 1;i<=n;i++){
string a;
cin >> a;
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
reverse(all(a));
if(mp[a] == 0){
v[a.size()][ii(a[0])][ii(a[a.size()-1])] += 1;
}
mp[a] += 1;
}
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = 0;j<cnt;j++){
for(int l = 0;l<cnt;l++){
for(int u = 0;u<cnt;u++){
g[sz][j][l][u] += ((v[sz][i][j]*v[sz][i][l]) % mod) * (v[sz][i][u])% mod;
g[sz][j][l][u] %= mod;
}
}
}
}
}
for(int sz = 3;sz<=10;sz++){
for(int i = 0;i<cnt;i++){
for(int j = 0;j<cnt;j++){
for(int l = 0;l<cnt;l++){
for(int u = 0;u<cnt;u++){
ans += (((g[sz][i][j][l] * g[sz][i][j][u])% mod) * g[sz][i][l][u]) % mod * g[sz][j][l][u] % mod;
ans %= mod;
}
}
}
}
}
cout << ans << '\n';
}
/*
*/
signed main()
{
for(int i = 0;i<='p'-'a';i+=1){
mps['a'+i] = cnt++;
}
for(int i = 0;i<='p'-'a';i+=1){
mps['A'+i] = cnt++;
}
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
17024 KB |
Output is correct |
2 |
Correct |
210 ms |
17228 KB |
Output is correct |
3 |
Correct |
198 ms |
16980 KB |
Output is correct |
4 |
Correct |
201 ms |
16980 KB |
Output is correct |
5 |
Correct |
210 ms |
17264 KB |
Output is correct |
6 |
Correct |
198 ms |
16980 KB |
Output is correct |
7 |
Correct |
200 ms |
17184 KB |
Output is correct |
8 |
Correct |
235 ms |
17196 KB |
Output is correct |
9 |
Correct |
203 ms |
17080 KB |
Output is correct |
10 |
Correct |
199 ms |
16948 KB |
Output is correct |
11 |
Correct |
197 ms |
16976 KB |
Output is correct |
12 |
Correct |
198 ms |
17172 KB |
Output is correct |
13 |
Correct |
204 ms |
16976 KB |
Output is correct |
14 |
Correct |
225 ms |
16976 KB |
Output is correct |
15 |
Correct |
210 ms |
17180 KB |
Output is correct |
16 |
Correct |
202 ms |
17176 KB |
Output is correct |
17 |
Correct |
206 ms |
17036 KB |
Output is correct |
18 |
Correct |
198 ms |
16972 KB |
Output is correct |
19 |
Correct |
214 ms |
17224 KB |
Output is correct |
20 |
Correct |
201 ms |
16980 KB |
Output is correct |
21 |
Correct |
204 ms |
17060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
17024 KB |
Output is correct |
2 |
Correct |
210 ms |
17228 KB |
Output is correct |
3 |
Correct |
198 ms |
16980 KB |
Output is correct |
4 |
Correct |
201 ms |
16980 KB |
Output is correct |
5 |
Correct |
210 ms |
17264 KB |
Output is correct |
6 |
Correct |
198 ms |
16980 KB |
Output is correct |
7 |
Correct |
200 ms |
17184 KB |
Output is correct |
8 |
Correct |
235 ms |
17196 KB |
Output is correct |
9 |
Correct |
203 ms |
17080 KB |
Output is correct |
10 |
Correct |
199 ms |
16948 KB |
Output is correct |
11 |
Correct |
197 ms |
16976 KB |
Output is correct |
12 |
Correct |
198 ms |
17172 KB |
Output is correct |
13 |
Correct |
204 ms |
16976 KB |
Output is correct |
14 |
Correct |
225 ms |
16976 KB |
Output is correct |
15 |
Correct |
210 ms |
17180 KB |
Output is correct |
16 |
Correct |
202 ms |
17176 KB |
Output is correct |
17 |
Correct |
206 ms |
17036 KB |
Output is correct |
18 |
Correct |
198 ms |
16972 KB |
Output is correct |
19 |
Correct |
214 ms |
17224 KB |
Output is correct |
20 |
Correct |
201 ms |
16980 KB |
Output is correct |
21 |
Correct |
204 ms |
17060 KB |
Output is correct |
22 |
Correct |
214 ms |
17744 KB |
Output is correct |
23 |
Correct |
205 ms |
17856 KB |
Output is correct |
24 |
Correct |
196 ms |
17864 KB |
Output is correct |
25 |
Correct |
203 ms |
18108 KB |
Output is correct |
26 |
Correct |
203 ms |
17740 KB |
Output is correct |
27 |
Correct |
204 ms |
17748 KB |
Output is correct |
28 |
Correct |
202 ms |
17760 KB |
Output is correct |
29 |
Correct |
249 ms |
17760 KB |
Output is correct |
30 |
Correct |
227 ms |
17752 KB |
Output is correct |
31 |
Correct |
203 ms |
17860 KB |
Output is correct |
32 |
Correct |
202 ms |
17660 KB |
Output is correct |
33 |
Correct |
206 ms |
17692 KB |
Output is correct |
34 |
Correct |
198 ms |
17740 KB |
Output is correct |
35 |
Correct |
206 ms |
17748 KB |
Output is correct |
36 |
Correct |
205 ms |
17760 KB |
Output is correct |
37 |
Correct |
209 ms |
17744 KB |
Output is correct |
38 |
Correct |
200 ms |
17752 KB |
Output is correct |
39 |
Correct |
198 ms |
17684 KB |
Output is correct |
40 |
Correct |
198 ms |
17628 KB |
Output is correct |
41 |
Correct |
221 ms |
17748 KB |
Output is correct |
42 |
Correct |
199 ms |
17748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
17024 KB |
Output is correct |
2 |
Correct |
210 ms |
17228 KB |
Output is correct |
3 |
Correct |
198 ms |
16980 KB |
Output is correct |
4 |
Correct |
201 ms |
16980 KB |
Output is correct |
5 |
Correct |
210 ms |
17264 KB |
Output is correct |
6 |
Correct |
198 ms |
16980 KB |
Output is correct |
7 |
Correct |
200 ms |
17184 KB |
Output is correct |
8 |
Correct |
235 ms |
17196 KB |
Output is correct |
9 |
Correct |
203 ms |
17080 KB |
Output is correct |
10 |
Correct |
199 ms |
16948 KB |
Output is correct |
11 |
Correct |
197 ms |
16976 KB |
Output is correct |
12 |
Correct |
198 ms |
17172 KB |
Output is correct |
13 |
Correct |
204 ms |
16976 KB |
Output is correct |
14 |
Correct |
225 ms |
16976 KB |
Output is correct |
15 |
Correct |
210 ms |
17180 KB |
Output is correct |
16 |
Correct |
202 ms |
17176 KB |
Output is correct |
17 |
Correct |
206 ms |
17036 KB |
Output is correct |
18 |
Correct |
198 ms |
16972 KB |
Output is correct |
19 |
Correct |
214 ms |
17224 KB |
Output is correct |
20 |
Correct |
201 ms |
16980 KB |
Output is correct |
21 |
Correct |
204 ms |
17060 KB |
Output is correct |
22 |
Correct |
214 ms |
17744 KB |
Output is correct |
23 |
Correct |
205 ms |
17856 KB |
Output is correct |
24 |
Correct |
196 ms |
17864 KB |
Output is correct |
25 |
Correct |
203 ms |
18108 KB |
Output is correct |
26 |
Correct |
203 ms |
17740 KB |
Output is correct |
27 |
Correct |
204 ms |
17748 KB |
Output is correct |
28 |
Correct |
202 ms |
17760 KB |
Output is correct |
29 |
Correct |
249 ms |
17760 KB |
Output is correct |
30 |
Correct |
227 ms |
17752 KB |
Output is correct |
31 |
Correct |
203 ms |
17860 KB |
Output is correct |
32 |
Correct |
202 ms |
17660 KB |
Output is correct |
33 |
Correct |
206 ms |
17692 KB |
Output is correct |
34 |
Correct |
198 ms |
17740 KB |
Output is correct |
35 |
Correct |
206 ms |
17748 KB |
Output is correct |
36 |
Correct |
205 ms |
17760 KB |
Output is correct |
37 |
Correct |
209 ms |
17744 KB |
Output is correct |
38 |
Correct |
200 ms |
17752 KB |
Output is correct |
39 |
Correct |
198 ms |
17684 KB |
Output is correct |
40 |
Correct |
198 ms |
17628 KB |
Output is correct |
41 |
Correct |
221 ms |
17748 KB |
Output is correct |
42 |
Correct |
199 ms |
17748 KB |
Output is correct |
43 |
Correct |
213 ms |
18000 KB |
Output is correct |
44 |
Correct |
200 ms |
17996 KB |
Output is correct |
45 |
Correct |
199 ms |
18004 KB |
Output is correct |
46 |
Correct |
201 ms |
17924 KB |
Output is correct |
47 |
Correct |
238 ms |
18004 KB |
Output is correct |
48 |
Correct |
200 ms |
17836 KB |
Output is correct |
49 |
Correct |
236 ms |
18072 KB |
Output is correct |
50 |
Correct |
210 ms |
18256 KB |
Output is correct |
51 |
Correct |
201 ms |
18008 KB |
Output is correct |
52 |
Correct |
199 ms |
18000 KB |
Output is correct |
53 |
Correct |
209 ms |
18004 KB |
Output is correct |
54 |
Correct |
203 ms |
18160 KB |
Output is correct |
55 |
Correct |
204 ms |
17944 KB |
Output is correct |
56 |
Correct |
205 ms |
18084 KB |
Output is correct |
57 |
Correct |
204 ms |
17964 KB |
Output is correct |
58 |
Correct |
213 ms |
18000 KB |
Output is correct |
59 |
Correct |
200 ms |
18000 KB |
Output is correct |
60 |
Correct |
203 ms |
17984 KB |
Output is correct |
61 |
Correct |
206 ms |
17856 KB |
Output is correct |
62 |
Correct |
203 ms |
18036 KB |
Output is correct |
63 |
Correct |
205 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
17024 KB |
Output is correct |
2 |
Correct |
210 ms |
17228 KB |
Output is correct |
3 |
Correct |
198 ms |
16980 KB |
Output is correct |
4 |
Correct |
201 ms |
16980 KB |
Output is correct |
5 |
Correct |
210 ms |
17264 KB |
Output is correct |
6 |
Correct |
198 ms |
16980 KB |
Output is correct |
7 |
Correct |
200 ms |
17184 KB |
Output is correct |
8 |
Correct |
235 ms |
17196 KB |
Output is correct |
9 |
Correct |
203 ms |
17080 KB |
Output is correct |
10 |
Correct |
199 ms |
16948 KB |
Output is correct |
11 |
Correct |
197 ms |
16976 KB |
Output is correct |
12 |
Correct |
198 ms |
17172 KB |
Output is correct |
13 |
Correct |
204 ms |
16976 KB |
Output is correct |
14 |
Correct |
225 ms |
16976 KB |
Output is correct |
15 |
Correct |
210 ms |
17180 KB |
Output is correct |
16 |
Correct |
202 ms |
17176 KB |
Output is correct |
17 |
Correct |
206 ms |
17036 KB |
Output is correct |
18 |
Correct |
198 ms |
16972 KB |
Output is correct |
19 |
Correct |
214 ms |
17224 KB |
Output is correct |
20 |
Correct |
201 ms |
16980 KB |
Output is correct |
21 |
Correct |
204 ms |
17060 KB |
Output is correct |
22 |
Correct |
214 ms |
17744 KB |
Output is correct |
23 |
Correct |
205 ms |
17856 KB |
Output is correct |
24 |
Correct |
196 ms |
17864 KB |
Output is correct |
25 |
Correct |
203 ms |
18108 KB |
Output is correct |
26 |
Correct |
203 ms |
17740 KB |
Output is correct |
27 |
Correct |
204 ms |
17748 KB |
Output is correct |
28 |
Correct |
202 ms |
17760 KB |
Output is correct |
29 |
Correct |
249 ms |
17760 KB |
Output is correct |
30 |
Correct |
227 ms |
17752 KB |
Output is correct |
31 |
Correct |
203 ms |
17860 KB |
Output is correct |
32 |
Correct |
202 ms |
17660 KB |
Output is correct |
33 |
Correct |
206 ms |
17692 KB |
Output is correct |
34 |
Correct |
198 ms |
17740 KB |
Output is correct |
35 |
Correct |
206 ms |
17748 KB |
Output is correct |
36 |
Correct |
205 ms |
17760 KB |
Output is correct |
37 |
Correct |
209 ms |
17744 KB |
Output is correct |
38 |
Correct |
200 ms |
17752 KB |
Output is correct |
39 |
Correct |
198 ms |
17684 KB |
Output is correct |
40 |
Correct |
198 ms |
17628 KB |
Output is correct |
41 |
Correct |
221 ms |
17748 KB |
Output is correct |
42 |
Correct |
199 ms |
17748 KB |
Output is correct |
43 |
Correct |
213 ms |
18000 KB |
Output is correct |
44 |
Correct |
200 ms |
17996 KB |
Output is correct |
45 |
Correct |
199 ms |
18004 KB |
Output is correct |
46 |
Correct |
201 ms |
17924 KB |
Output is correct |
47 |
Correct |
238 ms |
18004 KB |
Output is correct |
48 |
Correct |
200 ms |
17836 KB |
Output is correct |
49 |
Correct |
236 ms |
18072 KB |
Output is correct |
50 |
Correct |
210 ms |
18256 KB |
Output is correct |
51 |
Correct |
201 ms |
18008 KB |
Output is correct |
52 |
Correct |
199 ms |
18000 KB |
Output is correct |
53 |
Correct |
209 ms |
18004 KB |
Output is correct |
54 |
Correct |
203 ms |
18160 KB |
Output is correct |
55 |
Correct |
204 ms |
17944 KB |
Output is correct |
56 |
Correct |
205 ms |
18084 KB |
Output is correct |
57 |
Correct |
204 ms |
17964 KB |
Output is correct |
58 |
Correct |
213 ms |
18000 KB |
Output is correct |
59 |
Correct |
200 ms |
18000 KB |
Output is correct |
60 |
Correct |
203 ms |
17984 KB |
Output is correct |
61 |
Correct |
206 ms |
17856 KB |
Output is correct |
62 |
Correct |
203 ms |
18036 KB |
Output is correct |
63 |
Correct |
205 ms |
18004 KB |
Output is correct |
64 |
Incorrect |
214 ms |
18240 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |