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

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

int main() {
  int n;
  vector<string> v;
  string s;
  int count = 0;
  long long result = 0;

  cin >> n;

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

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

  for (int i = 0; i < n; i++) {
    for (int ii = (i + 1); ii < n; ii++) {
      if (v[i] != v[ii]) {
        break;
      }

      result++;
    }
  }

  cout << result << endl;
  return 0;
}

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

int main() {
  int n;
  vector<string> v;
  string s;
  int count = 0;
  long long result = 0;

  cin >> n;

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

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

  for (int i = 1; i < n; i++) {
    if (v[i] == v[i - 1]) {
      result += ++count;
    } else {
      count = 0;
    }
  }

  cout << result << 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;
  string s[100010];
  for (int i = 0; i < N; i++)
    cin >> s[i];
  for (int i = 0; i < N; i++)
    sort(s[i].begin(), s[i].end());
  for (int i = 0; i < N; i++)
    sort(s, s + N);
  s[N] = "";
  LL ans = 0, same = 0;
  for (int i = 0; i < N; i++) {
    same++;
    if (s[i] != s[i + 1]) {
      ans += same * (same - 1) / 2;
      same = 0;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;
typedef long long LL;

int main() {
  int N;
  cin >> N;
  string s[100010];
  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, s + N);
  s[N] = "";
  LL ans = 0, same = 0;
  for (int i = 0; i < N; i++) {
    same++;
    if (s[i] != s[i + 1]) {
      ans += same * (same - 1) / 2;
      same = 0;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02947 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (size_t i = 0; i < n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  int64_t ans = 0;
  int count = 0;
  for (size_t i = 0; i < n; i++) {

    /* code */

    if (s.at(i) == s.at(i + 1)) {
      count++;
      ans += count;
    } else {
      count = 0;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (size_t i = 0; i < n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  int64_t ans = 0;
  int count = 0;
  for (size_t i = 0; i < n - 1; i++) {

    /* code */

    if (s.at(i) == s.at(i + 1)) {
      count++;
      ans += count;
    } else {
      count = 0;
    }
  }
  cout << ans << endl;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define For(i, m, n) for (int i = m; i < n; i++)
#define Forr(i, m, n) for (int i = m; i > n; i--)
#define Sort(a) sort(a.begin(), a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

ll comb(int n, int k) {
  if (n == k || k == 0)
    return 1;
  else
    return comb(n - 1, k - 1) + comb(n - 1, k);
}

int main() {
  int N;
  ll sum = 0;
  cin >> N;
  vector<string> s(N);
  map<string, int> cnt;
  rep(i, N) {
    cin >> s[i];
    Sort(s[i]);
    cnt[s[i]]++;
  }

  for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
    if (cnt[itr->first] >= 2)
      sum += comb(cnt[itr->first], 2);
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define For(i, m, n) for (int i = m; i < n; i++)
#define Forr(i, m, n) for (int i = m; i > n; i--)
#define Sort(a) sort(a.begin(), a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

ll comb(int n, int k) {
  ll res = 1;
  if (k > n - k)
    k = n - k;
  rep(i, k) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}

int main() {
  int N;
  ll sum = 0;
  cin >> N;
  vector<string> s(N);
  map<string, int> cnt;
  rep(i, N) {
    cin >> s[i];
    Sort(s[i]);
    cnt[s[i]]++;
  }

  for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
    if (cnt[itr->first] >= 2)
      sum += comb(cnt[itr->first], 2);
  }
  cout << sum << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n) {
  ll res = 1;
  for (int i = 1; i <= n; i++) {
    res = res * i;
  }
  return res;
}

int main() {
  IOS;
  ll a;
  cin >> a;
  vector<string> L;
  for (int i = 0; i < a; i++) {
    string ch;
    cin >> ch;
    sort(ch.begin(), ch.end());
    L.push_back(ch);
  }
  sort(L.begin(), L.end());
  /*for(int i=0;i<a;i++)
      cout << L[i];*/
  ll str = 1;
  vector<ll> L2;
  for (int i = 0; i < a - 1; i++) {
    if (L[i] == L[i + 1])
      str++;
    else {
      L2.push_back(str);
      str = 1;
    }
  }
  if (str != 1)
    L2.push_back(str);
  ll res = 0;
  for (int i = 0; i < L2.size(); i++) {
    if (L2[i] != 1)
      res += fact(L2[i]) / ((fact(2) * fact(L2[i] - 2)));
  }

  cout << res;

  cout.precision(30);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n) {
  ll res = 1;
  for (int i = 1; i <= n; i++) {
    res = res * i;
  }
  return res;
}

int main() {
  IOS;
  ll a;
  cin >> a;
  vector<string> L;
  for (int i = 0; i < a; i++) {
    string ch;
    cin >> ch;
    sort(ch.begin(), ch.end());
    L.push_back(ch);
  }
  sort(L.begin(), L.end());
  /*for(int i=0;i<a;i++)
      cout << L[i];*/
  ll str = 1;
  vector<ll> L2;
  for (int i = 0; i < a - 1; i++) {
    if (L[i] == L[i + 1])
      str++;
    else {
      L2.push_back(str);
      str = 1;
    }
  }
  if (str != 1)
    L2.push_back(str);
  ll res = 0;
  for (int i = 0; i < L2.size(); i++) {
    if (L2[i] != 1)
      res += (L2[i] * (L2[i] - 1)) / 2;
  }

  cout << res;

  cout.precision(30);
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
string a[100001];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end());
  }
  sort(a + 1, a + n + 1);
  long long ans = 0;
  long long length = 1;
  /*for(int i=1;i<=n;i++)
  cout<<a[i]<<endl;*/
  for (int i = 1; i <= n; i++) {
    while (a[i] == a[i + 1]) {
      length++;
      i++;
    }
    ans += length * (length - 1) / 2;
    length = 1;
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
string a[500001];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end());
  }
  sort(a + 1, a + n + 1);
  long long ans = 0;
  long long length = 1;
  /*for(int i=1;i<=n;i++)
  cout<<a[i]<<endl;*/
  for (int i = 1; i <= n; i++) {
    while (a[i] == a[i + 1]) {
      length++;
      i++;
    }
    ans += length * (length - 1) / 2;
    length = 1;
  }
  cout << ans;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#define maxn 200100
using namespace std;
int trie1[maxn][26];
int S1[26 * maxn];
int tot1 = 0;
int in(char *s) {
  int root, len;
  len = strlen(s);
  root = 0;
  for (int i = 0; i < len; i++) {
    int id = s[i] - 'a';
    if (!trie1[root][id]) {
      trie1[root][id] = ++tot1;
      S1[tot1] = 0;
    }
    root = trie1[root][id];
    S1[root]++;
  }
  return S1[root] - 1;
}
int main() {
  int N;
  scanf("%d", &N);
  long long ans = 0;
  while (N--) {
    char s[15];
    cin >> s;
    sort(s, s + 10);
    ans += in(s);
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#define maxn 2001000
using namespace std;
int trie1[maxn][26];
int S1[26 * maxn];
int tot1 = 0;
int in(char *s) {
  int root, len;
  len = strlen(s);
  root = 0;
  for (int i = 0; i < len; i++) {
    int id = s[i] - 'a';
    if (!trie1[root][id]) {
      trie1[root][id] = ++tot1;
      S1[tot1] = 0;
    }
    root = trie1[root][id];
    S1[root]++;
  }
  return S1[root] - 1;
}
int main() {
  int N;
  scanf("%d", &N);
  long long ans = 0;
  while (N--) {
    char s[15];
    cin >> s;
    sort(s, s + 10);
    ans += in(s);
  }
  printf("%lld\n", ans);
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // これつけるとA[N]でもいいらしい
// for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main() {
  int 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());
  /*
  rep(i,n){
      cout<<s[i]<<endl;
  }
  */
  int64_t sum = 0;
  int64_t j = 1;
  int i = 0;
  while (i < n) {
    j = 1;
    if (s[i] == s[i + 1]) {
      while (s[i] == s[i + j]) {
        j++;
        if (i + j == n) {
          break;
        }
      }
      // 同じのがj個⇒コンビネーション
      sum += j * (j - 1) / 2;
    }
    i = i + j;
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // これつけるとA[N]でもいいらしい
// for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main() {
  int 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());
  /*
  rep(i,n){
      cout<<s[i]<<endl;
  }
  */
  int64_t sum = 0;
  int64_t j = 1;
  int i = 0;
  while (i < n - 1) {
    j = 1;
    if (s[i] == s[i + 1]) {
      while (s[i] == s[i + j]) {
        j++;
        if (i + j == n) {
          break;
        }
      }
      // 同じのがj個⇒コンビネーション
      sum += j * (j - 1) / 2;
    }
    i = i + j;
  }
  cout << sum << endl;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long co(int x) {
  long long y = 0;
  for (int i = 1; i <= x - 1; i++) {
    y += i;
  }
  return y;
}
int main() {
  int n;
  map<string, int> ma;
  string s[10000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    getchar();
    sort(s[i].begin(), s[i].end());
    ma[s[i]]++;
  }
  map<string, int>::iterator it;
  long long t = 0;
  for (it = ma.begin(); it != ma.end(); it++) {
    if (it->second > 1)
      t += co(it->second);
  }
  printf("%lld", t);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long co(int x) {
  long long y = 0;
  for (int i = 1; i <= x - 1; i++) {
    y += i;
  }
  return y;
}
int main() {
  int n;
  map<string, int> ma;
  string s[100001];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    getchar();
    sort(s[i].begin(), s[i].end());
    ma[s[i]]++;
  }
  map<string, int>::iterator it;
  long long t = 0;
  for (it = ma.begin(); it != ma.end(); it++) {
    if (it->second > 1)
      t += co(it->second);
  }
  printf("%lld", t);
  return 0;
}
Problem p02947 (C++)

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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ << " " <<

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<ll, pair<int, int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;

  map<string, ll> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (mp.find(s) != mp.end()) {
      mp[s]++;
    } else {
      mp[s] = 1;
    }
  }
  ll sum = 0;
  for (auto u : mp) {
    sum += (u.se * (u.se - 1)) / 2;
  }
  cout << sum << endl;

  return 0;
}


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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ << " " <<

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<ll, pair<int, int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int main(int argc, char const *argv[]) {
  // #ifndef ONLINE_JUDGE
  //    	freopen("input.txt", "r", stdin);
  //    	freopen("output.txt", "w", stdout);
  //    	freopen("error.txt", "w", stderr);
  // #endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;

  map<string, ll> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (mp.find(s) != mp.end()) {
      mp[s]++;
    } else {
      mp[s] = 1;
    }
  }
  ll sum = 0;
  for (auto u : mp) {
    sum += (u.se * (u.se - 1)) / 2;
  }
  cout << sum << endl;

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll long long

using namespace std;

const int M = 1000000007;

ll n, a, sol;
string c, h[10];
set<string> s;
map<string, ll> m;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> c;
    for (int i = 0; i < 10; i++)
      h[i] = c.substr(i, 1);
    sort(h, h + 10);
    c = "";
    for (int i = 0; i < n; i++)
      c += h[i];
    s.insert(c);
    m[c]++;
  }

  for (set<string>::iterator it = s.begin(); it != s.end(); it++) {
    a = m[*it];
    if (a == 2)
      sol++;
    if (a > 2)
      sol += (a * (a - 3)) / 2 + a;
  }

  cout << sol;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll long long

using namespace std;

const int M = 1000000007;

ll n, a, sol;
string c, h[10];
set<string> s;
map<string, ll> m;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> c;
    for (int i = 0; i < 10; i++)
      h[i] = c.substr(i, 1);
    sort(h, h + 10);
    c = "";
    for (int i = 0; i < 10; i++)
      c += h[i];
    s.insert(c);
    m[c]++;
  }

  for (set<string>::iterator it = s.begin(); it != s.end(); it++) {
    a = m[*it];
    if (a == 2)
      sol++;
    if (a > 2)
      sol += (a * (a - 3)) / 2 + a;
  }

  cout << sol;

  return 0;
}
Problem p02947 (C++)

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

string s[50000 + 5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s + n);
  long long cnt = 1;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] != s[i + 1] && cnt != 1) {
      sum += (cnt * (cnt - 1)) / 2;
      cnt = 1;
    } else if (s[i] != s[i + 1] && cnt == 1) {
      cnt = 1;
    } else
      cnt++;
  }
  sum += (cnt * (cnt - 1)) / 2;
  cout << sum << endl;
}

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

string s[5000000 + 5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s + n);
  long long cnt = 1;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] != s[i + 1] && cnt != 1) {
      sum += (cnt * (cnt - 1)) / 2;
      cnt = 1;
    } else if (s[i] != s[i + 1] && cnt == 1) {
      cnt = 1;
    } else
      cnt++;
  }
  sum += (cnt * (cnt - 1)) / 2;
  cout << sum << endl;
}
Problem p02947 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if L[i] in dic:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)


Fixed submission:
N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if str(L[i]) in flag:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define cases                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  string a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sort(a[i].begin(), a[i].end());
  }
  ll cnt = 0;
  sort(a, a + n);
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; a[j] == a[i]; j++)
      cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define cases                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  string a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sort(a[i].begin(), a[i].end());
  }
  ll cnt = 0;
  sort(a, a + n);
  for (ll i = 0; i < n - 1; i++) {
    bool temp = false;
    ll d;
    for (ll j = i + 1; a[j] == a[i]; j++) {
      temp = true;
      d = j;
    }
    if (temp) {
      for (int j = 0; j <= (d - i); j++)
        cnt += j;
      i = d;
    }
  }
  cout << cnt << "\n";
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize(3, "Ofast", "inline")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#define ll long long
using namespace std;

int n, tmp[30];
map<string, int> ma;
ll ans = 0, sum = 0;
char c[15];

inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-')
    c = getchar();
  if (c == '-')
    t = -1, c = getchar();
  while (c >= '0' && c <= '9')
    s = s * 10 + c - '0', c = getchar();
  return s * t;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    memset(tmp, 0, sizeof(tmp));
    scanf("%s", c + 1);
    for (int j = 1; j <= 10; j++)
      tmp[c[j] - 'a' + 1]++;
    string s;
    for (int j = 1; j <= 30; j++) {
      for (int k = 1; k <= tmp[j]; k++)
        s += (j + 'a' - 1);
    }
    ma[s]++;
    ans += ma[s] - 1;
  }
  printf("%lld", ans);
}


Fixed submission:
#pragma GCC optimize(3, "Ofast", "inline")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#define ll long long
using namespace std;

int n, tmp[30];
map<string, int> ma;
ll ans = 0, sum = 0;
char c[15];

inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-')
    c = getchar();
  if (c == '-')
    t = -1, c = getchar();
  while (c >= '0' && c <= '9')
    s = s * 10 + c - '0', c = getchar();
  return s * t;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    memset(tmp, 0, sizeof(tmp));
    scanf("%s", c + 1);
    for (int j = 1; j <= 10; j++)
      tmp[c[j] - 'a' + 1]++;
    string s;
    for (int j = 1; j <= 26; j++) {
      for (int k = 1; k <= tmp[j]; k++)
        s += (j + 'a' - 1);
    }
    ma[s]++;
    ans += ma[s] - 1;
  }
  printf("%lld", ans);
}
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;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  int i, j;
  ll cnt = 1, ans = 0;
  rep(i, n) sort(s[i].begin(), s[i].end());
  sort(s.begin(), s.end());
  for (i = 0; i < n - 1; i++) {
    cnt = 1;
    while (s[i] == s[i + cnt]) {
      cnt++;
    }
    ans += cnt - 1;
  }
  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;
using ll = long long;

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

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int inf = 1e9;

int add(int x, int y) { return (1ll * x + 1ll * y) % mod; }

int del(int x, int y) { return ((1ll * x - 1ll * y) % mod + mod) % mod; }

int mul(int x, int y) { return (1ll * x * 1ll * y) % mod; }

const int N = 1e5 + 5;

int n;
string s[N];

long long sum = 0;

vector<string> vec;

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    vec.pb(s[i]);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    int j = i;
    while (vec[i] == vec[j] && j < n)
      j++;
    j--;
    sum += 1ll * (j - i + 1) * (j - i) / (1ll * 2);
    i = j;
  }
  cout << sum;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int inf = 1e9;

int add(int x, int y) { return (1ll * x + 1ll * y) % mod; }

int del(int x, int y) { return ((1ll * x - 1ll * y) % mod + mod) % mod; }

int mul(int x, int y) { return (1ll * x * 1ll * y) % mod; }

const int N = 1e5 + 5;

int n;
string s[N];

long long sum = 0;

vector<string> vec;

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    vec.pb(s[i]);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && vec[i] == vec[j] && j < n)
      j++;
    j--;
    sum += 1ll * (j - i + 1) * (j - i) / (1ll * 2);
    i = j;
  }
  cout << sum;
}
Problem p02947 (C++)

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

