#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define debug(x) cerr<<#x<<" "<<x<<endl;
ll mod = 998244353;
const int N = 1e6+23, S= 33;
ll ans=0;
ll num[S][S][S];
ll cnt[S][S];
set<string> st[11];
int n;
ll power(ll a, ll b){
ll ans=1;
a%=mod;
while(b){
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
int get(char c){
if(c>='a' && c<='p'){
int t=c-'a';
return t;
}
if(c>='A' && c<='P'){
int t=c-'A';
t+=16;
return t;
}
exit(0);
}
int main()
{
fast_io
cin>>n;
for (int i=0; i<n; i++){
string s; cin>>s;
st[s.size()].insert(s);
reverse(all(s));
st[s.size()].insert(s);
}
for (int i=3; i<=10; i++){
memset(num, 0, sizeof(num));
memset(cnt, 0, sizeof(cnt));
for (string s : st[i]){
char c=s.back();
int t=get(c);
c=s[0];
int r=get(c);
cnt[r][t]++;
}
for (int x=0; x<S; x++) for (int a=0; a<S; a++) for (int b=0; b<S; b++) for (int c=0; c<S; c++)num[a][b][c]=(num[a][b][c]+cnt[x][a]*cnt[x][b]%mod*cnt[x][c]%mod)%mod;
for (int a=0; a<S; a++) for (int b=0; b<S; b++) for (int c=0; c<S; c++) for (int d=0; d<S; d++) ans=(ans+ num[a][b][c]*num[a][b][d]%mod*num[a][c][d]%mod*num[b][c][d]%mod)%mod;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
15956 KB |
Output is correct |
2 |
Correct |
332 ms |
15948 KB |
Output is correct |
3 |
Correct |
331 ms |
16072 KB |
Output is correct |
4 |
Correct |
361 ms |
16064 KB |
Output is correct |
5 |
Correct |
345 ms |
15956 KB |
Output is correct |
6 |
Correct |
361 ms |
15992 KB |
Output is correct |
7 |
Correct |
333 ms |
16084 KB |
Output is correct |
8 |
Correct |
356 ms |
16076 KB |
Output is correct |
9 |
Correct |
365 ms |
15932 KB |
Output is correct |
10 |
Correct |
371 ms |
15960 KB |
Output is correct |
11 |
Correct |
346 ms |
16076 KB |
Output is correct |
12 |
Correct |
349 ms |
15928 KB |
Output is correct |
13 |
Correct |
330 ms |
15924 KB |
Output is correct |
14 |
Correct |
351 ms |
16080 KB |
Output is correct |
15 |
Correct |
349 ms |
16084 KB |
Output is correct |
16 |
Correct |
343 ms |
16212 KB |
Output is correct |
17 |
Correct |
336 ms |
15988 KB |
Output is correct |
18 |
Correct |
343 ms |
16208 KB |
Output is correct |
19 |
Correct |
335 ms |
15952 KB |
Output is correct |
20 |
Correct |
343 ms |
16080 KB |
Output is correct |
21 |
Correct |
340 ms |
16064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
15956 KB |
Output is correct |
2 |
Correct |
332 ms |
15948 KB |
Output is correct |
3 |
Correct |
331 ms |
16072 KB |
Output is correct |
4 |
Correct |
361 ms |
16064 KB |
Output is correct |
5 |
Correct |
345 ms |
15956 KB |
Output is correct |
6 |
Correct |
361 ms |
15992 KB |
Output is correct |
7 |
Correct |
333 ms |
16084 KB |
Output is correct |
8 |
Correct |
356 ms |
16076 KB |
Output is correct |
9 |
Correct |
365 ms |
15932 KB |
Output is correct |
10 |
Correct |
371 ms |
15960 KB |
Output is correct |
11 |
Correct |
346 ms |
16076 KB |
Output is correct |
12 |
Correct |
349 ms |
15928 KB |
Output is correct |
13 |
Correct |
330 ms |
15924 KB |
Output is correct |
14 |
Correct |
351 ms |
16080 KB |
Output is correct |
15 |
Correct |
349 ms |
16084 KB |
Output is correct |
16 |
Correct |
343 ms |
16212 KB |
Output is correct |
17 |
Correct |
336 ms |
15988 KB |
Output is correct |
18 |
Correct |
343 ms |
16208 KB |
Output is correct |
19 |
Correct |
335 ms |
15952 KB |
Output is correct |
20 |
Correct |
343 ms |
16080 KB |
Output is correct |
21 |
Correct |
340 ms |
16064 KB |
Output is correct |
22 |
Correct |
340 ms |
16656 KB |
Output is correct |
23 |
Correct |
358 ms |
16464 KB |
Output is correct |
24 |
Correct |
340 ms |
16468 KB |
Output is correct |
25 |
Correct |
339 ms |
16464 KB |
Output is correct |
26 |
Correct |
361 ms |
16640 KB |
Output is correct |
27 |
Correct |
357 ms |
16496 KB |
Output is correct |
28 |
Correct |
354 ms |
16644 KB |
Output is correct |
29 |
Correct |
383 ms |
16656 KB |
Output is correct |
30 |
Correct |
374 ms |
16644 KB |
Output is correct |
31 |
Correct |
363 ms |
16640 KB |
Output is correct |
32 |
Correct |
361 ms |
16468 KB |
Output is correct |
33 |
Correct |
349 ms |
16724 KB |
Output is correct |
34 |
Correct |
376 ms |
16644 KB |
Output is correct |
35 |
Correct |
354 ms |
16708 KB |
Output is correct |
36 |
Correct |
369 ms |
16404 KB |
Output is correct |
37 |
Correct |
360 ms |
16724 KB |
Output is correct |
38 |
Correct |
352 ms |
16468 KB |
Output is correct |
39 |
Correct |
362 ms |
16800 KB |
Output is correct |
40 |
Correct |
350 ms |
16648 KB |
Output is correct |
41 |
Correct |
343 ms |
16392 KB |
Output is correct |
42 |
Correct |
340 ms |
16464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
15956 KB |
Output is correct |
2 |
Correct |
332 ms |
15948 KB |
Output is correct |
3 |
Correct |
331 ms |
16072 KB |
Output is correct |
4 |
Correct |
361 ms |
16064 KB |
Output is correct |
5 |
Correct |
345 ms |
15956 KB |
Output is correct |
6 |
Correct |
361 ms |
15992 KB |
Output is correct |
7 |
Correct |
333 ms |
16084 KB |
Output is correct |
8 |
Correct |
356 ms |
16076 KB |
Output is correct |
9 |
Correct |
365 ms |
15932 KB |
Output is correct |
10 |
Correct |
371 ms |
15960 KB |
Output is correct |
11 |
Correct |
346 ms |
16076 KB |
Output is correct |
12 |
Correct |
349 ms |
15928 KB |
Output is correct |
13 |
Correct |
330 ms |
15924 KB |
Output is correct |
14 |
Correct |
351 ms |
16080 KB |
Output is correct |
15 |
Correct |
349 ms |
16084 KB |
Output is correct |
16 |
Correct |
343 ms |
16212 KB |
Output is correct |
17 |
Correct |
336 ms |
15988 KB |
Output is correct |
18 |
Correct |
343 ms |
16208 KB |
Output is correct |
19 |
Correct |
335 ms |
15952 KB |
Output is correct |
20 |
Correct |
343 ms |
16080 KB |
Output is correct |
21 |
Correct |
340 ms |
16064 KB |
Output is correct |
22 |
Correct |
340 ms |
16656 KB |
Output is correct |
23 |
Correct |
358 ms |
16464 KB |
Output is correct |
24 |
Correct |
340 ms |
16468 KB |
Output is correct |
25 |
Correct |
339 ms |
16464 KB |
Output is correct |
26 |
Correct |
361 ms |
16640 KB |
Output is correct |
27 |
Correct |
357 ms |
16496 KB |
Output is correct |
28 |
Correct |
354 ms |
16644 KB |
Output is correct |
29 |
Correct |
383 ms |
16656 KB |
Output is correct |
30 |
Correct |
374 ms |
16644 KB |
Output is correct |
31 |
Correct |
363 ms |
16640 KB |
Output is correct |
32 |
Correct |
361 ms |
16468 KB |
Output is correct |
33 |
Correct |
349 ms |
16724 KB |
Output is correct |
34 |
Correct |
376 ms |
16644 KB |
Output is correct |
35 |
Correct |
354 ms |
16708 KB |
Output is correct |
36 |
Correct |
369 ms |
16404 KB |
Output is correct |
37 |
Correct |
360 ms |
16724 KB |
Output is correct |
38 |
Correct |
352 ms |
16468 KB |
Output is correct |
39 |
Correct |
362 ms |
16800 KB |
Output is correct |
40 |
Correct |
350 ms |
16648 KB |
Output is correct |
41 |
Correct |
343 ms |
16392 KB |
Output is correct |
42 |
Correct |
340 ms |
16464 KB |
Output is correct |
43 |
Correct |
394 ms |
16840 KB |
Output is correct |
44 |
Correct |
395 ms |
16844 KB |
Output is correct |
45 |
Correct |
426 ms |
16720 KB |
Output is correct |
46 |
Correct |
389 ms |
16728 KB |
Output is correct |
47 |
Correct |
410 ms |
16976 KB |
Output is correct |
48 |
Correct |
403 ms |
16596 KB |
Output is correct |
49 |
Correct |
403 ms |
16840 KB |
Output is correct |
50 |
Correct |
399 ms |
16984 KB |
Output is correct |
51 |
Correct |
412 ms |
16816 KB |
Output is correct |
52 |
Correct |
395 ms |
16724 KB |
Output is correct |
53 |
Correct |
402 ms |
16832 KB |
Output is correct |
54 |
Correct |
407 ms |
16976 KB |
Output is correct |
55 |
Correct |
416 ms |
16716 KB |
Output is correct |
56 |
Correct |
417 ms |
16836 KB |
Output is correct |
57 |
Correct |
397 ms |
16724 KB |
Output is correct |
58 |
Correct |
403 ms |
16724 KB |
Output is correct |
59 |
Correct |
402 ms |
16820 KB |
Output is correct |
60 |
Correct |
415 ms |
16848 KB |
Output is correct |
61 |
Correct |
429 ms |
16860 KB |
Output is correct |
62 |
Correct |
407 ms |
16820 KB |
Output is correct |
63 |
Correct |
401 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
15956 KB |
Output is correct |
2 |
Correct |
332 ms |
15948 KB |
Output is correct |
3 |
Correct |
331 ms |
16072 KB |
Output is correct |
4 |
Correct |
361 ms |
16064 KB |
Output is correct |
5 |
Correct |
345 ms |
15956 KB |
Output is correct |
6 |
Correct |
361 ms |
15992 KB |
Output is correct |
7 |
Correct |
333 ms |
16084 KB |
Output is correct |
8 |
Correct |
356 ms |
16076 KB |
Output is correct |
9 |
Correct |
365 ms |
15932 KB |
Output is correct |
10 |
Correct |
371 ms |
15960 KB |
Output is correct |
11 |
Correct |
346 ms |
16076 KB |
Output is correct |
12 |
Correct |
349 ms |
15928 KB |
Output is correct |
13 |
Correct |
330 ms |
15924 KB |
Output is correct |
14 |
Correct |
351 ms |
16080 KB |
Output is correct |
15 |
Correct |
349 ms |
16084 KB |
Output is correct |
16 |
Correct |
343 ms |
16212 KB |
Output is correct |
17 |
Correct |
336 ms |
15988 KB |
Output is correct |
18 |
Correct |
343 ms |
16208 KB |
Output is correct |
19 |
Correct |
335 ms |
15952 KB |
Output is correct |
20 |
Correct |
343 ms |
16080 KB |
Output is correct |
21 |
Correct |
340 ms |
16064 KB |
Output is correct |
22 |
Correct |
340 ms |
16656 KB |
Output is correct |
23 |
Correct |
358 ms |
16464 KB |
Output is correct |
24 |
Correct |
340 ms |
16468 KB |
Output is correct |
25 |
Correct |
339 ms |
16464 KB |
Output is correct |
26 |
Correct |
361 ms |
16640 KB |
Output is correct |
27 |
Correct |
357 ms |
16496 KB |
Output is correct |
28 |
Correct |
354 ms |
16644 KB |
Output is correct |
29 |
Correct |
383 ms |
16656 KB |
Output is correct |
30 |
Correct |
374 ms |
16644 KB |
Output is correct |
31 |
Correct |
363 ms |
16640 KB |
Output is correct |
32 |
Correct |
361 ms |
16468 KB |
Output is correct |
33 |
Correct |
349 ms |
16724 KB |
Output is correct |
34 |
Correct |
376 ms |
16644 KB |
Output is correct |
35 |
Correct |
354 ms |
16708 KB |
Output is correct |
36 |
Correct |
369 ms |
16404 KB |
Output is correct |
37 |
Correct |
360 ms |
16724 KB |
Output is correct |
38 |
Correct |
352 ms |
16468 KB |
Output is correct |
39 |
Correct |
362 ms |
16800 KB |
Output is correct |
40 |
Correct |
350 ms |
16648 KB |
Output is correct |
41 |
Correct |
343 ms |
16392 KB |
Output is correct |
42 |
Correct |
340 ms |
16464 KB |
Output is correct |
43 |
Correct |
394 ms |
16840 KB |
Output is correct |
44 |
Correct |
395 ms |
16844 KB |
Output is correct |
45 |
Correct |
426 ms |
16720 KB |
Output is correct |
46 |
Correct |
389 ms |
16728 KB |
Output is correct |
47 |
Correct |
410 ms |
16976 KB |
Output is correct |
48 |
Correct |
403 ms |
16596 KB |
Output is correct |
49 |
Correct |
403 ms |
16840 KB |
Output is correct |
50 |
Correct |
399 ms |
16984 KB |
Output is correct |
51 |
Correct |
412 ms |
16816 KB |
Output is correct |
52 |
Correct |
395 ms |
16724 KB |
Output is correct |
53 |
Correct |
402 ms |
16832 KB |
Output is correct |
54 |
Correct |
407 ms |
16976 KB |
Output is correct |
55 |
Correct |
416 ms |
16716 KB |
Output is correct |
56 |
Correct |
417 ms |
16836 KB |
Output is correct |
57 |
Correct |
397 ms |
16724 KB |
Output is correct |
58 |
Correct |
403 ms |
16724 KB |
Output is correct |
59 |
Correct |
402 ms |
16820 KB |
Output is correct |
60 |
Correct |
415 ms |
16848 KB |
Output is correct |
61 |
Correct |
429 ms |
16860 KB |
Output is correct |
62 |
Correct |
407 ms |
16820 KB |
Output is correct |
63 |
Correct |
401 ms |
16724 KB |
Output is correct |
64 |
Incorrect |
77 ms |
16872 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |