#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
const ll S = 11;
const ll C = 65;
const ll N = 1e5 + 50;
const ll Mod = 998244353;
ll n, m, cnt[C][C], val[C][C][C];
vector<string> vec[S];
int id(char x){
if('a' <= x && x <= 'z') return x - 'a';
if('A' <= x && x <= 'Z') return x - 'A' + 26;
return x - '0' + 52;
}
int main(){
fast_io;
cin >> n;
for(int i = 1; i <= n; i++){
string s; cin >> s;
vec[s.size()].pb(s);
reverse(all(s));
vec[s.size()].pb(s);
}
for(int i = 3; i <= 10; i++){
sort(all(vec[i]));
vec[i].resize(unique(all(vec[i])) - vec[i].begin());
}
ll res = 0;
for(int i = 3; i <= 10; i++){
for(int j = 0; j < C; j++) for(int k = 0; k < C; k++) cnt[j][k] = 0;
for(int j = 0; j < C; j++) for(int k = 0; k < C; k++) for(int c = 0; c < C; c++) val[j][k][c] = 0;
for(auto j: vec[i]) cnt[id(j[0])][id(j[i-1])]++;
for(int a = 0; a < C; a++)
for(int b = a; b < C; b++)
for(int c = b; c < C; c++)
for(int j = 0; j < C; j++)
val[a][b][c] = (val[a][b][c] + (cnt[a][j] * cnt[b][j] % Mod * cnt[c][j])) % Mod;
for(int a = 0; a < C; a++)
for(int b = a; b < C; b++)
for(int c = b; c < C; c++)
for(int d = c; d < C; d++){
ll th = val[a][b][c] * val[a][b][d] % Mod * val[a][c][d] % Mod * val[b][c][d] % Mod;
ll z = 24;
vector<int> ops;
ops.pb(a); ops.pb(b); ops.pb(c); ops.pb(d);
ops.resize(unique(all(ops)) - ops.begin());
if(ops.size() == 1) z = 1;
if(ops.size() == 2){
z = 4;
if(a == b && c == d) z = 6;
}
if(ops.size() == 3) z = 12;
res = (res + th * z) % Mod;
}
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
10208 KB |
Output is correct |
2 |
Correct |
570 ms |
9892 KB |
Output is correct |
3 |
Correct |
573 ms |
10060 KB |
Output is correct |
4 |
Correct |
577 ms |
10044 KB |
Output is correct |
5 |
Correct |
593 ms |
10156 KB |
Output is correct |
6 |
Correct |
565 ms |
10184 KB |
Output is correct |
7 |
Correct |
581 ms |
10128 KB |
Output is correct |
8 |
Correct |
569 ms |
10144 KB |
Output is correct |
9 |
Correct |
568 ms |
10128 KB |
Output is correct |
10 |
Correct |
583 ms |
10268 KB |
Output is correct |
11 |
Correct |
584 ms |
10232 KB |
Output is correct |
12 |
Correct |
575 ms |
10172 KB |
Output is correct |
13 |
Correct |
576 ms |
10168 KB |
Output is correct |
14 |
Correct |
584 ms |
10016 KB |
Output is correct |
15 |
Correct |
622 ms |
9972 KB |
Output is correct |
16 |
Correct |
570 ms |
10108 KB |
Output is correct |
17 |
Correct |
581 ms |
10132 KB |
Output is correct |
18 |
Correct |
578 ms |
10012 KB |
Output is correct |
19 |
Correct |
573 ms |
9960 KB |
Output is correct |
20 |
Correct |
604 ms |
9960 KB |
Output is correct |
21 |
Correct |
590 ms |
10376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
10208 KB |
Output is correct |
2 |
Correct |
570 ms |
9892 KB |
Output is correct |
3 |
Correct |
573 ms |
10060 KB |
Output is correct |
4 |
Correct |
577 ms |
10044 KB |
Output is correct |
5 |
Correct |
593 ms |
10156 KB |
Output is correct |
6 |
Correct |
565 ms |
10184 KB |
Output is correct |
7 |
Correct |
581 ms |
10128 KB |
Output is correct |
8 |
Correct |
569 ms |
10144 KB |
Output is correct |
9 |
Correct |
568 ms |
10128 KB |
Output is correct |
10 |
Correct |
583 ms |
10268 KB |
Output is correct |
11 |
Correct |
584 ms |
10232 KB |
Output is correct |
12 |
Correct |
575 ms |
10172 KB |
Output is correct |
13 |
Correct |
576 ms |
10168 KB |
Output is correct |
14 |
Correct |
584 ms |
10016 KB |
Output is correct |
15 |
Correct |
622 ms |
9972 KB |
Output is correct |
16 |
Correct |
570 ms |
10108 KB |
Output is correct |
17 |
Correct |
581 ms |
10132 KB |
Output is correct |
18 |
Correct |
578 ms |
10012 KB |
Output is correct |
19 |
Correct |
573 ms |
9960 KB |
Output is correct |
20 |
Correct |
604 ms |
9960 KB |
Output is correct |
21 |
Correct |
590 ms |
10376 KB |
Output is correct |
22 |
Correct |
565 ms |
9688 KB |
Output is correct |
23 |
Correct |
567 ms |
9696 KB |
Output is correct |
24 |
Correct |
575 ms |
10132 KB |
Output is correct |
25 |
Correct |
587 ms |
9992 KB |
Output is correct |
26 |
Correct |
569 ms |
9892 KB |
Output is correct |
27 |
Correct |
617 ms |
10012 KB |
Output is correct |
28 |
Correct |
586 ms |
9716 KB |
Output is correct |
29 |
Correct |
574 ms |
9824 KB |
Output is correct |
30 |
Correct |
570 ms |
9748 KB |
Output is correct |
31 |
Correct |
570 ms |
9972 KB |
Output is correct |
32 |
Correct |
573 ms |
9816 KB |
Output is correct |
33 |
Correct |
568 ms |
9712 KB |
Output is correct |
34 |
Correct |
573 ms |
9692 KB |
Output is correct |
35 |
Correct |
574 ms |
10008 KB |
Output is correct |
36 |
Correct |
581 ms |
9928 KB |
Output is correct |
37 |
Correct |
573 ms |
9828 KB |
Output is correct |
38 |
Correct |
590 ms |
9968 KB |
Output is correct |
39 |
Correct |
578 ms |
10104 KB |
Output is correct |
40 |
Correct |
571 ms |
9888 KB |
Output is correct |
41 |
Correct |
570 ms |
9856 KB |
Output is correct |
42 |
Correct |
577 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
10208 KB |
Output is correct |
2 |
Correct |
570 ms |
9892 KB |
Output is correct |
3 |
Correct |
573 ms |
10060 KB |
Output is correct |
4 |
Correct |
577 ms |
10044 KB |
Output is correct |
5 |
Correct |
593 ms |
10156 KB |
Output is correct |
6 |
Correct |
565 ms |
10184 KB |
Output is correct |
7 |
Correct |
581 ms |
10128 KB |
Output is correct |
8 |
Correct |
569 ms |
10144 KB |
Output is correct |
9 |
Correct |
568 ms |
10128 KB |
Output is correct |
10 |
Correct |
583 ms |
10268 KB |
Output is correct |
11 |
Correct |
584 ms |
10232 KB |
Output is correct |
12 |
Correct |
575 ms |
10172 KB |
Output is correct |
13 |
Correct |
576 ms |
10168 KB |
Output is correct |
14 |
Correct |
584 ms |
10016 KB |
Output is correct |
15 |
Correct |
622 ms |
9972 KB |
Output is correct |
16 |
Correct |
570 ms |
10108 KB |
Output is correct |
17 |
Correct |
581 ms |
10132 KB |
Output is correct |
18 |
Correct |
578 ms |
10012 KB |
Output is correct |
19 |
Correct |
573 ms |
9960 KB |
Output is correct |
20 |
Correct |
604 ms |
9960 KB |
Output is correct |
21 |
Correct |
590 ms |
10376 KB |
Output is correct |
22 |
Correct |
565 ms |
9688 KB |
Output is correct |
23 |
Correct |
567 ms |
9696 KB |
Output is correct |
24 |
Correct |
575 ms |
10132 KB |
Output is correct |
25 |
Correct |
587 ms |
9992 KB |
Output is correct |
26 |
Correct |
569 ms |
9892 KB |
Output is correct |
27 |
Correct |
617 ms |
10012 KB |
Output is correct |
28 |
Correct |
586 ms |
9716 KB |
Output is correct |
29 |
Correct |
574 ms |
9824 KB |
Output is correct |
30 |
Correct |
570 ms |
9748 KB |
Output is correct |
31 |
Correct |
570 ms |
9972 KB |
Output is correct |
32 |
Correct |
573 ms |
9816 KB |
Output is correct |
33 |
Correct |
568 ms |
9712 KB |
Output is correct |
34 |
Correct |
573 ms |
9692 KB |
Output is correct |
35 |
Correct |
574 ms |
10008 KB |
Output is correct |
36 |
Correct |
581 ms |
9928 KB |
Output is correct |
37 |
Correct |
573 ms |
9828 KB |
Output is correct |
38 |
Correct |
590 ms |
9968 KB |
Output is correct |
39 |
Correct |
578 ms |
10104 KB |
Output is correct |
40 |
Correct |
571 ms |
9888 KB |
Output is correct |
41 |
Correct |
570 ms |
9856 KB |
Output is correct |
42 |
Correct |
577 ms |
9820 KB |
Output is correct |
43 |
Correct |
564 ms |
9788 KB |
Output is correct |
44 |
Correct |
568 ms |
9688 KB |
Output is correct |
45 |
Correct |
576 ms |
9788 KB |
Output is correct |
46 |
Correct |
577 ms |
9796 KB |
Output is correct |
47 |
Correct |
577 ms |
9564 KB |
Output is correct |
48 |
Correct |
614 ms |
10176 KB |
Output is correct |
49 |
Correct |
576 ms |
10172 KB |
Output is correct |
50 |
Correct |
583 ms |
10192 KB |
Output is correct |
51 |
Correct |
578 ms |
9884 KB |
Output is correct |
52 |
Correct |
574 ms |
9692 KB |
Output is correct |
53 |
Correct |
577 ms |
9604 KB |
Output is correct |
54 |
Correct |
589 ms |
9860 KB |
Output is correct |
55 |
Correct |
581 ms |
9996 KB |
Output is correct |
56 |
Correct |
577 ms |
9560 KB |
Output is correct |
57 |
Correct |
587 ms |
10064 KB |
Output is correct |
58 |
Correct |
565 ms |
10056 KB |
Output is correct |
59 |
Correct |
576 ms |
10040 KB |
Output is correct |
60 |
Correct |
578 ms |
10028 KB |
Output is correct |
61 |
Correct |
566 ms |
9824 KB |
Output is correct |
62 |
Correct |
566 ms |
9924 KB |
Output is correct |
63 |
Correct |
587 ms |
10148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
575 ms |
10208 KB |
Output is correct |
2 |
Correct |
570 ms |
9892 KB |
Output is correct |
3 |
Correct |
573 ms |
10060 KB |
Output is correct |
4 |
Correct |
577 ms |
10044 KB |
Output is correct |
5 |
Correct |
593 ms |
10156 KB |
Output is correct |
6 |
Correct |
565 ms |
10184 KB |
Output is correct |
7 |
Correct |
581 ms |
10128 KB |
Output is correct |
8 |
Correct |
569 ms |
10144 KB |
Output is correct |
9 |
Correct |
568 ms |
10128 KB |
Output is correct |
10 |
Correct |
583 ms |
10268 KB |
Output is correct |
11 |
Correct |
584 ms |
10232 KB |
Output is correct |
12 |
Correct |
575 ms |
10172 KB |
Output is correct |
13 |
Correct |
576 ms |
10168 KB |
Output is correct |
14 |
Correct |
584 ms |
10016 KB |
Output is correct |
15 |
Correct |
622 ms |
9972 KB |
Output is correct |
16 |
Correct |
570 ms |
10108 KB |
Output is correct |
17 |
Correct |
581 ms |
10132 KB |
Output is correct |
18 |
Correct |
578 ms |
10012 KB |
Output is correct |
19 |
Correct |
573 ms |
9960 KB |
Output is correct |
20 |
Correct |
604 ms |
9960 KB |
Output is correct |
21 |
Correct |
590 ms |
10376 KB |
Output is correct |
22 |
Correct |
565 ms |
9688 KB |
Output is correct |
23 |
Correct |
567 ms |
9696 KB |
Output is correct |
24 |
Correct |
575 ms |
10132 KB |
Output is correct |
25 |
Correct |
587 ms |
9992 KB |
Output is correct |
26 |
Correct |
569 ms |
9892 KB |
Output is correct |
27 |
Correct |
617 ms |
10012 KB |
Output is correct |
28 |
Correct |
586 ms |
9716 KB |
Output is correct |
29 |
Correct |
574 ms |
9824 KB |
Output is correct |
30 |
Correct |
570 ms |
9748 KB |
Output is correct |
31 |
Correct |
570 ms |
9972 KB |
Output is correct |
32 |
Correct |
573 ms |
9816 KB |
Output is correct |
33 |
Correct |
568 ms |
9712 KB |
Output is correct |
34 |
Correct |
573 ms |
9692 KB |
Output is correct |
35 |
Correct |
574 ms |
10008 KB |
Output is correct |
36 |
Correct |
581 ms |
9928 KB |
Output is correct |
37 |
Correct |
573 ms |
9828 KB |
Output is correct |
38 |
Correct |
590 ms |
9968 KB |
Output is correct |
39 |
Correct |
578 ms |
10104 KB |
Output is correct |
40 |
Correct |
571 ms |
9888 KB |
Output is correct |
41 |
Correct |
570 ms |
9856 KB |
Output is correct |
42 |
Correct |
577 ms |
9820 KB |
Output is correct |
43 |
Correct |
564 ms |
9788 KB |
Output is correct |
44 |
Correct |
568 ms |
9688 KB |
Output is correct |
45 |
Correct |
576 ms |
9788 KB |
Output is correct |
46 |
Correct |
577 ms |
9796 KB |
Output is correct |
47 |
Correct |
577 ms |
9564 KB |
Output is correct |
48 |
Correct |
614 ms |
10176 KB |
Output is correct |
49 |
Correct |
576 ms |
10172 KB |
Output is correct |
50 |
Correct |
583 ms |
10192 KB |
Output is correct |
51 |
Correct |
578 ms |
9884 KB |
Output is correct |
52 |
Correct |
574 ms |
9692 KB |
Output is correct |
53 |
Correct |
577 ms |
9604 KB |
Output is correct |
54 |
Correct |
589 ms |
9860 KB |
Output is correct |
55 |
Correct |
581 ms |
9996 KB |
Output is correct |
56 |
Correct |
577 ms |
9560 KB |
Output is correct |
57 |
Correct |
587 ms |
10064 KB |
Output is correct |
58 |
Correct |
565 ms |
10056 KB |
Output is correct |
59 |
Correct |
576 ms |
10040 KB |
Output is correct |
60 |
Correct |
578 ms |
10028 KB |
Output is correct |
61 |
Correct |
566 ms |
9824 KB |
Output is correct |
62 |
Correct |
566 ms |
9924 KB |
Output is correct |
63 |
Correct |
587 ms |
10148 KB |
Output is correct |
64 |
Correct |
576 ms |
9860 KB |
Output is correct |
65 |
Correct |
605 ms |
10172 KB |
Output is correct |
66 |
Correct |
569 ms |
9680 KB |
Output is correct |
67 |
Correct |
581 ms |
9660 KB |
Output is correct |
68 |
Correct |
580 ms |
9664 KB |
Output is correct |
69 |
Correct |
574 ms |
9888 KB |
Output is correct |
70 |
Correct |
585 ms |
9924 KB |
Output is correct |
71 |
Correct |
572 ms |
9796 KB |
Output is correct |
72 |
Correct |
565 ms |
9892 KB |
Output is correct |
73 |
Correct |
577 ms |
9768 KB |
Output is correct |
74 |
Correct |
580 ms |
10108 KB |
Output is correct |
75 |
Correct |
570 ms |
9996 KB |
Output is correct |
76 |
Correct |
576 ms |
9920 KB |
Output is correct |
77 |
Correct |
575 ms |
9620 KB |
Output is correct |
78 |
Correct |
577 ms |
10008 KB |
Output is correct |
79 |
Correct |
569 ms |
9788 KB |
Output is correct |
80 |
Correct |
576 ms |
10044 KB |
Output is correct |
81 |
Correct |
579 ms |
10052 KB |
Output is correct |
82 |
Correct |
572 ms |
9928 KB |
Output is correct |
83 |
Correct |
573 ms |
9784 KB |
Output is correct |
84 |
Correct |
580 ms |
10176 KB |
Output is correct |