int main() {

  string str;
  int n, i, sum = 0;
  long long int tot = 0;
  cin >> n;
  vector<string> vect;
  for (i = 0; i < n; i++) {
    cin >> str;
    sort(str.begin(), str.end());
    vect.push_back(str);
  }
  sort(vect.begin(), vect.end());

  for (i = 0; i < vect.size(); i++) {
    if (vect[i] == vect[i + 1])
      sum++;
    else
      sum = 0;
    tot += sum;
  }
  cout << tot << endl;

  return 0;
}


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

int main() {

  string str;
  int n, i, sum = 0;
  long long int tot = 0;
  cin >> n;
  vector<string> vect;
  for (i = 0; i < n; i++) {
    cin >> str;
    sort(str.begin(), str.end());
    vect.push_back(str);
  }
  sort(vect.begin(), vect.end());

  for (i = 0; i < vect.size() - 1; i++) {
    if (vect[i] == vect[i + 1])
      sum++;
    else
      sum = 0;
    tot += sum;
  }
  cout << tot << endl;

  return 0;
}
Problem p02947 (Python)

Buggy submission (status: Runtime Error):
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    x = factorial(v) / factorial(2) / factorial(v - 2)
    ans += x

print(round(ans))


Fixed submission:
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))
Problem p02947 (Python)

Buggy submission (status: Runtime Error):
# -*- coding:utf-8 -*-

import math

N = int(input())

type_dict = {}
for _ in range(N):
    s = input()
    counts = (
        s.count("a"),
        s.count("b"),
        s.count("c"),
        s.count("d"),
        s.count("e"),
        s.count("f"),
        s.count("g"),
        s.count("h"),
        s.count("i"),
        s.count("j"),
        s.count("k"),
        s.count("l"),
        s.count("m"),
        s.count("n"),
        s.count("o"),
        s.count("p"),
        s.count("q"),
        s.count("r"),
        s.count("s"),
        s.count("t"),
        s.count("u"),
        s.count("v"),
        s.count("w"),
        s.count("x"),
        s.count("y"),
        s.count("z"),
    )
    if counts in type_dict:
        type_dict[counts] = type_dict[counts] + 1
    else:
        type_dict[counts] = 1


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1]))


Fixed submission:
# -*- coding:utf-8 -*-

import math

N = int(input())

type_dict = {}
for _ in range(N):
    s = input()
    counts = (
        s.count("a"),
        s.count("b"),
        s.count("c"),
        s.count("d"),
        s.count("e"),
        s.count("f"),
        s.count("g"),
        s.count("h"),
        s.count("i"),
        s.count("j"),
        s.count("k"),
        s.count("l"),
        s.count("m"),
        s.count("n"),
        s.count("o"),
        s.count("p"),
        s.count("q"),
        s.count("r"),
        s.count("s"),
        s.count("t"),
        s.count("u"),
        s.count("v"),
        s.count("w"),
        s.count("x"),
        s.count("y"),
        s.count("z"),
    )
    if counts in type_dict:
        type_dict[counts] = type_dict[counts] + 1
    else:
        type_dict[counts] = 1


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


print(sum([combinations_count(x, 2) for x in type_dict.values() if x > 1]))
Problem p02947 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = sorted(input())

        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = "".join(sorted(input()))
        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)


if __name__ == "__main__":
    main()
Problem p02947 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    s.sort()
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)


def SortString(text):
    return "".join(sorted(list(text)))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    sDictionary = {}
    for i in range(n):
        if sDictionary.get(s[i]):
            ans += sDictionary.get(s[i])
            sDictionary[s[i]] += 1
        else:
            sDictionary[s[i]] = 1
    print(ans)


def SortString(text):
    return "".join(sorted(list(text)))


if __name__ == "__main__":
    main()
Problem p02947 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    print(S)
    S[s] += 1
    ans += S[s]
print(ans)


Fixed submission:
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    S[s] += 1
    ans += S[s]
print(ans)
Problem p02947 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
acc = [0] * 11
for i in range(10):
    acc[i + 1] = acc[i] + (i + 1)
