#include <iostream>
#include <algorithm>
using namespace std;
using num = long long;
num gora[26][26];
num dol[26][26];
num lewo[26][26];
num prawo[26][26];
bool tab[26][26][26][26];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
num n;
num r = 0;
cin >> n;
for (num i = 0; i < n; ++i)
{
string s1;
string s2;
cin >> s1 >> s2;
num a = s1[0] - 65;
num b = s1[1] - 65;
num c = s2[0] - 65;
num d = s2[1] - 65;
++gora [a][b];
++dol [c][d];
++prawo[b][d];
++lewo [a][c];
tab[a][b]
[c][d] = true;
if (tab[c][d]
[a][b])
{
++r;
}
if (tab[b][a]
[d][c])
{
++r;
}
if (a == d)
{
for (num j = 0; j < 26; ++j)
{
if (tab[b][j]
[a][b])
{
++r;
}
}
for (num j = 0; j < 26; ++j)
{
if (tab[c][a]
[j][c])
{
++r;
}
}
}
if (b == c)
{
for (num j = 0; j < 26; ++j)
{
if (tab[b][d]
[d][j])
{
++r;
}
}
for (num j = 0; j < 26; ++j)
{
if (tab[j][a]
[a][b])
{
++r;
}
}
}
if (a == d && b == c)
{
if (tab[b][a]
[a][b])
{
r -= 3;
}
}
if (a == d && b == c && a == b)
{
--r;
}
//cout << r << '\n';
}
num suma = 0;
for (num i = 0; i < 26; ++i)
{
for (num j = 0; j < 26; ++j)
{
suma += gora[i][j] * dol[i][j];
//if(gora[i][j] * dol[i][j] > 0)
//cout << i << ' ' << j << ' ' << gora[i][j] << ' ' << dol[i][j] << '\n';
}
}
for (num i = 0; i < 26; ++i)
{
for (num j = 0; j < 26; ++j)
{
suma += prawo[i][j] * lewo[i][j];
//if(prawo[i][j] * lewo[i][j] > 0)
//cout << i << ' ' << j << ' ' << prawo[i][j] << ' ' << lewo[i][j] << '\n';
}
}
cout << suma - r;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
768 KB |
Output is correct |
2 |
Correct |
55 ms |
3448 KB |
Output is correct |
3 |
Correct |
64 ms |
3320 KB |
Output is correct |
4 |
Correct |
57 ms |
3404 KB |
Output is correct |
5 |
Correct |
55 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
788 KB |
Output is correct |
3 |
Correct |
34 ms |
724 KB |
Output is correct |
4 |
Correct |
21 ms |
788 KB |
Output is correct |
5 |
Correct |
20 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
58 ms |
768 KB |
Output is correct |
13 |
Correct |
55 ms |
3448 KB |
Output is correct |
14 |
Correct |
64 ms |
3320 KB |
Output is correct |
15 |
Correct |
57 ms |
3404 KB |
Output is correct |
16 |
Correct |
55 ms |
3328 KB |
Output is correct |
17 |
Correct |
6 ms |
788 KB |
Output is correct |
18 |
Correct |
34 ms |
724 KB |
Output is correct |
19 |
Correct |
21 ms |
788 KB |
Output is correct |
20 |
Correct |
20 ms |
724 KB |
Output is correct |
21 |
Correct |
13 ms |
1288 KB |
Output is correct |
22 |
Correct |
52 ms |
2808 KB |
Output is correct |
23 |
Correct |
41 ms |
2052 KB |
Output is correct |
24 |
Correct |
32 ms |
2044 KB |
Output is correct |