#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
using namespace std;
vector<vector<long long>> mp;
int main() {
//cout << (long long)'a' - '0' << " " << (long long)'z' - '0' << '\n' << (long long)'A' - '0' << " " << (long long)'Z' - '0';
long long mod = 998244353;
long long n;
cin >> n;
vector<vector<string>> have(11);
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
have[s.size()].push_back(s);
}
long long ans = 0;
for (long long len = 3; len <= 10; len++) {
mp.assign(75, vector<long long>(75, 0));
vector<vector<set<string>>> pupu(75, vector<set<string>>(75));
for (auto s : have[len]) {
/*if (s[0] != s.back()) {
mp[min(s[0], s.back()) - 'A'][max(s[0], s.back()) - 'A']++;
mp[max(s[0], s.back()) - 'A'][min(s[0], s.back()) - 'A']++;
mp[min(s[0], s.back()) - 'A'][max(s[0], s.back()) - 'A'] %= mod;
mp[max(s[0], s.back()) - 'A'][min(s[0], s.back()) - 'A'] %= mod;
}
else {
bool palind = 1;
for (long long i = 0; i < s.size(); i++) {
if (s[i] != s[s.size() - 1 - i]) {
palind = 0;
break;
}
}
if (palind) {
mp[s[0] - 'A'][s[0] - 'A']++;
mp[s[0] - 'A'][s[0] - 'A'] %= mod;
}
else {
mp[s[0] - 'A'][s[0] - 'A'] += 2;
mp[s[0] - 'A'][s[0] - 'A'] %= mod;
}
}*/
pupu[s[0] - '0'][s.back() - '0'].insert(s);
reverse(s.begin(), s.end());
pupu[s[0] - '0'][s.back() - '0'].insert(s);
}
for (long long a = 0; a < 75; a++) {
for (long long b = 0; b < 75; b++) {
mp[a][b] = pupu[a][b].size();
}
}
vector<vector<vector<long long>>> muls(75, vector<vector<long long>>(75, vector<long long>(75, 0)));
for (long long a = 0; a < 75; a++) {
if (a == 10) {
a = 17;
}
if (a == 43) {
a = 49;
}
for (long long b = 0; b < 75; b++) {
if (b == 10) {
b = 17;
}
if (b == 43) {
b = 49;
}
for (long long c = 0; c < 75; c++) {
if (c == 10) {
c = 17;
}
if (c == 43) {
c = 49;
}
for (long long x = 0; x < 75; x++) {
if (x == 10) {
x = 17;
}
if (x == 43) {
x = 49;
}
muls[a][b][c] += (((mp[a][x] * mp[b][x]) % mod) * mp[c][x]) % mod;
muls[a][b][c] %= mod;
}
}
}
}
for (long long a = 0; a < 75; a++) {
if (a == 10) {
a = 17;
}
if (a == 43) {
a = 49;
}
for (long long b = 0; b < 75; b++) {
if (b == 10) {
b = 17;
}
if (b == 43) {
b = 49;
}
for (long long c = 0; c < 75; c++) {
if (c == 10) {
c = 17;
}
if (c == 43) {
c = 49;
}
for (long long d = 0; d < 75; d++) {
if (d == 10) {
d = 17;
}
if (d == 43) {
d = 49;
}
ans += (((((muls[a][b][c] * muls[a][b][d]) % mod) * muls[a][c][d]) % mod) * muls[b][c][d]) % mod;
ans %= mod;
}
}
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |