#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <assert.h>
#include <map>
using namespace std;
typedef long long int ll;
typedef vector <ll> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
const int alfa = 1 + ('z' - 'a');
const int ALFA = 2 * alfa + 10;
const ll mod = 998244353;
int char_to_int(char c){
if (c > 'Z') return c - 'a';
if (c > '9') return alfa + (c - 'A');
return 2 * alfa + (c - '0');
}
int main (){
int n;
cin >> n;
set <string> S;
for (int i = 0; i < n; ++i){
string s;
cin >> s;
S.insert(s);
reverse(s.begin(), s.end());
S.insert(s);
}
vvvi freq(11, vvi(ALFA, vi(ALFA, 0)));
for (string s: S){
freq[s.size()][char_to_int(s.front())][char_to_int(s.back())] += 1;
}
ll ans = 0;
for (int l = 3; l <= 10; ++l){
vvi curr_freq = freq[l];
vvvi C(ALFA, vvi(ALFA, vi(ALFA, 0)));
for (int a = 0; a < ALFA; ++a){
for (int b = 0; b < ALFA; ++b){
for (int c = 0; c < ALFA; ++c){
for (int d = 0; d < ALFA; ++d){
C[a][b][c] += (curr_freq[a][d] * curr_freq[b][d] * curr_freq[c][d]) % mod;
}
C[a][b][c] %= mod;
}
}
}
for (int a = 0; a < ALFA; ++a){
for (int b = 0; b < ALFA; ++b){
for (int c = 0; c < ALFA; ++c){
for (int d = 0; d < ALFA; ++d){
ans += ((C[a][b][c] * C[b][c][d]) % mod) * ((C[c][d][a] * C[d][a][b]) % mod);
}
ans %= mod;
}
}
}
}
cout << ans << endl;
}
/*
3
TURING
SUBMIT
ACCEPT
3
MAN1LA
MAN60S
AN4NAS
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
18256 KB |
Output is correct |
2 |
Correct |
851 ms |
18388 KB |
Output is correct |
3 |
Correct |
836 ms |
18196 KB |
Output is correct |
4 |
Correct |
852 ms |
18120 KB |
Output is correct |
5 |
Correct |
865 ms |
18424 KB |
Output is correct |
6 |
Correct |
907 ms |
18288 KB |
Output is correct |
7 |
Correct |
831 ms |
18136 KB |
Output is correct |
8 |
Correct |
870 ms |
18184 KB |
Output is correct |
9 |
Correct |
852 ms |
18152 KB |
Output is correct |
10 |
Correct |
856 ms |
18456 KB |
Output is correct |
11 |
Correct |
849 ms |
18256 KB |
Output is correct |
12 |
Correct |
912 ms |
18236 KB |
Output is correct |
13 |
Correct |
846 ms |
18200 KB |
Output is correct |
14 |
Correct |
779 ms |
18136 KB |
Output is correct |
15 |
Correct |
773 ms |
18172 KB |
Output is correct |
16 |
Correct |
806 ms |
18184 KB |
Output is correct |
17 |
Correct |
831 ms |
18148 KB |
Output is correct |
18 |
Correct |
766 ms |
18184 KB |
Output is correct |
19 |
Correct |
789 ms |
18396 KB |
Output is correct |
20 |
Correct |
791 ms |
18132 KB |
Output is correct |
21 |
Correct |
788 ms |
18160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
18256 KB |
Output is correct |
2 |
Correct |
851 ms |
18388 KB |
Output is correct |
3 |
Correct |
836 ms |
18196 KB |
Output is correct |
4 |
Correct |
852 ms |
18120 KB |
Output is correct |
5 |
Correct |
865 ms |
18424 KB |
Output is correct |
6 |
Correct |
907 ms |
18288 KB |
Output is correct |
7 |
Correct |
831 ms |
18136 KB |
Output is correct |
8 |
Correct |
870 ms |
18184 KB |
Output is correct |
9 |
Correct |
852 ms |
18152 KB |
Output is correct |
10 |
Correct |
856 ms |
18456 KB |
Output is correct |
11 |
Correct |
849 ms |
18256 KB |
Output is correct |
12 |
Correct |
912 ms |
18236 KB |
Output is correct |
13 |
Correct |
846 ms |
18200 KB |
Output is correct |
14 |
Correct |
779 ms |
18136 KB |
Output is correct |
15 |
Correct |
773 ms |
18172 KB |
Output is correct |
16 |
Correct |
806 ms |
18184 KB |
Output is correct |
17 |
Correct |
831 ms |
18148 KB |
Output is correct |
18 |
Correct |
766 ms |
18184 KB |
Output is correct |
19 |
Correct |
789 ms |
18396 KB |
Output is correct |
20 |
Correct |
791 ms |
18132 KB |
Output is correct |
21 |
Correct |
788 ms |
18160 KB |
Output is correct |
22 |
Correct |
820 ms |
18728 KB |
Output is correct |
23 |
Correct |
823 ms |
18904 KB |
Output is correct |
24 |
Correct |
845 ms |
18776 KB |
Output is correct |
25 |
Correct |
840 ms |
18764 KB |
Output is correct |
26 |
Correct |
816 ms |
18688 KB |
Output is correct |
27 |
Correct |
828 ms |
18660 KB |
Output is correct |
28 |
Correct |
830 ms |
18900 KB |
Output is correct |
29 |
Correct |
775 ms |
18664 KB |
Output is correct |
30 |
Correct |
816 ms |
18764 KB |
Output is correct |
31 |
Correct |
800 ms |
18764 KB |
Output is correct |
32 |
Correct |
770 ms |
18684 KB |
Output is correct |
33 |
Correct |
731 ms |
18656 KB |
Output is correct |
34 |
Correct |
735 ms |
18664 KB |
Output is correct |
35 |
Correct |
764 ms |
18652 KB |
Output is correct |
36 |
Correct |
782 ms |
18768 KB |
Output is correct |
37 |
Correct |
771 ms |
18660 KB |
Output is correct |
38 |
Correct |
777 ms |
18768 KB |
Output is correct |
39 |
Correct |
765 ms |
18780 KB |
Output is correct |
40 |
Correct |
740 ms |
18764 KB |
Output is correct |
41 |
Correct |
761 ms |
18716 KB |
Output is correct |
42 |
Correct |
793 ms |
18764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
18256 KB |
Output is correct |
2 |
Correct |
851 ms |
18388 KB |
Output is correct |
3 |
Correct |
836 ms |
18196 KB |
Output is correct |
4 |
Correct |
852 ms |
18120 KB |
Output is correct |
5 |
Correct |
865 ms |
18424 KB |
Output is correct |
6 |
Correct |
907 ms |
18288 KB |
Output is correct |
7 |
Correct |
831 ms |
18136 KB |
Output is correct |
8 |
Correct |
870 ms |
18184 KB |
Output is correct |
9 |
Correct |
852 ms |
18152 KB |
Output is correct |
10 |
Correct |
856 ms |
18456 KB |
Output is correct |
11 |
Correct |
849 ms |
18256 KB |
Output is correct |
12 |
Correct |
912 ms |
18236 KB |
Output is correct |
13 |
Correct |
846 ms |
18200 KB |
Output is correct |
14 |
Correct |
779 ms |
18136 KB |
Output is correct |
15 |
Correct |
773 ms |
18172 KB |
Output is correct |
16 |
Correct |
806 ms |
18184 KB |
Output is correct |
17 |
Correct |
831 ms |
18148 KB |
Output is correct |
18 |
Correct |
766 ms |
18184 KB |
Output is correct |
19 |
Correct |
789 ms |
18396 KB |
Output is correct |
20 |
Correct |
791 ms |
18132 KB |
Output is correct |
21 |
Correct |
788 ms |
18160 KB |
Output is correct |
22 |
Correct |
820 ms |
18728 KB |
Output is correct |
23 |
Correct |
823 ms |
18904 KB |
Output is correct |
24 |
Correct |
845 ms |
18776 KB |
Output is correct |
25 |
Correct |
840 ms |
18764 KB |
Output is correct |
26 |
Correct |
816 ms |
18688 KB |
Output is correct |
27 |
Correct |
828 ms |
18660 KB |
Output is correct |
28 |
Correct |
830 ms |
18900 KB |
Output is correct |
29 |
Correct |
775 ms |
18664 KB |
Output is correct |
30 |
Correct |
816 ms |
18764 KB |
Output is correct |
31 |
Correct |
800 ms |
18764 KB |
Output is correct |
32 |
Correct |
770 ms |
18684 KB |
Output is correct |
33 |
Correct |
731 ms |
18656 KB |
Output is correct |
34 |
Correct |
735 ms |
18664 KB |
Output is correct |
35 |
Correct |
764 ms |
18652 KB |
Output is correct |
36 |
Correct |
782 ms |
18768 KB |
Output is correct |
37 |
Correct |
771 ms |
18660 KB |
Output is correct |
38 |
Correct |
777 ms |
18768 KB |
Output is correct |
39 |
Correct |
765 ms |
18780 KB |
Output is correct |
40 |
Correct |
740 ms |
18764 KB |
Output is correct |
41 |
Correct |
761 ms |
18716 KB |
Output is correct |
42 |
Correct |
793 ms |
18764 KB |
Output is correct |
43 |
Incorrect |
752 ms |
18944 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
18256 KB |
Output is correct |
2 |
Correct |
851 ms |
18388 KB |
Output is correct |
3 |
Correct |
836 ms |
18196 KB |
Output is correct |
4 |
Correct |
852 ms |
18120 KB |
Output is correct |
5 |
Correct |
865 ms |
18424 KB |
Output is correct |
6 |
Correct |
907 ms |
18288 KB |
Output is correct |
7 |
Correct |
831 ms |
18136 KB |
Output is correct |
8 |
Correct |
870 ms |
18184 KB |
Output is correct |
9 |
Correct |
852 ms |
18152 KB |
Output is correct |
10 |
Correct |
856 ms |
18456 KB |
Output is correct |
11 |
Correct |
849 ms |
18256 KB |
Output is correct |
12 |
Correct |
912 ms |
18236 KB |
Output is correct |
13 |
Correct |
846 ms |
18200 KB |
Output is correct |
14 |
Correct |
779 ms |
18136 KB |
Output is correct |
15 |
Correct |
773 ms |
18172 KB |
Output is correct |
16 |
Correct |
806 ms |
18184 KB |
Output is correct |
17 |
Correct |
831 ms |
18148 KB |
Output is correct |
18 |
Correct |
766 ms |
18184 KB |
Output is correct |
19 |
Correct |
789 ms |
18396 KB |
Output is correct |
20 |
Correct |
791 ms |
18132 KB |
Output is correct |
21 |
Correct |
788 ms |
18160 KB |
Output is correct |
22 |
Correct |
820 ms |
18728 KB |
Output is correct |
23 |
Correct |
823 ms |
18904 KB |
Output is correct |
24 |
Correct |
845 ms |
18776 KB |
Output is correct |
25 |
Correct |
840 ms |
18764 KB |
Output is correct |
26 |
Correct |
816 ms |
18688 KB |
Output is correct |
27 |
Correct |
828 ms |
18660 KB |
Output is correct |
28 |
Correct |
830 ms |
18900 KB |
Output is correct |
29 |
Correct |
775 ms |
18664 KB |
Output is correct |
30 |
Correct |
816 ms |
18764 KB |
Output is correct |
31 |
Correct |
800 ms |
18764 KB |
Output is correct |
32 |
Correct |
770 ms |
18684 KB |
Output is correct |
33 |
Correct |
731 ms |
18656 KB |
Output is correct |
34 |
Correct |
735 ms |
18664 KB |
Output is correct |
35 |
Correct |
764 ms |
18652 KB |
Output is correct |
36 |
Correct |
782 ms |
18768 KB |
Output is correct |
37 |
Correct |
771 ms |
18660 KB |
Output is correct |
38 |
Correct |
777 ms |
18768 KB |
Output is correct |
39 |
Correct |
765 ms |
18780 KB |
Output is correct |
40 |
Correct |
740 ms |
18764 KB |
Output is correct |
41 |
Correct |
761 ms |
18716 KB |
Output is correct |
42 |
Correct |
793 ms |
18764 KB |
Output is correct |
43 |
Incorrect |
752 ms |
18944 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |