Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <ccomplex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <unordered_map>
#include <vector>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repR(i, s, e) for (ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)

template <class T> inline bool chMax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chMin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline ll gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
template <class T> inline ll lcm(T a, T b) { return a * b / gcd(a, b); }
template <class T> inline ll fact(T a) {
  if (a <= 1) {
    return 1;
  } else {
    return a * fact(a - 1);
  }
}
template <class T> inline ll comb(T a, T b) {
  return a == 0 ? 0 : fact(a) / fact(b) / fact(a - b);
}

int main() {
  ll N;
  vector<string> s;
  map<string, ll> cnt;
  cin >> N;
  rep(i, 0, N) {
    string temp;
    cin >> temp;
    sort(begin(temp), end(temp));
    cnt[temp]++;
  }
  ll ans = 0;
  for (pair<string, ll> ele : cnt) {
    if (ele.second >= 2) {
      ans += comb(ele.second, (ll)2);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <ccomplex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <unordered_map>
#include <vector>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repR(i, s, e) for (ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)

template <class T> inline bool chMax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chMin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline ll gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
template <class T> inline ll lcm(T a, T b) { return a * b / gcd(a, b); }
template <class T> inline ll fact(T a) {
  if (a <= 1) {
    return 1;
  } else {
    return a * fact(a - 1);
  }
}
template <class T> inline ll comb(T a, T b) {
  return a == 0 ? 0 : fact(a) / fact(b) / fact(a - b);
}

int main() {
  ll N;
  vector<string> s;
  map<string, ll> cnt;
  cin >> N;
  rep(i, 0, N) {
    string temp;
    cin >> temp;
    sort(begin(temp), end(temp));
    cnt[temp]++;
  }
  ll ans = 0;
  for (pair<string, ll> ele : cnt) {
    if (ele.second >= 2) {
      ans += (ele.second * (ele.second - 1) / 2);
    }
  }
  cout << ans << endl;
  return 0;
}