Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define INF (int)1e16
#define speed                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.flush()
#define MOD (int)(1e9 + 7)
#define fi first
#define se second
#define sq(a) a *a
#define ld long double
#define Error(x) cout << #x << " = " << (x) << endl;
#define Error2(a, b)                                                           \
  cout << "( " << #a << " , " << #b << " ) = ( " << (a) << " , " << (b)        \
       << " )\n";
#define Error3(a, b, c)                                                        \
  cout << "(" << #a << " , " << #b << " , " << #c << " ) = ( " << (a) << " , " \
       << (b) << " , " << (c) << ")\n";
#define Error4(a, b, c, d)                                                     \
  cout << "(" << #a << " , " << #b << " , " << #c << " , " << #d << " ) = \
                            ( "    \
       << (a) << " , " << (b) << " , " << (c) << " , " << (d) << ")\n";
#define popcount __builtin_popcountll
#define ign cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define PI acos(-1.0)

int abso(int a) { return a > 0 ? a : (-a); }
int cdiv(int a, int b) { return a / b + ((a % b) > 0); }
int mul(int a, int b) {
  int res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % MOD;
    a = (a + a) % MOD;
    b = b / 2;
  }
  return res;
}
int bexp(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b = b / 2;
  }
  return res;
}
int inv(int a) { return bexp(a, MOD - 2); }

int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b = b >> 1;
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  string arr[n + 1];
  map<string, int> mp;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    sort(arr[i].begin(), arr[i].end());
    mp[arr[i]]++;
  }
  int ans = 0;
  for (auto it : mp) {
    ans = ans + ((it.second) * (it.second - 1)) / 2;
  }
  cout << ans << "\n";
}

signed main() {
  speed;
#ifndef ONLINE_JUDGE
  freopen("C:\\Users\\anuj\\CLionProjects\\untitled\\input.txt", "r", stdin);
  freopen("C:\\Users\\anuj\\CLionProjects\\untitled\\output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define INF (int)1e16
#define speed                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.flush()
#define MOD (int)(1e9 + 7)
#define fi first
#define se second
#define sq(a) a *a
#define ld long double
#define Error(x) cout << #x << " = " << (x) << endl;
#define Error2(a, b)                                                           \
  cout << "( " << #a << " , " << #b << " ) = ( " << (a) << " , " << (b)        \
       << " )\n";
#define Error3(a, b, c)                                                        \
  cout << "(" << #a << " , " << #b << " , " << #c << " ) = ( " << (a) << " , " \
       << (b) << " , " << (c) << ")\n";
#define Error4(a, b, c, d)                                                     \
  cout << "(" << #a << " , " << #b << " , " << #c << " , " << #d << " ) = \
                            ( "    \
       << (a) << " , " << (b) << " , " << (c) << " , " << (d) << ")\n";
#define popcount __builtin_popcountll
#define ign cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define PI acos(-1.0)

int abso(int a) { return a > 0 ? a : (-a); }
int cdiv(int a, int b) { return a / b + ((a % b) > 0); }
int mul(int a, int b) {
  int res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % MOD;
    a = (a + a) % MOD;
    b = b / 2;
  }
  return res;
}
int bexp(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b = b / 2;
  }
  return res;
}
int inv(int a) { return bexp(a, MOD - 2); }

int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b = b >> 1;
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  string arr[n + 1];
  map<string, int> mp;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    sort(arr[i].begin(), arr[i].end());
    mp[arr[i]]++;
  }
  int ans = 0;
  for (auto it : mp) {
    ans = ans + ((it.second) * (it.second - 1)) / 2;
  }
  cout << ans << "\n";
}

signed main() {
  speed;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}