prithivMLmods/Coder-Stat huggingface dataset:
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end());
  int c = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != s[i - 1]) {
      ans = ans + (c * (c + 1)) / 2;
      c = 0;
    } else {
      c++;
    }
  }
  ans = ans + (c * (c + 1)) / 2;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end());
  ll c = 0;
  ll ans = 0;
  rep(i, n - 1) {
    if (s[i] != s[i + 1]) {
      ans = ans + (c * (c + 1)) / 2;
      c = 0;
    } else {
      c++;
    }
  }
  ans = ans + (c * (c + 1)) / 2;
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
// Garg's Code
#include <bits/stdc++.h>
using namespace std;
#define set set<ll>
#define ll long long
#define ldb long double;
#define pa pair<ll, ll>
// #define map map < ll, ll >
#define vec vector<ll>
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define f(i, x, n) for (ll i = x; i < n; i++)
#define unique_sort(x)                                                         \
  sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(), c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
#define llong 1e9 + 7
#define lsmall -1e9 + 7
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
int main()

{
  fast();

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n, ans = 0;
  cin >> n;
  vector<string> v;
  map<string, ll> m;
  string s;
  f(i, 0, n) {
    cin >> s;
    sort(s.begin(), s.end());
    // cout << s << endl;
    v.pb(s);
    m[s] = 0;
  }
  f(i, 0, n) {
    m[v[i]] += 1;
    // cout << m[v[i]] << " ";
  }
  map<string, ll>::iterator j;
  for (j = m.begin(); j != m.end(); j++) {
    // cout << j->second << " ";
    ll p = j->second;
    ans += p * (p - 1) / 2;
  }
  cout << ans;
  return 0;
}

Fixed submission:
// Garg's Code
#include <bits/stdc++.h>
using namespace std;
#define set set<ll>
#define ll long long
#define ldb long double;
#define pa pair<ll, ll>
// #define map map < ll, ll >
#define vec vector<ll>
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define f(i, x, n) for (ll i = x; i < n; i++)
#define unique_sort(x)                                                         \
  sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(), c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
#define llong 1e9 + 7
#define lsmall -1e9 + 7
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
int main()

{
  fast();

  ll n, ans = 0;
  cin >> n;
  vector<string> v;
  map<string, ll> m;
  string s;
  f(i, 0, n) {
    cin >> s;
    sort(s.begin(), s.end());
    // cout << s << endl;
    v.pb(s);
    m[s] = 0;
  }
  f(i, 0, n) {
    m[v[i]] += 1;
    // cout << m[v[i]] << " ";
  }
  map<string, ll>::iterator j;
  for (j = m.begin(); j != m.end(); j++) {
    // cout << j->second << " ";
    ll p = j->second;
    ans += p * (p - 1) / 2;
  }
  cout << ans;
  return 0;
}
Problem p02947 (C++)

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

