Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define MOD 1000000007
#define eps 1e-8
#define FASTER                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  out << "";
  for (auto it = a.begin(); it != a.end(); it++) {
    if (it != a.begin())
      out << " ";
    out << *it;
  }
  out << "";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
// ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main() {
  FASTER;
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sort(all(v[i]));
  }
  sort(all(v));
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int cnt = 1;
    while (v[i] == v[i + 1]) {
      cnt++;
      i++;
    }
    ans += (cnt * (cnt - 1) / 2);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define MOD 1000000007
#define eps 1e-8
#define FASTER                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  out << "";
  for (auto it = a.begin(); it != a.end(); it++) {
    if (it != a.begin())
      out << " ";
    out << *it;
  }
  out << "";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
// ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main() {
  FASTER;
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sort(all(v[i]));
  }
  sort(all(v));
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int cnt = 1;
    while (i + 1 < n && v[i] == v[i + 1]) {
      cnt++;
      i++;
    }
    ans += (cnt * (cnt - 1) / 2);
  }
  cout << ans;
}