could anybody please explain this solution for usaco bronze why did the cow cross the road - II:
#include <bits/stdc++.h>
using namespace std;
int main ()
{
vector vec[26];
string alphabet;
cin >> alphabet;
int ans = 0;
for (int i = 0; i<52; i++)
{
int cur = alphabet[i] - 'A';
vec[cur].push_back(i);
}
for (int i = 0; i<26; i++)
{
for (int j = i+1; j<26; j++)
{
if (vec[i][0] < vec[j][0] && vec[i][1] > vec[j][0] && vec[i][1] < vec[j][1] || vec[i][0] > vec[j][0] && vec[j][1] > vec[i][0] && vec[i][1] > vec[j][1])
{
ans++;
}
}
}
cout << ans << '\n';
}