This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int wyst[27][27][27][27];
//26 = nie obchodzi mnie co to za litera
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,ind1,ind2,ind3,ind4;
    long long int odp;
    string a,b;
    cin >> n;
    odp = 0;
    for (int x=0;x<n;x++){
        cin >> a >> b;
        for (int mask = 0;mask<(1<<4);mask++){
            ind1 = 26; ind2 = 26; ind3 = 26; ind4 = 26;
            if (mask&1){
                ind1 = (int)a[0] - 65;
            }
            if (mask&2){
                ind2 = (int)a[1] - 65;
            }
            if (mask&4){
                ind3 = (int)b[0] - 65;
            }
            if (mask&8){
                ind4 = (int)b[1] - 65;
            }
            wyst[ind1][ind2][ind3][ind4] += 1;
        }
    }
    for (int x=0;x<26;x++){  
        for (int y=0;y<x;y++){
            odp += (wyst[x][y][x][y] * (wyst[x][y][x][y] -1 ))/2;
            odp += (wyst[y][x][y][x] * (wyst[y][x][y][x] -1 ))/2;
            odp += (wyst[x][x][y][y] * (wyst[x][x][y][y] -1 ))/2;
            odp += (wyst[y][y][x][x] * (wyst[y][y][x][x] -1 ))/2;
            odp += wyst[26][26][x][y] * wyst[x][y][26][26];
            odp -= wyst[x][y][x][y] * wyst[x][y][x][y];
            odp -= wyst[y][x][y][x] * wyst[y][x][y][x];
            odp += wyst[26][x][26][y] * wyst[x][26][y][26];
            odp -= wyst[x][x][y][y] * wyst[x][x][y][y];
            odp -= wyst[y][y][x][x] * wyst[y][y][x][x];
            odp -= wyst[26][x][x][y] * wyst[x][y][y][26];
        }
    }
    for (int x=0;x<26;x++){
         if (wyst[x][x][x][x]>1){
             odp += (wyst[x][x][x][x] * (wyst[x][x][x][x] -1 ))/2;
            // odp -= wyst[x][x][x][x] * wyst[x][x][x][x];
        }  
    }
    cout << odp << "\n";
    return 0;
}
| # | 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... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |