#include <bits/stdc++.h>
#define SZ 63
using ll = long long;
ll rel[SZ][SZ];
ll tuplas[SZ][SZ][SZ];
ll MOD = 998244353;
std::map<char,int> mapinha;
int cur=0;
int valor(char ch){
if(mapinha.find(ch)!=mapinha.end())return mapinha[ch];
mapinha[ch]=cur;
++cur;
return mapinha[ch];
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int N;
std::cin>>N;
std::map<std::string,bool> mapa[11];
for(int i=0;i!=N;++i){
std::string s;
std::cin >> s;
mapa[s.size()][s]=1;
std::reverse(s.begin(),s.end());
mapa[s.size()][s]=1;
}
ll ans=0;
for(int j=3;j<=10;++j){
for(auto&x:rel)for(auto&y:x)y=0;
for(auto&x:mapa[j]){
rel[valor(x.first[0])][valor(x.first.back())]++;
}
for(int i=0;i!=SZ;++i){
for(int j=i;j!=SZ;++j){
for(int k=j;k!=SZ;++k){
ll tot=0;
for(int u=0;u!=SZ;++u)tot=(tot+((rel[i][u]*rel[j][u]%MOD)*rel[k][u]))%MOD;
tuplas[i][j][k]=tuplas[i][k][j]=tuplas[j][i][k]=tuplas[j][k][i]=tuplas[k][i][j]=tuplas[k][j][i]=tot;
}
}
}
for(int i=0;i!=SZ;++i){
for(int j=i;j!=SZ;++j){
for(int k=j;k!=SZ;++k){
for(int l=k;l!=SZ;++l){
ll peq = (((tuplas[i][j][k]*tuplas[i][k][l]%MOD)*tuplas[k][l][j]%MOD)*tuplas[i][j][l])%MOD;
if(i!=j&&j!=k&&k!=l){
ans=(ans+(24LL*peq))%MOD;
}else {
std::vector<int> arr={i,j,k,l};
do{
ans=(ans+(peq))%MOD;
}while(std::next_permutation(arr.begin(),arr.end()));
}
}
}
}
}
}
std::cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
16784 KB |
Output is correct |
2 |
Correct |
457 ms |
16716 KB |
Output is correct |
3 |
Correct |
451 ms |
16716 KB |
Output is correct |
4 |
Correct |
464 ms |
16764 KB |
Output is correct |
5 |
Correct |
442 ms |
16684 KB |
Output is correct |
6 |
Correct |
446 ms |
16844 KB |
Output is correct |
7 |
Correct |
459 ms |
16672 KB |
Output is correct |
8 |
Correct |
453 ms |
16784 KB |
Output is correct |
9 |
Correct |
440 ms |
16768 KB |
Output is correct |
10 |
Correct |
459 ms |
16800 KB |
Output is correct |
11 |
Correct |
448 ms |
16772 KB |
Output is correct |
12 |
Correct |
438 ms |
16760 KB |
Output is correct |
13 |
Correct |
454 ms |
16892 KB |
Output is correct |
14 |
Correct |
441 ms |
16772 KB |
Output is correct |
15 |
Correct |
447 ms |
16844 KB |
Output is correct |
16 |
Correct |
435 ms |
16760 KB |
Output is correct |
17 |
Correct |
480 ms |
16780 KB |
Output is correct |
18 |
Correct |
442 ms |
16764 KB |
Output is correct |
19 |
Correct |
431 ms |
16712 KB |
Output is correct |
20 |
Correct |
446 ms |
16772 KB |
Output is correct |
21 |
Correct |
473 ms |
16756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
16784 KB |
Output is correct |
2 |
Correct |
457 ms |
16716 KB |
Output is correct |
3 |
Correct |
451 ms |
16716 KB |
Output is correct |
4 |
Correct |
464 ms |
16764 KB |
Output is correct |
5 |
Correct |
442 ms |
16684 KB |
Output is correct |
6 |
Correct |
446 ms |
16844 KB |
Output is correct |
7 |
Correct |
459 ms |
16672 KB |
Output is correct |
8 |
Correct |
453 ms |
16784 KB |
Output is correct |
9 |
Correct |
440 ms |
16768 KB |
Output is correct |
10 |
Correct |
459 ms |
16800 KB |
Output is correct |
11 |
Correct |
448 ms |
16772 KB |
Output is correct |
12 |
Correct |
438 ms |
16760 KB |
Output is correct |
13 |
Correct |
454 ms |
16892 KB |
Output is correct |
14 |
Correct |
441 ms |
16772 KB |
Output is correct |
15 |
Correct |
447 ms |
16844 KB |
Output is correct |
16 |
Correct |
435 ms |
16760 KB |
Output is correct |
17 |
Correct |
480 ms |
16780 KB |
Output is correct |
18 |
Correct |
442 ms |
16764 KB |
Output is correct |
19 |
Correct |
431 ms |
16712 KB |
Output is correct |
20 |
Correct |
446 ms |
16772 KB |
Output is correct |
21 |
Correct |
473 ms |
16756 KB |
Output is correct |
22 |
Correct |
455 ms |
17440 KB |
Output is correct |
23 |
Correct |
460 ms |
17432 KB |
Output is correct |
24 |
Correct |
451 ms |
17444 KB |
Output is correct |
25 |
Correct |
457 ms |
17428 KB |
Output is correct |
26 |
Correct |
457 ms |
17428 KB |
Output is correct |
27 |
Correct |
457 ms |
17424 KB |
Output is correct |
28 |
Correct |
460 ms |
17376 KB |
Output is correct |
29 |
Correct |
454 ms |
17440 KB |
Output is correct |
30 |
Correct |
457 ms |
17428 KB |
Output is correct |
31 |
Correct |
454 ms |
17424 KB |
Output is correct |
32 |
Correct |
453 ms |
17420 KB |
Output is correct |
33 |
Correct |
451 ms |
17424 KB |
Output is correct |
34 |
Correct |
470 ms |
17448 KB |
Output is correct |
35 |
Correct |
453 ms |
17428 KB |
Output is correct |
36 |
Correct |
458 ms |
17436 KB |
Output is correct |
37 |
Correct |
454 ms |
17428 KB |
Output is correct |
38 |
Correct |
480 ms |
17428 KB |
Output is correct |
39 |
Correct |
462 ms |
17448 KB |
Output is correct |
40 |
Correct |
450 ms |
17428 KB |
Output is correct |
41 |
Correct |
460 ms |
17320 KB |
Output is correct |
42 |
Correct |
452 ms |
17484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
16784 KB |
Output is correct |
2 |
Correct |
457 ms |
16716 KB |
Output is correct |
3 |
Correct |
451 ms |
16716 KB |
Output is correct |
4 |
Correct |
464 ms |
16764 KB |
Output is correct |
5 |
Correct |
442 ms |
16684 KB |
Output is correct |
6 |
Correct |
446 ms |
16844 KB |
Output is correct |
7 |
Correct |
459 ms |
16672 KB |
Output is correct |
8 |
Correct |
453 ms |
16784 KB |
Output is correct |
9 |
Correct |
440 ms |
16768 KB |
Output is correct |
10 |
Correct |
459 ms |
16800 KB |
Output is correct |
11 |
Correct |
448 ms |
16772 KB |
Output is correct |
12 |
Correct |
438 ms |
16760 KB |
Output is correct |
13 |
Correct |
454 ms |
16892 KB |
Output is correct |
14 |
Correct |
441 ms |
16772 KB |
Output is correct |
15 |
Correct |
447 ms |
16844 KB |
Output is correct |
16 |
Correct |
435 ms |
16760 KB |
Output is correct |
17 |
Correct |
480 ms |
16780 KB |
Output is correct |
18 |
Correct |
442 ms |
16764 KB |
Output is correct |
19 |
Correct |
431 ms |
16712 KB |
Output is correct |
20 |
Correct |
446 ms |
16772 KB |
Output is correct |
21 |
Correct |
473 ms |
16756 KB |
Output is correct |
22 |
Correct |
455 ms |
17440 KB |
Output is correct |
23 |
Correct |
460 ms |
17432 KB |
Output is correct |
24 |
Correct |
451 ms |
17444 KB |
Output is correct |
25 |
Correct |
457 ms |
17428 KB |
Output is correct |
26 |
Correct |
457 ms |
17428 KB |
Output is correct |
27 |
Correct |
457 ms |
17424 KB |
Output is correct |
28 |
Correct |
460 ms |
17376 KB |
Output is correct |
29 |
Correct |
454 ms |
17440 KB |
Output is correct |
30 |
Correct |
457 ms |
17428 KB |
Output is correct |
31 |
Correct |
454 ms |
17424 KB |
Output is correct |
32 |
Correct |
453 ms |
17420 KB |
Output is correct |
33 |
Correct |
451 ms |
17424 KB |
Output is correct |
34 |
Correct |
470 ms |
17448 KB |
Output is correct |
35 |
Correct |
453 ms |
17428 KB |
Output is correct |
36 |
Correct |
458 ms |
17436 KB |
Output is correct |
37 |
Correct |
454 ms |
17428 KB |
Output is correct |
38 |
Correct |
480 ms |
17428 KB |
Output is correct |
39 |
Correct |
462 ms |
17448 KB |
Output is correct |
40 |
Correct |
450 ms |
17428 KB |
Output is correct |
41 |
Correct |
460 ms |
17320 KB |
Output is correct |
42 |
Correct |
452 ms |
17484 KB |
Output is correct |
43 |
Correct |
445 ms |
17544 KB |
Output is correct |
44 |
Correct |
447 ms |
17656 KB |
Output is correct |
45 |
Correct |
465 ms |
17644 KB |
Output is correct |
46 |
Correct |
454 ms |
17640 KB |
Output is correct |
47 |
Correct |
477 ms |
17644 KB |
Output is correct |
48 |
Correct |
473 ms |
17648 KB |
Output is correct |
49 |
Correct |
467 ms |
17648 KB |
Output is correct |
50 |
Correct |
450 ms |
17548 KB |
Output is correct |
51 |
Correct |
482 ms |
17648 KB |
Output is correct |
52 |
Correct |
461 ms |
17640 KB |
Output is correct |
53 |
Correct |
458 ms |
17652 KB |
Output is correct |
54 |
Correct |
475 ms |
17600 KB |
Output is correct |
55 |
Correct |
474 ms |
17600 KB |
Output is correct |
56 |
Correct |
477 ms |
17644 KB |
Output is correct |
57 |
Correct |
478 ms |
17624 KB |
Output is correct |
58 |
Correct |
472 ms |
17648 KB |
Output is correct |
59 |
Correct |
464 ms |
17648 KB |
Output is correct |
60 |
Correct |
472 ms |
17636 KB |
Output is correct |
61 |
Correct |
474 ms |
17644 KB |
Output is correct |
62 |
Correct |
465 ms |
17636 KB |
Output is correct |
63 |
Correct |
479 ms |
17648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
16784 KB |
Output is correct |
2 |
Correct |
457 ms |
16716 KB |
Output is correct |
3 |
Correct |
451 ms |
16716 KB |
Output is correct |
4 |
Correct |
464 ms |
16764 KB |
Output is correct |
5 |
Correct |
442 ms |
16684 KB |
Output is correct |
6 |
Correct |
446 ms |
16844 KB |
Output is correct |
7 |
Correct |
459 ms |
16672 KB |
Output is correct |
8 |
Correct |
453 ms |
16784 KB |
Output is correct |
9 |
Correct |
440 ms |
16768 KB |
Output is correct |
10 |
Correct |
459 ms |
16800 KB |
Output is correct |
11 |
Correct |
448 ms |
16772 KB |
Output is correct |
12 |
Correct |
438 ms |
16760 KB |
Output is correct |
13 |
Correct |
454 ms |
16892 KB |
Output is correct |
14 |
Correct |
441 ms |
16772 KB |
Output is correct |
15 |
Correct |
447 ms |
16844 KB |
Output is correct |
16 |
Correct |
435 ms |
16760 KB |
Output is correct |
17 |
Correct |
480 ms |
16780 KB |
Output is correct |
18 |
Correct |
442 ms |
16764 KB |
Output is correct |
19 |
Correct |
431 ms |
16712 KB |
Output is correct |
20 |
Correct |
446 ms |
16772 KB |
Output is correct |
21 |
Correct |
473 ms |
16756 KB |
Output is correct |
22 |
Correct |
455 ms |
17440 KB |
Output is correct |
23 |
Correct |
460 ms |
17432 KB |
Output is correct |
24 |
Correct |
451 ms |
17444 KB |
Output is correct |
25 |
Correct |
457 ms |
17428 KB |
Output is correct |
26 |
Correct |
457 ms |
17428 KB |
Output is correct |
27 |
Correct |
457 ms |
17424 KB |
Output is correct |
28 |
Correct |
460 ms |
17376 KB |
Output is correct |
29 |
Correct |
454 ms |
17440 KB |
Output is correct |
30 |
Correct |
457 ms |
17428 KB |
Output is correct |
31 |
Correct |
454 ms |
17424 KB |
Output is correct |
32 |
Correct |
453 ms |
17420 KB |
Output is correct |
33 |
Correct |
451 ms |
17424 KB |
Output is correct |
34 |
Correct |
470 ms |
17448 KB |
Output is correct |
35 |
Correct |
453 ms |
17428 KB |
Output is correct |
36 |
Correct |
458 ms |
17436 KB |
Output is correct |
37 |
Correct |
454 ms |
17428 KB |
Output is correct |
38 |
Correct |
480 ms |
17428 KB |
Output is correct |
39 |
Correct |
462 ms |
17448 KB |
Output is correct |
40 |
Correct |
450 ms |
17428 KB |
Output is correct |
41 |
Correct |
460 ms |
17320 KB |
Output is correct |
42 |
Correct |
452 ms |
17484 KB |
Output is correct |
43 |
Correct |
445 ms |
17544 KB |
Output is correct |
44 |
Correct |
447 ms |
17656 KB |
Output is correct |
45 |
Correct |
465 ms |
17644 KB |
Output is correct |
46 |
Correct |
454 ms |
17640 KB |
Output is correct |
47 |
Correct |
477 ms |
17644 KB |
Output is correct |
48 |
Correct |
473 ms |
17648 KB |
Output is correct |
49 |
Correct |
467 ms |
17648 KB |
Output is correct |
50 |
Correct |
450 ms |
17548 KB |
Output is correct |
51 |
Correct |
482 ms |
17648 KB |
Output is correct |
52 |
Correct |
461 ms |
17640 KB |
Output is correct |
53 |
Correct |
458 ms |
17652 KB |
Output is correct |
54 |
Correct |
475 ms |
17600 KB |
Output is correct |
55 |
Correct |
474 ms |
17600 KB |
Output is correct |
56 |
Correct |
477 ms |
17644 KB |
Output is correct |
57 |
Correct |
478 ms |
17624 KB |
Output is correct |
58 |
Correct |
472 ms |
17648 KB |
Output is correct |
59 |
Correct |
464 ms |
17648 KB |
Output is correct |
60 |
Correct |
472 ms |
17636 KB |
Output is correct |
61 |
Correct |
474 ms |
17644 KB |
Output is correct |
62 |
Correct |
465 ms |
17636 KB |
Output is correct |
63 |
Correct |
479 ms |
17648 KB |
Output is correct |
64 |
Correct |
512 ms |
17888 KB |
Output is correct |
65 |
Correct |
504 ms |
18392 KB |
Output is correct |
66 |
Correct |
493 ms |
18392 KB |
Output is correct |
67 |
Correct |
502 ms |
18392 KB |
Output is correct |
68 |
Correct |
510 ms |
18392 KB |
Output is correct |
69 |
Correct |
511 ms |
18304 KB |
Output is correct |
70 |
Correct |
495 ms |
18396 KB |
Output is correct |
71 |
Correct |
501 ms |
18392 KB |
Output is correct |
72 |
Correct |
481 ms |
18392 KB |
Output is correct |
73 |
Correct |
504 ms |
18388 KB |
Output is correct |
74 |
Correct |
490 ms |
18388 KB |
Output is correct |
75 |
Correct |
495 ms |
18292 KB |
Output is correct |
76 |
Correct |
483 ms |
18388 KB |
Output is correct |
77 |
Correct |
495 ms |
18384 KB |
Output is correct |
78 |
Correct |
505 ms |
18304 KB |
Output is correct |
79 |
Correct |
497 ms |
18396 KB |
Output is correct |
80 |
Correct |
480 ms |
18392 KB |
Output is correct |
81 |
Correct |
491 ms |
18380 KB |
Output is correct |
82 |
Correct |
482 ms |
18384 KB |
Output is correct |
83 |
Correct |
493 ms |
18400 KB |
Output is correct |
84 |
Correct |
503 ms |
18392 KB |
Output is correct |