#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int) 1e5 + 7;
const int SIGMA = 62;
const int LEN = 11;
const int M = 998244353;
int cnt[SIGMA][SIGMA];
int dp[SIGMA][SIGMA][SIGMA];
vector<pair<int, int>> info[LEN];
int n, l;
int add(int a, int b) {
a += b;
if (a >= M) {
return a - M;
}
if (a < 0) {
return a + M;
}
return a;
}
void addup(int &a, int b) {
a = add(a, b);
}
int mul(int a, int b) {
return (ll) a * b % M;
}
int mul(int a, int b, int c) {
return mul(a, mul(b, c));
}
int mul(int a, int b, int c, int d) {
return mul(a, mul(b, c, d));
}
int decode(char ch) {
if ('a' <= ch && ch <= 'z') {
return ch - 'a';
} else if ('A' <= ch && ch <= 'Z') {
return 26 + ch - 'A';
} else if ('0' <= ch && ch <= '9') {
return 26 + 26 + ch - '0';
}
assert(0);
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen("input", "r", stdin);
cin >> n;
set<string> words;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
string revs = s;
reverse(revs.begin(), revs.end());
words.insert(s);
words.insert(revs);
}
for (auto &it : words) {
info[(int) it.size()].push_back({decode(it[0]), decode(it.back())});
}
int sol = 0;
for (int len = 3; len <= 10; len++) {
for (int i = 0; i < SIGMA; i++) {
for (int j = 0; j < SIGMA; j++) {
cnt[i][j] = 0;
}
}
for (auto &it : info[len]) {
cnt[it.first][it.second]++;
}
for (int a = 0; a < SIGMA; a++) {
for (int b = 0; b < SIGMA; b++) {
for (int c = 0; c < SIGMA; c++) {
dp[a][b][c] = 0;
}
}
}
for (int a = 0; a < SIGMA; a++) {
for (int b = a; b < SIGMA; b++) {
for (int c = b; c < SIGMA; c++) {
for (int d = 0; d < SIGMA; d++) {
addup(dp[a][b][c], mul(cnt[d][a], cnt[d][b], cnt[d][c]));
}
}
}
}
{ /// 1 unique value
for (int a = 0; a < SIGMA; a++) {
addup(sol, mul(dp[a][a][a], dp[a][a][a], dp[a][a][a], dp[a][a][a]));
}
}
{ /// 2 unique values
int aux = 0;
for (int a = 0; a < SIGMA; a++) {
for (int b = a + 1; b < SIGMA; b++) {
addup(aux, mul(dp[a][a][b], dp[a][a][b], dp[a][b][b], dp[a][b][b]));
}
}
addup(sol, mul(aux, 6));
aux = 0;
for (int a = 0; a < SIGMA; a++) {
for (int b = a + 1; b < SIGMA; b++) {
addup(aux, mul(dp[a][a][a], dp[a][a][b], dp[a][a][b], dp[a][a][b]));
addup(aux, mul(dp[b][b][b], dp[a][b][b], dp[a][b][b], dp[a][b][b]));
}
}
addup(sol, mul(aux, 4));
}
{ /// 3 unique values
int aux = 0;
for (int a = 0; a < SIGMA; a++) {
for (int b = a + 1; b < SIGMA; b++) {
for (int c = b + 1; c < SIGMA; c++) {
addup(aux, mul(dp[a][b][c], dp[a][b][c], dp[a][c][c], dp[b][c][c]));
addup(aux, mul(dp[a][b][c], dp[a][b][c], dp[a][a][c], dp[a][a][b]));
addup(aux, mul(dp[a][b][c], dp[a][b][c], dp[a][b][b], dp[b][b][c]));
}
}
}
addup(sol, mul(aux, 12));
}
{ /// 4 unique values
int aux = 0;
for (int a = 0; a < SIGMA; a++) {
for (int b = a + 1; b < SIGMA; b++) {
for (int c = b + 1; c < SIGMA; c++) {
for (int d = c + 1; d < SIGMA; d++) {
addup(aux, mul(dp[a][b][c], dp[a][b][d], dp[a][c][d], dp[b][c][d]));
}
}
}
}
addup(sol, mul(aux, 24));
}
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
18096 KB |
Output is correct |
2 |
Correct |
203 ms |
18280 KB |
Output is correct |
3 |
Correct |
221 ms |
18380 KB |
Output is correct |
4 |
Correct |
225 ms |
18188 KB |
Output is correct |
5 |
Correct |
201 ms |
18356 KB |
Output is correct |
6 |
Correct |
208 ms |
18436 KB |
Output is correct |
7 |
Correct |
202 ms |
18196 KB |
Output is correct |
8 |
Correct |
199 ms |
18428 KB |
Output is correct |
9 |
Correct |
207 ms |
18236 KB |
Output is correct |
10 |
Correct |
197 ms |
18160 KB |
Output is correct |
11 |
Correct |
202 ms |
18088 KB |
Output is correct |
12 |
Correct |
208 ms |
18196 KB |
Output is correct |
13 |
Correct |
208 ms |
18224 KB |
Output is correct |
14 |
Correct |
203 ms |
18104 KB |
Output is correct |
15 |
Correct |
210 ms |
18184 KB |
Output is correct |
16 |
Correct |
200 ms |
18376 KB |
Output is correct |
17 |
Correct |
218 ms |
18456 KB |
Output is correct |
18 |
Correct |
235 ms |
18536 KB |
Output is correct |
19 |
Correct |
206 ms |
18452 KB |
Output is correct |
20 |
Correct |
201 ms |
18460 KB |
Output is correct |
21 |
Correct |
211 ms |
18228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
18096 KB |
Output is correct |
2 |
Correct |
203 ms |
18280 KB |
Output is correct |
3 |
Correct |
221 ms |
18380 KB |
Output is correct |
4 |
Correct |
225 ms |
18188 KB |
Output is correct |
5 |
Correct |
201 ms |
18356 KB |
Output is correct |
6 |
Correct |
208 ms |
18436 KB |
Output is correct |
7 |
Correct |
202 ms |
18196 KB |
Output is correct |
8 |
Correct |
199 ms |
18428 KB |
Output is correct |
9 |
Correct |
207 ms |
18236 KB |
Output is correct |
10 |
Correct |
197 ms |
18160 KB |
Output is correct |
11 |
Correct |
202 ms |
18088 KB |
Output is correct |
12 |
Correct |
208 ms |
18196 KB |
Output is correct |
13 |
Correct |
208 ms |
18224 KB |
Output is correct |
14 |
Correct |
203 ms |
18104 KB |
Output is correct |
15 |
Correct |
210 ms |
18184 KB |
Output is correct |
16 |
Correct |
200 ms |
18376 KB |
Output is correct |
17 |
Correct |
218 ms |
18456 KB |
Output is correct |
18 |
Correct |
235 ms |
18536 KB |
Output is correct |
19 |
Correct |
206 ms |
18452 KB |
Output is correct |
20 |
Correct |
201 ms |
18460 KB |
Output is correct |
21 |
Correct |
211 ms |
18228 KB |
Output is correct |
22 |
Correct |
203 ms |
18876 KB |
Output is correct |
23 |
Correct |
210 ms |
18996 KB |
Output is correct |
24 |
Correct |
201 ms |
18996 KB |
Output is correct |
25 |
Correct |
218 ms |
18792 KB |
Output is correct |
26 |
Correct |
209 ms |
18776 KB |
Output is correct |
27 |
Correct |
200 ms |
19084 KB |
Output is correct |
28 |
Correct |
207 ms |
19096 KB |
Output is correct |
29 |
Correct |
205 ms |
18984 KB |
Output is correct |
30 |
Correct |
202 ms |
18784 KB |
Output is correct |
31 |
Correct |
215 ms |
18984 KB |
Output is correct |
32 |
Correct |
231 ms |
19064 KB |
Output is correct |
33 |
Correct |
209 ms |
18960 KB |
Output is correct |
34 |
Correct |
200 ms |
19016 KB |
Output is correct |
35 |
Correct |
234 ms |
18788 KB |
Output is correct |
36 |
Correct |
203 ms |
19224 KB |
Output is correct |
37 |
Correct |
209 ms |
18984 KB |
Output is correct |
38 |
Correct |
209 ms |
18956 KB |
Output is correct |
39 |
Correct |
203 ms |
19008 KB |
Output is correct |
40 |
Correct |
198 ms |
18832 KB |
Output is correct |
41 |
Correct |
202 ms |
18980 KB |
Output is correct |
42 |
Correct |
205 ms |
18752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
18096 KB |
Output is correct |
2 |
Correct |
203 ms |
18280 KB |
Output is correct |
3 |
Correct |
221 ms |
18380 KB |
Output is correct |
4 |
Correct |
225 ms |
18188 KB |
Output is correct |
5 |
Correct |
201 ms |
18356 KB |
Output is correct |
6 |
Correct |
208 ms |
18436 KB |
Output is correct |
7 |
Correct |
202 ms |
18196 KB |
Output is correct |
8 |
Correct |
199 ms |
18428 KB |
Output is correct |
9 |
Correct |
207 ms |
18236 KB |
Output is correct |
10 |
Correct |
197 ms |
18160 KB |
Output is correct |
11 |
Correct |
202 ms |
18088 KB |
Output is correct |
12 |
Correct |
208 ms |
18196 KB |
Output is correct |
13 |
Correct |
208 ms |
18224 KB |
Output is correct |
14 |
Correct |
203 ms |
18104 KB |
Output is correct |
15 |
Correct |
210 ms |
18184 KB |
Output is correct |
16 |
Correct |
200 ms |
18376 KB |
Output is correct |
17 |
Correct |
218 ms |
18456 KB |
Output is correct |
18 |
Correct |
235 ms |
18536 KB |
Output is correct |
19 |
Correct |
206 ms |
18452 KB |
Output is correct |
20 |
Correct |
201 ms |
18460 KB |
Output is correct |
21 |
Correct |
211 ms |
18228 KB |
Output is correct |
22 |
Correct |
203 ms |
18876 KB |
Output is correct |
23 |
Correct |
210 ms |
18996 KB |
Output is correct |
24 |
Correct |
201 ms |
18996 KB |
Output is correct |
25 |
Correct |
218 ms |
18792 KB |
Output is correct |
26 |
Correct |
209 ms |
18776 KB |
Output is correct |
27 |
Correct |
200 ms |
19084 KB |
Output is correct |
28 |
Correct |
207 ms |
19096 KB |
Output is correct |
29 |
Correct |
205 ms |
18984 KB |
Output is correct |
30 |
Correct |
202 ms |
18784 KB |
Output is correct |
31 |
Correct |
215 ms |
18984 KB |
Output is correct |
32 |
Correct |
231 ms |
19064 KB |
Output is correct |
33 |
Correct |
209 ms |
18960 KB |
Output is correct |
34 |
Correct |
200 ms |
19016 KB |
Output is correct |
35 |
Correct |
234 ms |
18788 KB |
Output is correct |
36 |
Correct |
203 ms |
19224 KB |
Output is correct |
37 |
Correct |
209 ms |
18984 KB |
Output is correct |
38 |
Correct |
209 ms |
18956 KB |
Output is correct |
39 |
Correct |
203 ms |
19008 KB |
Output is correct |
40 |
Correct |
198 ms |
18832 KB |
Output is correct |
41 |
Correct |
202 ms |
18980 KB |
Output is correct |
42 |
Correct |
205 ms |
18752 KB |
Output is correct |
43 |
Correct |
208 ms |
19384 KB |
Output is correct |
44 |
Correct |
205 ms |
19412 KB |
Output is correct |
45 |
Correct |
198 ms |
19032 KB |
Output is correct |
46 |
Correct |
201 ms |
18948 KB |
Output is correct |
47 |
Correct |
219 ms |
19052 KB |
Output is correct |
48 |
Correct |
220 ms |
19076 KB |
Output is correct |
49 |
Correct |
204 ms |
19196 KB |
Output is correct |
50 |
Correct |
217 ms |
19060 KB |
Output is correct |
51 |
Correct |
218 ms |
19024 KB |
Output is correct |
52 |
Correct |
200 ms |
19016 KB |
Output is correct |
53 |
Correct |
213 ms |
19284 KB |
Output is correct |
54 |
Correct |
210 ms |
18996 KB |
Output is correct |
55 |
Correct |
207 ms |
19248 KB |
Output is correct |
56 |
Correct |
226 ms |
19116 KB |
Output is correct |
57 |
Correct |
240 ms |
18960 KB |
Output is correct |
58 |
Correct |
209 ms |
18948 KB |
Output is correct |
59 |
Correct |
210 ms |
19204 KB |
Output is correct |
60 |
Correct |
226 ms |
19036 KB |
Output is correct |
61 |
Correct |
203 ms |
19108 KB |
Output is correct |
62 |
Correct |
234 ms |
19100 KB |
Output is correct |
63 |
Correct |
253 ms |
19100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
18096 KB |
Output is correct |
2 |
Correct |
203 ms |
18280 KB |
Output is correct |
3 |
Correct |
221 ms |
18380 KB |
Output is correct |
4 |
Correct |
225 ms |
18188 KB |
Output is correct |
5 |
Correct |
201 ms |
18356 KB |
Output is correct |
6 |
Correct |
208 ms |
18436 KB |
Output is correct |
7 |
Correct |
202 ms |
18196 KB |
Output is correct |
8 |
Correct |
199 ms |
18428 KB |
Output is correct |
9 |
Correct |
207 ms |
18236 KB |
Output is correct |
10 |
Correct |
197 ms |
18160 KB |
Output is correct |
11 |
Correct |
202 ms |
18088 KB |
Output is correct |
12 |
Correct |
208 ms |
18196 KB |
Output is correct |
13 |
Correct |
208 ms |
18224 KB |
Output is correct |
14 |
Correct |
203 ms |
18104 KB |
Output is correct |
15 |
Correct |
210 ms |
18184 KB |
Output is correct |
16 |
Correct |
200 ms |
18376 KB |
Output is correct |
17 |
Correct |
218 ms |
18456 KB |
Output is correct |
18 |
Correct |
235 ms |
18536 KB |
Output is correct |
19 |
Correct |
206 ms |
18452 KB |
Output is correct |
20 |
Correct |
201 ms |
18460 KB |
Output is correct |
21 |
Correct |
211 ms |
18228 KB |
Output is correct |
22 |
Correct |
203 ms |
18876 KB |
Output is correct |
23 |
Correct |
210 ms |
18996 KB |
Output is correct |
24 |
Correct |
201 ms |
18996 KB |
Output is correct |
25 |
Correct |
218 ms |
18792 KB |
Output is correct |
26 |
Correct |
209 ms |
18776 KB |
Output is correct |
27 |
Correct |
200 ms |
19084 KB |
Output is correct |
28 |
Correct |
207 ms |
19096 KB |
Output is correct |
29 |
Correct |
205 ms |
18984 KB |
Output is correct |
30 |
Correct |
202 ms |
18784 KB |
Output is correct |
31 |
Correct |
215 ms |
18984 KB |
Output is correct |
32 |
Correct |
231 ms |
19064 KB |
Output is correct |
33 |
Correct |
209 ms |
18960 KB |
Output is correct |
34 |
Correct |
200 ms |
19016 KB |
Output is correct |
35 |
Correct |
234 ms |
18788 KB |
Output is correct |
36 |
Correct |
203 ms |
19224 KB |
Output is correct |
37 |
Correct |
209 ms |
18984 KB |
Output is correct |
38 |
Correct |
209 ms |
18956 KB |
Output is correct |
39 |
Correct |
203 ms |
19008 KB |
Output is correct |
40 |
Correct |
198 ms |
18832 KB |
Output is correct |
41 |
Correct |
202 ms |
18980 KB |
Output is correct |
42 |
Correct |
205 ms |
18752 KB |
Output is correct |
43 |
Correct |
208 ms |
19384 KB |
Output is correct |
44 |
Correct |
205 ms |
19412 KB |
Output is correct |
45 |
Correct |
198 ms |
19032 KB |
Output is correct |
46 |
Correct |
201 ms |
18948 KB |
Output is correct |
47 |
Correct |
219 ms |
19052 KB |
Output is correct |
48 |
Correct |
220 ms |
19076 KB |
Output is correct |
49 |
Correct |
204 ms |
19196 KB |
Output is correct |
50 |
Correct |
217 ms |
19060 KB |
Output is correct |
51 |
Correct |
218 ms |
19024 KB |
Output is correct |
52 |
Correct |
200 ms |
19016 KB |
Output is correct |
53 |
Correct |
213 ms |
19284 KB |
Output is correct |
54 |
Correct |
210 ms |
18996 KB |
Output is correct |
55 |
Correct |
207 ms |
19248 KB |
Output is correct |
56 |
Correct |
226 ms |
19116 KB |
Output is correct |
57 |
Correct |
240 ms |
18960 KB |
Output is correct |
58 |
Correct |
209 ms |
18948 KB |
Output is correct |
59 |
Correct |
210 ms |
19204 KB |
Output is correct |
60 |
Correct |
226 ms |
19036 KB |
Output is correct |
61 |
Correct |
203 ms |
19108 KB |
Output is correct |
62 |
Correct |
234 ms |
19100 KB |
Output is correct |
63 |
Correct |
253 ms |
19100 KB |
Output is correct |
64 |
Correct |
231 ms |
19220 KB |
Output is correct |
65 |
Correct |
243 ms |
19336 KB |
Output is correct |
66 |
Correct |
237 ms |
19560 KB |
Output is correct |
67 |
Correct |
264 ms |
19292 KB |
Output is correct |
68 |
Correct |
223 ms |
19312 KB |
Output is correct |
69 |
Correct |
235 ms |
19252 KB |
Output is correct |
70 |
Correct |
244 ms |
19312 KB |
Output is correct |
71 |
Correct |
231 ms |
19492 KB |
Output is correct |
72 |
Correct |
234 ms |
19248 KB |
Output is correct |
73 |
Correct |
234 ms |
19368 KB |
Output is correct |
74 |
Correct |
240 ms |
19544 KB |
Output is correct |
75 |
Correct |
256 ms |
19244 KB |
Output is correct |
76 |
Correct |
236 ms |
19676 KB |
Output is correct |
77 |
Correct |
228 ms |
19356 KB |
Output is correct |
78 |
Correct |
231 ms |
19304 KB |
Output is correct |
79 |
Correct |
258 ms |
19364 KB |
Output is correct |
80 |
Correct |
242 ms |
19564 KB |
Output is correct |
81 |
Correct |
230 ms |
19200 KB |
Output is correct |
82 |
Correct |
244 ms |
19372 KB |
Output is correct |
83 |
Correct |
237 ms |
19500 KB |
Output is correct |
84 |
Correct |
234 ms |
19184 KB |
Output is correct |