#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long ll;
const int MOD = 998244353;
const int L = 11;
const int A = 62;
set<string> st[L];
int n;
ll cnt[A][A], xx[A][A][A];
map<char, int> sc;
int sz;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
set<char> ss;
for (int i=1; i<=n; ++i) {
string s; cin>>s;
st[s.size()].insert(s);
reverse(s.begin(), s.end());
st[s.size()].insert(s);
ss.insert(s[0]), ss.insert(s.back());
}
int i=0;
for (auto c : ss) sc[c]=i++;
ll ans=0;
sz=ss.size();
for (int l=3; l<L; ++l) {
memset(cnt, 0, sizeof(cnt)), memset(xx, 0, sizeof(xx));
for (auto u : st[l]) ++cnt[sc[(int)u[0]]][sc[(int)u.back()]];
for (int i=0; i<sz; ++i) {
for (int j=0; j<sz; ++j) {
for (int k=0; k<sz; ++k) {
vector<int> v={i, j, k};
for (int d=0; d<sz; ++d) {
ll tp=1;
for (auto u : v) tp*=cnt[d][u];
(xx[i][j][k]+=tp);
if (xx[i][j][k] >= MOD) xx[i][j][k]%=MOD;
}
}
}
}
for (int a=0; a<sz; ++a) {
for (int b=a; b<sz; ++b) {
for (int c=b; c<sz; ++c) {
for (int d=c; d<sz; ++d) {
ll x=(xx[a][b][c]*xx[a][b][d])%MOD*xx[a][c][d]%MOD*xx[b][c][d]%MOD;
if (a == d) x*=1;
else if ((a == b && b == c) || (b == c && c == d)) x*=4;
else if (a == b && c == d) x*=6;
else if (a == b || b == c || c == d) x*=12;
else x*=24;
(ans+=x)%=MOD;
}
}
}
}
} cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
16932 KB |
Output is correct |
2 |
Correct |
106 ms |
17488 KB |
Output is correct |
3 |
Correct |
105 ms |
17580 KB |
Output is correct |
4 |
Correct |
110 ms |
17548 KB |
Output is correct |
5 |
Correct |
115 ms |
17492 KB |
Output is correct |
6 |
Correct |
94 ms |
17676 KB |
Output is correct |
7 |
Correct |
100 ms |
17496 KB |
Output is correct |
8 |
Correct |
101 ms |
17592 KB |
Output is correct |
9 |
Correct |
104 ms |
17692 KB |
Output is correct |
10 |
Correct |
94 ms |
17488 KB |
Output is correct |
11 |
Correct |
97 ms |
17460 KB |
Output is correct |
12 |
Correct |
96 ms |
17660 KB |
Output is correct |
13 |
Correct |
112 ms |
17760 KB |
Output is correct |
14 |
Correct |
96 ms |
17680 KB |
Output is correct |
15 |
Correct |
103 ms |
17576 KB |
Output is correct |
16 |
Correct |
90 ms |
17488 KB |
Output is correct |
17 |
Correct |
93 ms |
17492 KB |
Output is correct |
18 |
Correct |
90 ms |
17488 KB |
Output is correct |
19 |
Correct |
96 ms |
17492 KB |
Output is correct |
20 |
Correct |
90 ms |
17656 KB |
Output is correct |
21 |
Correct |
93 ms |
17660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
16932 KB |
Output is correct |
2 |
Correct |
106 ms |
17488 KB |
Output is correct |
3 |
Correct |
105 ms |
17580 KB |
Output is correct |
4 |
Correct |
110 ms |
17548 KB |
Output is correct |
5 |
Correct |
115 ms |
17492 KB |
Output is correct |
6 |
Correct |
94 ms |
17676 KB |
Output is correct |
7 |
Correct |
100 ms |
17496 KB |
Output is correct |
8 |
Correct |
101 ms |
17592 KB |
Output is correct |
9 |
Correct |
104 ms |
17692 KB |
Output is correct |
10 |
Correct |
94 ms |
17488 KB |
Output is correct |
11 |
Correct |
97 ms |
17460 KB |
Output is correct |
12 |
Correct |
96 ms |
17660 KB |
Output is correct |
13 |
Correct |
112 ms |
17760 KB |
Output is correct |
14 |
Correct |
96 ms |
17680 KB |
Output is correct |
15 |
Correct |
103 ms |
17576 KB |
Output is correct |
16 |
Correct |
90 ms |
17488 KB |
Output is correct |
17 |
Correct |
93 ms |
17492 KB |
Output is correct |
18 |
Correct |
90 ms |
17488 KB |
Output is correct |
19 |
Correct |
96 ms |
17492 KB |
Output is correct |
20 |
Correct |
90 ms |
17656 KB |
Output is correct |
21 |
Correct |
93 ms |
17660 KB |
Output is correct |
22 |
Correct |
116 ms |
18256 KB |
Output is correct |
23 |
Correct |
111 ms |
18000 KB |
Output is correct |
24 |
Correct |
106 ms |
18256 KB |
Output is correct |
25 |
Correct |
102 ms |
18236 KB |
Output is correct |
26 |
Correct |
111 ms |
17996 KB |
Output is correct |
27 |
Correct |
104 ms |
18004 KB |
Output is correct |
28 |
Correct |
106 ms |
18228 KB |
Output is correct |
29 |
Correct |
117 ms |
18140 KB |
Output is correct |
30 |
Correct |
103 ms |
18080 KB |
Output is correct |
31 |
Correct |
103 ms |
18484 KB |
Output is correct |
32 |
Correct |
102 ms |
18000 KB |
Output is correct |
33 |
Correct |
105 ms |
18004 KB |
Output is correct |
34 |
Correct |
101 ms |
18204 KB |
Output is correct |
35 |
Correct |
113 ms |
18124 KB |
Output is correct |
36 |
Correct |
101 ms |
18052 KB |
Output is correct |
37 |
Correct |
98 ms |
18000 KB |
Output is correct |
38 |
Correct |
103 ms |
18116 KB |
Output is correct |
39 |
Correct |
105 ms |
18004 KB |
Output is correct |
40 |
Correct |
138 ms |
18416 KB |
Output is correct |
41 |
Correct |
106 ms |
18000 KB |
Output is correct |
42 |
Correct |
114 ms |
18004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
16932 KB |
Output is correct |
2 |
Correct |
106 ms |
17488 KB |
Output is correct |
3 |
Correct |
105 ms |
17580 KB |
Output is correct |
4 |
Correct |
110 ms |
17548 KB |
Output is correct |
5 |
Correct |
115 ms |
17492 KB |
Output is correct |
6 |
Correct |
94 ms |
17676 KB |
Output is correct |
7 |
Correct |
100 ms |
17496 KB |
Output is correct |
8 |
Correct |
101 ms |
17592 KB |
Output is correct |
9 |
Correct |
104 ms |
17692 KB |
Output is correct |
10 |
Correct |
94 ms |
17488 KB |
Output is correct |
11 |
Correct |
97 ms |
17460 KB |
Output is correct |
12 |
Correct |
96 ms |
17660 KB |
Output is correct |
13 |
Correct |
112 ms |
17760 KB |
Output is correct |
14 |
Correct |
96 ms |
17680 KB |
Output is correct |
15 |
Correct |
103 ms |
17576 KB |
Output is correct |
16 |
Correct |
90 ms |
17488 KB |
Output is correct |
17 |
Correct |
93 ms |
17492 KB |
Output is correct |
18 |
Correct |
90 ms |
17488 KB |
Output is correct |
19 |
Correct |
96 ms |
17492 KB |
Output is correct |
20 |
Correct |
90 ms |
17656 KB |
Output is correct |
21 |
Correct |
93 ms |
17660 KB |
Output is correct |
22 |
Correct |
116 ms |
18256 KB |
Output is correct |
23 |
Correct |
111 ms |
18000 KB |
Output is correct |
24 |
Correct |
106 ms |
18256 KB |
Output is correct |
25 |
Correct |
102 ms |
18236 KB |
Output is correct |
26 |
Correct |
111 ms |
17996 KB |
Output is correct |
27 |
Correct |
104 ms |
18004 KB |
Output is correct |
28 |
Correct |
106 ms |
18228 KB |
Output is correct |
29 |
Correct |
117 ms |
18140 KB |
Output is correct |
30 |
Correct |
103 ms |
18080 KB |
Output is correct |
31 |
Correct |
103 ms |
18484 KB |
Output is correct |
32 |
Correct |
102 ms |
18000 KB |
Output is correct |
33 |
Correct |
105 ms |
18004 KB |
Output is correct |
34 |
Correct |
101 ms |
18204 KB |
Output is correct |
35 |
Correct |
113 ms |
18124 KB |
Output is correct |
36 |
Correct |
101 ms |
18052 KB |
Output is correct |
37 |
Correct |
98 ms |
18000 KB |
Output is correct |
38 |
Correct |
103 ms |
18116 KB |
Output is correct |
39 |
Correct |
105 ms |
18004 KB |
Output is correct |
40 |
Correct |
138 ms |
18416 KB |
Output is correct |
41 |
Correct |
106 ms |
18000 KB |
Output is correct |
42 |
Correct |
114 ms |
18004 KB |
Output is correct |
43 |
Correct |
138 ms |
18260 KB |
Output is correct |
44 |
Correct |
137 ms |
18384 KB |
Output is correct |
45 |
Correct |
148 ms |
18260 KB |
Output is correct |
46 |
Correct |
133 ms |
18256 KB |
Output is correct |
47 |
Correct |
149 ms |
18244 KB |
Output is correct |
48 |
Correct |
137 ms |
18372 KB |
Output is correct |
49 |
Correct |
138 ms |
18428 KB |
Output is correct |
50 |
Correct |
146 ms |
18240 KB |
Output is correct |
51 |
Correct |
133 ms |
18428 KB |
Output is correct |
52 |
Correct |
133 ms |
18340 KB |
Output is correct |
53 |
Correct |
129 ms |
18324 KB |
Output is correct |
54 |
Correct |
150 ms |
18440 KB |
Output is correct |
55 |
Correct |
152 ms |
18292 KB |
Output is correct |
56 |
Correct |
142 ms |
18432 KB |
Output is correct |
57 |
Correct |
136 ms |
18260 KB |
Output is correct |
58 |
Correct |
144 ms |
18184 KB |
Output is correct |
59 |
Correct |
137 ms |
18260 KB |
Output is correct |
60 |
Correct |
136 ms |
18384 KB |
Output is correct |
61 |
Correct |
161 ms |
18340 KB |
Output is correct |
62 |
Correct |
130 ms |
18260 KB |
Output is correct |
63 |
Correct |
154 ms |
18308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
16932 KB |
Output is correct |
2 |
Correct |
106 ms |
17488 KB |
Output is correct |
3 |
Correct |
105 ms |
17580 KB |
Output is correct |
4 |
Correct |
110 ms |
17548 KB |
Output is correct |
5 |
Correct |
115 ms |
17492 KB |
Output is correct |
6 |
Correct |
94 ms |
17676 KB |
Output is correct |
7 |
Correct |
100 ms |
17496 KB |
Output is correct |
8 |
Correct |
101 ms |
17592 KB |
Output is correct |
9 |
Correct |
104 ms |
17692 KB |
Output is correct |
10 |
Correct |
94 ms |
17488 KB |
Output is correct |
11 |
Correct |
97 ms |
17460 KB |
Output is correct |
12 |
Correct |
96 ms |
17660 KB |
Output is correct |
13 |
Correct |
112 ms |
17760 KB |
Output is correct |
14 |
Correct |
96 ms |
17680 KB |
Output is correct |
15 |
Correct |
103 ms |
17576 KB |
Output is correct |
16 |
Correct |
90 ms |
17488 KB |
Output is correct |
17 |
Correct |
93 ms |
17492 KB |
Output is correct |
18 |
Correct |
90 ms |
17488 KB |
Output is correct |
19 |
Correct |
96 ms |
17492 KB |
Output is correct |
20 |
Correct |
90 ms |
17656 KB |
Output is correct |
21 |
Correct |
93 ms |
17660 KB |
Output is correct |
22 |
Correct |
116 ms |
18256 KB |
Output is correct |
23 |
Correct |
111 ms |
18000 KB |
Output is correct |
24 |
Correct |
106 ms |
18256 KB |
Output is correct |
25 |
Correct |
102 ms |
18236 KB |
Output is correct |
26 |
Correct |
111 ms |
17996 KB |
Output is correct |
27 |
Correct |
104 ms |
18004 KB |
Output is correct |
28 |
Correct |
106 ms |
18228 KB |
Output is correct |
29 |
Correct |
117 ms |
18140 KB |
Output is correct |
30 |
Correct |
103 ms |
18080 KB |
Output is correct |
31 |
Correct |
103 ms |
18484 KB |
Output is correct |
32 |
Correct |
102 ms |
18000 KB |
Output is correct |
33 |
Correct |
105 ms |
18004 KB |
Output is correct |
34 |
Correct |
101 ms |
18204 KB |
Output is correct |
35 |
Correct |
113 ms |
18124 KB |
Output is correct |
36 |
Correct |
101 ms |
18052 KB |
Output is correct |
37 |
Correct |
98 ms |
18000 KB |
Output is correct |
38 |
Correct |
103 ms |
18116 KB |
Output is correct |
39 |
Correct |
105 ms |
18004 KB |
Output is correct |
40 |
Correct |
138 ms |
18416 KB |
Output is correct |
41 |
Correct |
106 ms |
18000 KB |
Output is correct |
42 |
Correct |
114 ms |
18004 KB |
Output is correct |
43 |
Correct |
138 ms |
18260 KB |
Output is correct |
44 |
Correct |
137 ms |
18384 KB |
Output is correct |
45 |
Correct |
148 ms |
18260 KB |
Output is correct |
46 |
Correct |
133 ms |
18256 KB |
Output is correct |
47 |
Correct |
149 ms |
18244 KB |
Output is correct |
48 |
Correct |
137 ms |
18372 KB |
Output is correct |
49 |
Correct |
138 ms |
18428 KB |
Output is correct |
50 |
Correct |
146 ms |
18240 KB |
Output is correct |
51 |
Correct |
133 ms |
18428 KB |
Output is correct |
52 |
Correct |
133 ms |
18340 KB |
Output is correct |
53 |
Correct |
129 ms |
18324 KB |
Output is correct |
54 |
Correct |
150 ms |
18440 KB |
Output is correct |
55 |
Correct |
152 ms |
18292 KB |
Output is correct |
56 |
Correct |
142 ms |
18432 KB |
Output is correct |
57 |
Correct |
136 ms |
18260 KB |
Output is correct |
58 |
Correct |
144 ms |
18184 KB |
Output is correct |
59 |
Correct |
137 ms |
18260 KB |
Output is correct |
60 |
Correct |
136 ms |
18384 KB |
Output is correct |
61 |
Correct |
161 ms |
18340 KB |
Output is correct |
62 |
Correct |
130 ms |
18260 KB |
Output is correct |
63 |
Correct |
154 ms |
18308 KB |
Output is correct |
64 |
Correct |
515 ms |
18664 KB |
Output is correct |
65 |
Correct |
526 ms |
18688 KB |
Output is correct |
66 |
Correct |
510 ms |
18664 KB |
Output is correct |
67 |
Correct |
524 ms |
18664 KB |
Output is correct |
68 |
Correct |
524 ms |
18880 KB |
Output is correct |
69 |
Correct |
504 ms |
18520 KB |
Output is correct |
70 |
Correct |
520 ms |
18772 KB |
Output is correct |
71 |
Correct |
500 ms |
18768 KB |
Output is correct |
72 |
Correct |
495 ms |
18660 KB |
Output is correct |
73 |
Correct |
520 ms |
18772 KB |
Output is correct |
74 |
Correct |
552 ms |
18768 KB |
Output is correct |
75 |
Correct |
511 ms |
18512 KB |
Output is correct |
76 |
Correct |
522 ms |
18656 KB |
Output is correct |
77 |
Correct |
532 ms |
18768 KB |
Output is correct |
78 |
Correct |
521 ms |
18660 KB |
Output is correct |
79 |
Correct |
542 ms |
18668 KB |
Output is correct |
80 |
Correct |
528 ms |
18668 KB |
Output is correct |
81 |
Correct |
534 ms |
18436 KB |
Output is correct |
82 |
Correct |
595 ms |
18516 KB |
Output is correct |
83 |
Correct |
565 ms |
18668 KB |
Output is correct |
84 |
Correct |
572 ms |
18724 KB |
Output is correct |