int main() {

  int n;
  cin >> n;

  vector<string> s(n);

  for (int i = 0; i < n; i++) {

    cin >> s[i];

    sort(s[i].begin(), s[i].end());
  }

  sort(s.begin(), s.end());

  int count = 0;

  long long int ans = 0;

  //

  for (int i = 0; i < n; i++) {
    if (s[i - 1] == s[i]) {
      count++;
      ans += count;
    }

    else
      count = 0;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {

  int n;
  cin >> n;

  vector<string> s(n);

  for (int i = 0; i < n; i++) {

    cin >> s[i];

    sort(s[i].begin(), s[i].end());
  }

  sort(s.begin(), s.end());

  int count = 0;

  long long int ans = 0;

  //

  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      count++;
      ans += count;
    }

    else
      count = 0;
  }

  cout << ans << endl;

  return 0;
}
Problem p02947 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define int ll

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  for (int i = 0; i < N; i++)
    sort(rng(s[i]));
  sort(rng(s));
  int ans = 0;
  for (int i = 0; i < N; i++) {
    while (s[i] == s[i + 1]) {
      ans += i;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define int ll

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  for (int i = 0; i < N; i++)
    sort(rng(s[i]));
  sort(rng(s));
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int now = i;
    while (i + 1 < N && s[i] == s[i + 1]) {
      ans += i - now + 1;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  rep(i, n) sort(all(s[i]));
  sort(all(s));
  int ans = 0, cnt = 1;
  rep(i, n) {
    if (s[i] == s[i + 1])
      cnt++;
    else {
      ans += (cnt * (cnt - 1)) / 2;
      cnt = 1;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  rep(i, n) sort(all(s[i]));
  sort(all(s));
  s.push_back("HOGE");
  int ans = 0, cnt = 1;
  rep(i, n) {
    if (s[i] == s[i + 1])
      cnt++;
    else {
      ans += (cnt * (cnt - 1)) / 2;
      cnt = 1;
    }
  }
  cout << ans << endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i, a, b) for (ll i = a; i < b; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ii pair<ll, ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1)
      result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
const ld pi = acos(-1);

int main() {
  IOS;
  ll n;
  cin >> n;
  vector<string> v;
  f(i, 0, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    v.pb(s);
  }
  sort(v.begin(), v.end());
  ll cnt = 1, ans = 0;
  // f(i,0,v.size())cout<<v[i]<<" ";
  f(i, 1, v.size()) {
    if (v[i] == v[i - 1])
      while (v[i] == v[i - 1]) {
        cnt++;
        i++;
      }
    ans += (cnt * (cnt - 1)) / 2;
    cnt = 1;
    // cout<<ans<<" ";
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i, a, b) for (ll i = a; i < b; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ii pair<ll, ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1)
      result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
const ld pi = acos(-1);

int main() {
  IOS;
  ll n;
  cin >> n;
  vector<string> v;
  f(i, 0, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    v.pb(s);
  }
  sort(v.begin(), v.end());
  ll cnt = 1, ans = 0;
  // f(i,0,v.size())cout<<v[i]<<" ";
  f(i, 1, v.size()) {
    if (v[i] == v[i - 1])
      while (i < v.size() && v[i] == v[i - 1]) {
        cnt++;
        i++;
      }
    ans += (cnt * (cnt - 1)) / 2;
    cnt = 1;
    // cout<<ans<<" ";
  }
  cout << ans;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef int ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset                                                                   \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
#define orz                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define inp                                                                    \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
ll mod1 = 1e9 + 7;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
// cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int main() {
  orz;
  inp;
  int n, i, j, k;
  cin >> n;
  map<string, int> mp;
  string s;
  uint64_t count = 0;

  for (int i = 0; i < n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    count += mp[s];
    mp[s]++;
  }

  cout << count;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef int ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset                                                                   \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
#define orz                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define inp                                                                    \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
ll mod1 = 1e9 + 7;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
// cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int main() {
  orz;
  // inp;
  int n, i, j, k;
  cin >> n;
  map<string, int> mp;
  string s;
  uint64_t count = 0;

  for (int i = 0; i < n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    count += mp[s];
    mp[s]++;
  }

  cout << count;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++)
    cin >> h.at(i);
  sort(h.begin(), h.end());
  ll mini = h.at(K - 1);
  ll maxi = h.at(N - K);
  ll A = mini - h.at(0);
  ll B = h.at(N - 1) - maxi;
  cout << min(A, B) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  map<string, ll> mp;
  rep(i, N) {
    string w;
    cin >> w;
    sort(all(w));
    mp[w]++;
  }
  ll answer = 0;
  for (auto p : mp) {
    ll a = p.se;
    answer += a * (a - 1) / 2;
  }
  cout << answer << endl;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  // sort済みの文字列をソートする
  sort(s.begin(), s.end());
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll cnt = 0;
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j]) {
        cnt++;
        ans += cnt;
      } else {
        i = j - 1; // loopを抜けたあとi++されるので-1して帳尻を合わせる
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  // sort済みの文字列をソートする
  sort(s.begin(), s.end());
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll cnt = 0;
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j]) {
        cnt++;
        ans += cnt;
        if (j == N - 1) {
          i = N - 1;
        }
      } else {
        i = j - 1; // loopを抜けたあとi++されるので-1して帳尻を合わせる
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define boost()                                                                \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie();                                                                   \
  cout.tie();                                                                  \
  cout << fixed;                                                               \
  cout << setprecision(15);                                                    \
  srand(time(NULL))
#define all(x) x.begin(), x.end()
using namespace std;

vector<string> s;
int n;

signed main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string cur;
    cin >> cur;
    sort(all(cur));
    s.push_back(cur);
  }
  sort(all(s));
  int res = 0;
  int i = 0, j = 0;
  while (i < n && j < n) {
    while (s[i] == s[j])
      j++;
    int x = j - i;
    res += (x * (x - 1)) / 2;
    i = j;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define boost()                                                                \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie();                                                                   \
  cout.tie();                                                                  \
  cout << fixed;                                                               \
  cout << setprecision(15);                                                    \
  srand(time(NULL))
#define all(x) x.begin(), x.end()
using namespace std;

vector<string> s;
int n;

signed main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string cur;
    cin >> cur;
    sort(all(cur));
    s.push_back(cur);
  }
  sort(all(s));
  int res = 0;
  int i = 0, j = 0;
  while (i < n && j < n) {
    while (j < n && s[i] == s[j])
      j++;
    int x = j - i;
    res += (x * (x - 1)) / 2;
    i = j;
  }
  cout << res << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

void strsort(std::string &s) {
  std::vector<char> tmp;
  for (int i = 0; i < s.size(); i++)
    tmp.push_back(s[i]);
  std::sort(tmp.begin(), tmp.end());
  for (int i = 0; i < s.size(); i++)
    s[i] = tmp[i];
}

int main() {
  int N;
  std::cin >> N;
  std::vector<std::string> s(N);
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
    strsort(s[i]);
  }

  std::sort(s.begin(), s.end());
  long long count = 0;
  std::vector<long long> vcount;
  for (int i = 0; i < N; i++) {
    count++;
    if (i == N || (i != N && s[i] != s[i + 1])) {
      vcount.push_back(count);
      count = 0;
    }
  }
  long long ans = 0;
  for (auto &&itr = vcount.begin(); itr != vcount.end(); itr++) {
    long long c = (*itr);
    ans += c * (c - 1) / 2;
  }
  std::cout << ans << std::endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

void strsort(std::string &s) {
  std::vector<char> tmp;
  for (int i = 0; i < s.size(); i++)
    tmp.push_back(s[i]);
  std::sort(tmp.begin(), tmp.end());
  for (int i = 0; i < s.size(); i++)
    s[i] = tmp[i];
}

int main() {
  int N;
  std::cin >> N;
  std::vector<std::string> s(N);
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
    strsort(s[i]);
  }

  std::sort(s.begin(), s.end());
  long long count = 0;
  std::vector<long long> vcount;
  for (int i = 0; i < N; i++) {
    count++;
    if (i == N - 1 || (i != N - 1 && s[i] != s[i + 1])) {
      vcount.push_back(count);
      count = 0;
    }
  }
  long long ans = 0;
  for (auto &&itr = vcount.begin(); itr != vcount.end(); itr++) {
    long long c = (*itr);
    ans += c * (c - 1) / 2;
  }
  std::cout << ans << std::endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#define Max 2 * 100002
using namespace std;

vector<string> vec;

int main() {

  int n, i;
  string s;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    vec.push_back(s);
  }

  sort(vec.begin(), vec.end());

  long long int ans = 0, val = 0;
  for (i = 0; i < n; i++) {
    if (vec[i] == vec[i + 1])
      val++;
    else {
      ans += (val * (val + 1)) / 2;
      val = 0;
    }
  }

  if (val > 0)
    ans += (val * (val + 1)) / 2;

  printf("%lld\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#define Max 2 * 100002
using namespace std;

vector<string> vec;

int main() {

  int n, i;
  string s;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    vec.push_back(s);
  }

  sort(vec.begin(), vec.end());

  long long int ans = 0, val = 0;
  for (i = 0; i < n - 1; i++) {
    if (vec[i] == vec[i + 1])
      val++;
    else {
      ans += (val * (val + 1)) / 2;
      val = 0;
    }
  }

  if (val > 0)
    ans += (val * (val + 1)) / 2;

  printf("%lld\n", ans);

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
vector<ll> g[N];
ll score[N];
void dfs(ll v, ll p) {
  score[v] += score[p];
  for (auto u : g[v]) {
    if (u == p)
      continue;
    dfs(u, v);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    map<vector<ll>, ll> a;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      vector<ll> ct(26, 0);
      for (int i = 0; i < 10; i++) {
        ct[s[i] - 'a']++;
      }
      a[ct]++;
    }
    ll ans = 0;

    map<vector<ll>, ll>::iterator i;
    for (i = a.begin(); i != a.end(); i++) {
      ll temp = i->second * (i->second - 1);
      temp = temp / 2;
      ans += temp;
    }
    cout << ans;
  }
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
vector<ll> g[N];
ll score[N];
void dfs(ll v, ll p) {
  score[v] += score[p];
  for (auto u : g[v]) {
    if (u == p)
      continue;
    dfs(u, v);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    map<vector<ll>, ll> a;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      vector<ll> ct(26, 0);
      for (int i = 0; i < 10; i++) {
        ct[s[i] - 'a']++;
      }
      a[ct]++;
    }
    ll ans = 0;

    map<vector<ll>, ll>::iterator i;
    for (i = a.begin(); i != a.end(); i++) {
      ll temp = i->second * (i->second - 1);
      temp = temp / 2;
      ans += temp;
    }
    cout << ans;
  }
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int64_t cx(int64_t i) {
  int64_t res = 1;
  while (i > 1) {
    res = res * i;
    i--;
  }

  return res;
}

int main() {
  int64_t N;
  cin >> N;
  map<string, int64_t> d;
  for (int64_t i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (d.count(s) > 0) {
      d[s] = d[s] + 1;
    } else {
      d[s] = 1;
    }
  }

  int64_t sum_count = 0;
  for (auto c : d) {
    if (c.second > 2) {
      sum_count += cx(c.second) / (cx(c.second - 2) * 2);
    } else if (c.second == 2) {
      sum_count += 1;
    }
  }

  cout << sum_count << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int64_t cx(int64_t i) {
  int64_t res = 1;
  while (i > 1) {
    res = res * i;
    i--;
  }

  return res;
}

int main() {
  int64_t N;
  cin >> N;
  map<string, int64_t> d;
  for (int64_t i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (d.count(s) > 0) {
      d[s] = d[s] + 1;
    } else {
      d[s] = 1;
    }
  }

  int64_t sum_count = 0;
  for (auto c : d) {
    if (c.second > 2) {
      int64_t i = c.second;
      while (i > 1) {
        sum_count += i - 1;
        i--;
      }
    } else if (c.second == 2) {
      sum_count += 1;
    }
  }

  cout << sum_count << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> x;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    bool flag = true;
    for (auto itr = x.begin(); itr != x.end(); itr++) {
      if (s == itr->first) {
        itr->second++;
        flag = false;
        break;
      }
    }
    if (flag)
      x[s] = 1;
  }
  ll ans = 0;
  for (auto itr = x.begin(); itr != x.end(); itr++) {
    ll n = itr->second;
    ans += n * (n - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> x;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    auto itr = x.find(s);
    if (itr != x.end())
      itr->second++;
    else
      x[s] = 1;
  }
  ll ans = 0;
  for (auto itr = x.begin(); itr != x.end(); itr++) {
    ll n = itr->second;
    ans += n * (n - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  Int N;
  cin >> N;

  vector<string> s(N);
  for (Int i = 0; i < N; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }

  sort(s.begin(), s.end());

  Int ans = 0;
  string tmep;
  for (Int i = 0; i < N - 1; i++) {
    for (Int j = i + 1; j < N; j++) {
      if (s[i] == s[j])
        ans++;
      else
        break;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  Int N;
  cin >> N;

  vector<string> s(N);
  for (Int i = 0; i < N; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }

  sort(s.begin(), s.end());

  Int ans = 0;

  Int i = 0;
  while (i < N - 1) {
    Int start = i;
    Int end = 0;
    i++;

    while ((i < N) && (s[start] == s[i])) {
      end = i;
      i++;
    }

    Int j = end - start;
    while (j > 0) {
      ans += j;
      j--;
    }
  }

  cout << ans << endl;
}
Problem p02947 (C++)

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

using namespace std;

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    sort(S[i].begin(), S[i].end());
  }

  sort(S.begin(), S.end());

  ll ans = 0;

  ll index = 0;

  while (index < N) {
    string head = S[index];
    ll move = 1;
    while (S[index + move] == head && index + move < N) {
      move++;
    }
    ans += move * (move - 1) / 2;
    index += move;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    sort(S[i].begin(), S[i].end());
  }

  sort(S.begin(), S.end());

  ll ans = 0;

  ll index = 0;

  while (index < N) {
    string head = S[index];
    ll move = 1;
    while (index + move < N && S[index + move] == head) {
      move++;
    }
    ans += move * (move - 1) / 2;
    index += move;
  }

  cout << ans << endl;

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  rep(i, n) sort(all(s[i]));
  sort(all(s));

  ll res = 0;
  int i = 0;
  while (i < n) {
    ll count = 0;
    while (i < n) {
      if (s[i] != s[i + 1])
        break;
      count++;
      i++;
    }
    res += count * (count + 1) / 2;
    i++;
  }

  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  rep(i, n) sort(all(s[i]));
  sort(all(s));

  ll res = 0;
  int i = 0;
  while (i < n) {
    ll count = 0;
    while (i < n - 1) {
      if (s[i] != s[i + 1])
        break;
      count++;
      i++;
    }
    res += count * (count + 1) / 2;
    i++;
  }

  cout << res << endl;
}
Problem p02947 (C++)

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

#define FOR(i, x, n) for (ll i = x; i < n; i++)
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <class Arg1, class... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *sep = strchr(names + 1, ',');
  cerr.write(names, sep - names) << " : " << arg1 << "  ";
  __f(sep + 1, args...);
}

const int N = 1e5 + 5;

void solve() {
  map<string, int> mp;
  int t;
  cin >> t;
  while (t--) {
    string input;
    cin >> input;
    sort(all(input));
    mp[input]++;
  }
  int ret = 0;
  for (auto x : mp) {
    ret += (x.second * (x.second - 1)) / 2;
  }
  cout << ret << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

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

#define FOR(i, x, n) for (ll i = x; i < n; i++)
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <class Arg1, class... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *sep = strchr(names + 1, ',');
  cerr.write(names, sep - names) << " : " << arg1 << "  ";
  __f(sep + 1, args...);
}

const int N = 1e5 + 5;

void solve() {
  map<string, int> mp;
  int t;
  cin >> t;
  while (t--) {
    string input;
    cin >> input;
    sort(all(input));
    mp[input]++;
  }
  int ret = 0;
  for (auto x : mp) {
    ret += (x.second * (x.second - 1)) / 2;
  }
  cout << ret << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
  #endif*/
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define loop(i, first, end) for (int i = (first); i < (end); i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ull>
#define vll vector<ll>
#define init(type, var)                                                        \
  type var;                                                                    \
  cin >> var;
#define vinit(vtype, var, n)                                                   \
  vtype var(n);                                                                \
  loop(i, 0, n) cin >> var[i];

const ull MOD = 1000000007ULL;
const ull INF = (ull)(-1LL);

int main(void) {
  init(ull, n);
  vinit(vector<string>, s, n);
  loop(i, 0, s.size()) { sort(s[i].begin(), s[i].end()); }
  sort(s.begin(), s.end());
  ull count = 0;
  loop(i, 0, s.size()) {
    loop(j, i + 1, s.size()) {
      if (s[i] != s[j])
        break;
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define loop(i, first, end) for (int i = (first); i < (end); i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ull>
#define vll vector<ll>
#define init(type, var)                                                        \
  type var;                                                                    \
  cin >> var;
#define vinit(vtype, var, n)                                                   \
  vtype var(n);                                                                \
  loop(i, 0, n) cin >> var[i];

const ull MOD = 1000000007ULL;
const ull INF = (ull)(-1LL);

int main(void) {
  init(ull, n);
  vinit(vector<string>, s, n);
  loop(i, 0, s.size()) { sort(s[i].begin(), s[i].end()); }
  sort(s.begin(), s.end());
  ull count = 0;
  for (int i = 0; i < s.size();) {
    ull _c;
    for (_c = 1; i + _c < s.size() && s[i + _c] == s[i]; _c++)
      ;
    count += (_c * (_c - 1) / 2);
    i += _c;
  }
  cout << count << endl;

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int N;
  cin >> N;

  string s[N + 1];
  for (int i = 0; i < N; i++)
    cin >> s[i];

  string aToZ = "abcdefghijklmnopqrstuvwxyz";

  map<string, long> anagram_group;
  // 文字カウント(24桁の文字にして0~Aまでの文字で各文字の数を表現)
  for (int i = 0; i < N; i++) {

    string chrCount = string(24, '0');
    string targetStr = s[i];

    for (int j = 0; j < 10; j++) {
      /*             cout << targetStr[j] << endl;
                  cout << aToZ.find(targetStr[j]) << endl;
                  cout << chrCount[aToZ.find(targetStr[j])] << endl;
                  cout << "----" << endl;
      */
      char c = chrCount[aToZ.find(targetStr[j])];
      if ('c' == '9') {
        chrCount[aToZ.find(targetStr[j])] = 'A';
      } else {
        chrCount[aToZ.find(targetStr[j])] =
            to_string(std::stoi(string(1, c)) + 1)[0];
      }
    }

    if (anagram_group.count(chrCount) == 0) {
      anagram_group[chrCount] = 1L;
    } else {
      anagram_group[chrCount]++;
    }
  }

  long result = 0;
  auto begin = anagram_group.begin(), end = anagram_group.end();
  for (auto iter = begin; iter != end; iter++) {
    long value = iter->second;

    if (value > 1L) {
      result += (value * (value - 1L)) / 2L;
    }
  }
  cout << result << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int N;
  cin >> N;

  string s[N + 1];
  for (int i = 0; i < N; i++)
    cin >> s[i];

  string aToZ = "abcdefghijklmnopqrstuvwxyz";

  map<string, long> anagram_group;
  // 文字カウント(24桁の文字にして0~Aまでの文字で各文字の数を表現)
  for (int i = 0; i < N; i++) {

    string chrCount = string(26, '0');
    string targetStr = s[i];

    for (int j = 0; j < 10; j++) {
      /*             cout << targetStr[j] << endl;
                  cout << aToZ.find(targetStr[j]) << endl;
                  cout << chrCount[aToZ.find(targetStr[j])] << endl;
                  cout << "----" << endl;
      */
      char c = chrCount[aToZ.find(targetStr[j])];
      if ('c' == '9') {
        chrCount[aToZ.find(targetStr[j])] = 'A';
      } else {
        chrCount[aToZ.find(targetStr[j])] =
            to_string(std::stoi(string(1, c)) + 1)[0];
      }
    }

    if (anagram_group.count(chrCount) == 0) {
      anagram_group[chrCount] = 1L;
    } else {
      anagram_group[chrCount]++;
    }
  }

  long result = 0;
  auto begin = anagram_group.begin(), end = anagram_group.end();
  for (auto iter = begin; iter != end; iter++) {
    long value = iter->second;

    if (value > 1L) {
      result += (value * (value - 1L)) / 2L;
    }
  }
  cout << result << endl;

  return 0;
}
Problem p02947 (C++)

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

const bool DEBUG = false;

int N;
vector<string> s;

void input() {
  cin >> N;
  s = vector<string>(N);
  for (size_t i = 0; i < N; i++)
    cin >> s[i];
}

int main(int argc, char const *argv[]) {
  input();

  for (size_t i = 0; i < N; i++)
    sort(s[i].begin(), s[i].end());
  sort(s.begin(), s.end());

  long long total = 0, count = 1;
  for (size_t i = 0; i < N; i++) {
    if ((s[i] != s[i + 1]) || i == (N - 1)) {
      total += (count * (count - 1)) / 2;
      count = 1;
    } else {
      count++;
    }
  }

  cout << total << endl;

  return 0;
}


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

const bool DEBUG = false;

int N;
vector<string> s;

void input() {
  cin >> N;
  s = vector<string>(N);
  for (size_t i = 0; i < N; i++)
    cin >> s[i];
}

int main(int argc, char const *argv[]) {
  input();

  for (size_t i = 0; i < N; i++)
    sort(s[i].begin(), s[i].end());
  sort(s.begin(), s.end());

  long long total = 0, count = 1;
  for (size_t i = 0; i < N; i++) {
    if (i == (N - 1) || (s[i] != s[i + 1])) {
      total += (count * (count - 1)) / 2;
      count = 1;
    } else {
      count++;
    }
  }

  cout << total << endl;

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s.at(i) == s.at(j))
        ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  ll ans = 0;
  sort(s.begin(), s.end());
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    if (m.count(s.at(i))) {
      ans += m.at(s.at(i));
      m[s.at(i)] += 1;
    } else {
      m[s.at(i)] = 1;
    }
  }
  cout << ans << endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> s;

int main() {
  int N;
  long len = 1;
  long count = 0;
  string in;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> in;
    sort(in.begin(), in.begin() + in.size());
    s.push_back(in);
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < N; i++) {
    if (s[i] == s[i + 1])
      len++;
    else {
      count += len * (len - 1) / 2;
      len = 1;
    }
  }
  count += len * (len - 1) / 2;
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> s;

int main() {
  int N;
  long len = 1;
  long count = 0;
  string in;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> in;
    sort(in.begin(), in.begin() + in.size());
    s.push_back(in);
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < N - 1; i++) {
    if (s[i] == s[i + 1])
      len++;
    else {
      count += len * (len - 1) / 2;
      len = 1;
    }
  }
  count += len * (len - 1) / 2;
  cout << count << endl;
  return 0;
}
Problem p02947 (C++)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main() {

  lint n;
  cin >> n;

  lint ans = 0, tmp = 1;

  vector<string> s(n);
  REP(i, n) {
    cin >> s[i];
    sort(ALL(s[i]));
  }
  sort(ALL(s));

  REP(i, n - 1) {}

  REP(i, n) {
    if (s[i] == s[i + 1]) {
      tmp += 1;
    } else {
      ans += tmp * (tmp - 1) / 2;
      tmp = 1;
    }
    //  cout << s[i]<< tmp << "\n";
  }

  ans += tmp * (tmp - 1) / 2;

  cout << ans << "\n";

  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main() {

  lint n;
  cin >> n;

  lint ans = 0, tmp = 1;

  vector<string> s(n);
  REP(i, n) {
    cin >> s[i];
    sort(ALL(s[i]));
  }
  sort(ALL(s));

  REP(i, n - 1) {}

  REP(i, n - 1) {
    if (s[i] == s[i + 1]) {
      tmp += 1;
    } else {
      ans += tmp * (tmp - 1) / 2;
      tmp = 1;
    }
    //  cout << s[i]<< tmp << "\n";
  }

  ans += tmp * (tmp - 1) / 2;

  cout << ans << "\n";

  return 0;
}
Problem p02947 (C++)

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

int main() {

  int n;
  cin >> n;
  vector<string> all(n);
  for (int i = 0; i < n; i++)
    cin >> all.at(i);
  int count = 0;
  int i = 0;
  while (i < n) {
    string test = all.at(i);
    for (int k = i + 1; k < n; k++) {
      string cover = all.at(k);
      for (int j = 0; j < 10; j++) {
        for (int l = 0; l < cover.size(); l++) {
          if (test.at(j) == cover.at(l)) {
            cover.erase(l, 1);
            break;
          }
        }
        if (cover.size() == 0)
          count++;
      }
    }
    i++;
  }
  cout << count << endl;
}

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

int main() {

  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  long long count = 0;
  for (auto &x : mp) {
    long long i = x.second;
    count += i * (i - 1) / 2;
  }
  cout << count << endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

long long factorial(long long n) {
  if (n == 0) {
    return 1;
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}

long long combination(long long n, long long k) {
  if (n < k) {
    return 0;
  } else if (n == k) {
    return 1;
  }

  return factorial(n) / (factorial(k) * factorial(n - k));
}

int main() {
  int n;
  cin >> n;
  vector<string> strs;
  strs.reserve(n);

  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    strs.push_back(str);
  }

  sort(strs.begin(), strs.end());

  vector<long long> ns;
  string str = strs[0];
  long long count = 0;
  for (int i = 0; i < strs.size(); i++) {
    if (str == strs[i]) {
      count++;
    } else {
      ns.push_back(count);
      str = strs[i];
      count = 1;
    }
  }
  ns.push_back(count);

  long long ans = 0;
  for (int i = 0; i < ns.size(); i++) {
    ans += combination(ns[i], 2);
  }

  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

long long factorial(long long n) {
  if (n == 0) {
    return 1;
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}

long long combination(long long n, long long k) {
  if (n < k) {
    return 0;
  } else if (n == k) {
    return 1;
  }

  long long numerator = 1;
  long long denominator = factorial(k);
  for (int i = 0; i < k; i++) {
    numerator *= (n - i);
  }
  return numerator / denominator;
}

int main() {
  int n;
  cin >> n;
  vector<string> strs;
  strs.reserve(n);

  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    strs.push_back(str);
  }

  sort(strs.begin(), strs.end());

  vector<long long> ns;
  string str = strs[0];
  long long count = 0;
  for (int i = 0; i < strs.size(); i++) {
    if (str == strs[i]) {
      count++;
    } else {
      ns.push_back(count);
      str = strs[i];
      count = 1;
    }
  }
  ns.push_back(count);

  long long ans = 0;
  for (int i = 0; i < ns.size(); i++) {
    ans += combination(ns[i], 2);
  }

  cout << ans;
}