n = int(input())
s = [input() for _ in range(n)]
dic = {}
for i in range(n):
    srt = "".join(sorted(s[i]))
    dic[srt] = dic[srt] + 1 if srt in dic else 1
ans = 0
for v in dic.values():
    ans += acc[v - 1]
print(ans)


Fixed submission:
#!/usr/bin/env python3
acc = [0] * (10**5 + 1)
for i in range(10**5):
    acc[i + 1] = acc[i] + (i + 1)
n = int(input())
s = [input() for _ in range(n)]
dic = {}
for i in range(n):
    srt = "".join(sorted(s[i]))
    dic[srt] = dic[srt] + 1 if srt in dic else 1
ans = 0
for v in dic.values():
    ans += acc[v - 1]
print(ans)
Problem p02947 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)
Problem p02947 (Python)

Buggy submission (status: Time Limit Exceeded):
x = []
cnt = 0
for _ in range(int(input())):
    a = sorted(input())
    cnt += x.count(a)
    x.append(a)
print(cnt)


Fixed submission:
import collections

n = int(input())
x = ["".join(sorted(input())) for _ in range(n)]
a = collections.Counter(x)
print(sum(i * ~-i // 2 for i in a.values()))
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define popb pop_back
#define mem(a, b) memset(a, b, sizeof(a))
#define i first
#define j second
#define inf 2e9
#define MOD 1000000007
#define M 100007
void FAST() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void solve() {}
bool cmp(string s, string t) {
  int x = s.compare(t);
  if (x <= 0)
    return 1;
  return 0;
}
int main() {
  FAST();
  ll n;
  cin >> n;
  string arr[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sort(arr[i].begin(), arr[i].end());
  }
  sort(arr, arr + n, cmp);
  ll ans = 0;
  int i = 0;
  while (i < n) {
    int j = i + 1;
    while (j < n && arr[i].compare(arr[j]) == 0) {
      ++j;
    }
    //  cout<<i<<" "<<j<<"\n";

    ans += ((j - i) * 1LL * (j - i - 1)) / 2;
    i = j;
  }
  cout << ans << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define popb pop_back
#define mem(a, b) memset(a, b, sizeof(a))
#define i first
#define j second
#define inf 2e9
#define MOD 1000000007
#define M 100007
void FAST() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void solve() {}
bool cmp(string s, string t) {
  int x = s.compare(t);
  if (x <= 0)
    return 1;
  return 0;
}
int main() {
  FAST();
  ll n;
  cin >> n;
  string arr[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sort(arr[i].begin(), arr[i].end());
  }
  sort(arr, arr + n);
  ll ans = 0;
  int i = 0;
  while (i < n) {
    int j = i + 1;
    while (j < n && arr[i].compare(arr[j]) == 0) {
      ++j;
    }
    //  cout<<i<<" "<<j<<"\n";

    ans += ((j - i) * 1LL * (j - i - 1)) / 2;
    i = j;
  }
  cout << ans << "\n";

  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize(3)
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define lowbit(x) x & (-x)
typedef long long ll;
typedef long double lb;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const int maxn = 1000;
int read();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  std::vector<string> v(maxn);
  map<string, int> mp;
  string str;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    sort(str.begin(), str.end());
    v.at(i) = str;
    mp[str]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    string s = v.at(i);
    if (mp[s] > 0)
      ans += mp[s] - 1;
    mp[s]--;
  }
  cout << ans << endl;

  return 0;
}
inline int read() {
  int x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= (ch == '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}


Fixed submission:
// #pragma GCC optimize(3)
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define lowbit(x) x & (-x)
typedef long long ll;
typedef long double lb;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const int maxn = 100005;
int read();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  std::vector<string> v(maxn);
  map<string, int> mp;
  string str;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    sort(str.begin(), str.end());
    v.at(i) = str;
    mp[str]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    string s = v.at(i);
    if (mp[s] > 0)
      ans += mp[s] - 1;
    mp[s]--;
  }
  cout << ans << endl;

  return 0;
}
inline int read() {
  int x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= (ch == '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
Problem p02947 (C++)

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

char a[10];
vector<string> s;
string t;
long long n, i, j, ans = 0;
int main() {
  cin >> n;
  for (j = 0; j < n; j++) {
    for (i = 0; i < 10; i++) {
      cin >> a[i];
    }
    sort(a, a + 10);
    t = a;
    s.push_back(t);
    // cout << s;
    /*for (i = 0; i < 10; i++){
            cout << a[i];
    }*/
  }
  sort(s.begin(), s.end());
  // cout << s[0] << endl;
  j = 0;
  for (i = 0; i < n - 1; i++) {
    while (j < n && (s[i] == s[j + 1] || j < i)) {
      j++;
    }
    if (s[i] == s[j])
      ans += j - i;
    if (i == j)
      j++;
  }
  cout << ans << endl;
  return 0;
}


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

char a[10];
vector<string> s;
string t;
long long n, i, j, ans = 0;
int main() {
  cin >> n;
  for (j = 0; j < n; j++) {
    for (i = 0; i < 10; i++) {
      cin >> a[i];
    }
    sort(a, a + 10);
    t = a;
    s.push_back(t);
    // cout << s;
    /*for (i = 0; i < 10; i++){
            cout << a[i];
    }*/
  }
  sort(s.begin(), s.end());
  // cout << s[0] << endl;
  j = 0;
  for (i = 0; i < n - 1; i++) {
    while (j < n - 1 && (s[i] == s[j + 1] || j < i)) {
      j++;
    }
    if (s[i] == s[j])
      ans += j - i;
    if (i == j)
      j++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

const int MOD = 1000000007;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  VS s(n);
  rep(i, n) cin >> s.at(i);
  rep(i, n) { sort(all(s.at(i))); }
  LL ans = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      if (s.at(i) == s.at(j))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

const int MOD = 1000000007;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  VS s(n);
  rep(i, n) cin >> s.at(i);
  rep(i, n) { sort(all(s.at(i))); }
  LL ans = 0;
  map<string, int> mp;
  rep(i, n) { mp[s.at(i)]++; }
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    LL m = itr->second;
    ans += m * (m - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

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

int main(void) {
  int n;
  long long ans = 0;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j])
        ans++;
    }
  }

  cout << ans;
}


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

int main(void) {
  int n;
  long long ans = 0;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s + n);
  long long x = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      x++;
      if (i == n - 1) {
        ans += (x * (x + 1)) / 2;
        break;
      }
    } else {
      ans += (x * (x + 1)) / 2;
      x = 0;
    }
  }

  cout << ans;
}
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() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];
  int ans = 0;
  rep(k, N) {
    rep(i, 10) {
      if (s[1][i] == s[k][i]) {
        s[k].erase(s[k].begin() + i);
      }
    }
    if (sizeof(s[k]) == 0) {
      ans++;
    }
  }
  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() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto &p : mp) {
    int s = p.second;
    ans += (ll)s * (s - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}
Problem p02947 (C++)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vs s(n);
  rep(i, n) cin >> s[i];
  vector<map<char, int>> sm(n);
  rep(i, n) { rep(j, 10) sm[i][s[i][j]]++; }
  int ans = 0;
  rep(i, n - 1) for (int j = i + 1; j < n; ++j) {
    if (sm[i] == sm[j])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  map<string, int> sm;
  rep(i, n) {
    string s;
    cin >> s;
    sort(all(s));
    sm[s]++;
  }
  auto sigma = [&](int n) {
    ll ans = 0;
    rep1(i, n) ans += i;
    return ans;
  };
  ll ans = 0;
  for (pair<string, int> num : sm) {
    ans += sigma(num.second - 1);
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  int n;
  cin >> n;
  string s[n];
  ll sum = 0;
  map<string, ll> mp;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    if (mp[s[i]]) {
      sum += mp[s[i]];
    }
    mp[s[i]]++;
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s[n];
  ll sum = 0;
  map<string, ll> mp;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    if (mp[s[i]]) {
      sum += mp[s[i]];
    }
    mp[s[i]]++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02947 (C++)

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

int main(void) {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  rep(i, n) { sort(s.at(i).begin(), s.at(i).end()); }
  int ans = 0;
  rep(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      if (s.at(i) == s.at(j))
        ans++;
    }
  }
  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;
typedef pair<int, int> P;

int main(void) {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto &p : mp) {
    ll s = p.second;
    ans += s * (s - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}