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

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  for (int i = 0; i < k; ++i) {
    string t = s;
    reverse(t.begin(), t.end());
    string x = s + t;

    vector<string> tmp;
    for (int i = 0; i < n; ++i) {
      tmp.emplace_back(x.substr(i, n));
    }
    sort(tmp.begin(), tmp.end());
    s = *min_element(tmp.begin(), tmp.end());
    reverse(s.begin(), s.end());
  }

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

  cout << s << '\n';

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  for (int i = 0; i < k; ++i) {
    if (*min_element(s.begin(), s.end()) == *max_element(s.begin(), s.end())) {
      break;
    }
    string t = s;
    reverse(t.begin(), t.end());
    string x = s + t;

    vector<string> tmp;
    for (int i = 0; i < n; ++i) {
      tmp.emplace_back(x.substr(i, n));
    }
    sort(tmp.begin(), tmp.end());
    s = *min_element(tmp.begin(), tmp.end());
    reverse(s.begin(), s.end());
  }

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

  cout << s << '\n';

  return 0;
}
Problem p02943 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
char s[N];
int p[N];
signed main() {
  int n, K;
  long long res = 1;
  cin >> n >> K;
  for (int i = 2; i <= K; ++i) {
    res *= 2;
    if (res >= n) {
      res = n;
      break;
    }
  }
  cin >> (s + 1);
  for (int i = n + 1; i <= n + n; ++i)
    s[i] = s[i - n];
  reverse(s + n + 1, s + n + n + 1);
  char ch = *min_element(s + 1, s + n + 1);
  int cnt = (s[1] == ch);
  for (int i = 2; i <= n + n; ++i)
    if (s[i] == ch && s[i] == s[i - 1])
      ++cnt;
    else
      p[i - 1] = cnt, cnt = (s[i] == ch);
  p[n + n] = cnt;
  int mx = *max_element(p + n + 1, p + n + n + 1);
  res *= mx;
  if (res >= n) {
    for (int i = 1; i <= n; ++i)
      cout << ch;
    return 0;
  }
  string S = "", tmp;
  for (int i = n + 1; i <= n + n; ++i)
    if (p[i] == mx) {
      tmp = "";
      for (int j = 1; j <= res; ++j)
        tmp += ch;
      for (int j = i - p[i]; j > i - p[i] - (n - res); --j)
        tmp += s[j];
      if (S == "")
        S = tmp;
      else
        S = min(S, tmp);
    }
  cout << S;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
char s[N];
int p[N];
signed main() {
  int n, K;
  long long res = 1;
  cin >> n >> K;
  for (int i = 2; i <= K; ++i) {
    res *= 2;
    if (res >= n) {
      res = n;
      break;
    }
  }
  cin >> (s + 1);
  for (int i = n + 1; i <= n + n; ++i)
    s[i] = s[i - n];
  reverse(s + n + 1, s + n + n + 1);
  char ch = *min_element(s + 1, s + n + 1);
  int cnt = (s[1] == ch);
  for (int i = 2; i <= n + n; ++i)
    if (s[i] == ch && s[i] == s[i - 1])
      ++cnt;
    else
      p[i - 1] = cnt, cnt = (s[i] == ch);
  p[n + n] = cnt;
  int mx = *max_element(p + n + 1, p + n + n + 1);
  res *= mx;
  if (res >= n) {
    for (int i = 1; i <= n; ++i)
      cout << ch;
    return 0;
  }
  string S = "", tmp;
  for (int i = n + 1; i <= n + n; ++i)
    if (p[i] == mx) {
      tmp = "";
      for (int j = 1; j <= res; ++j)
        tmp += ch;
      for (int j = i - p[i]; j > i - p[i] - (n - res); --j)
        tmp += s[j];
      if (S == "")
        S = tmp;
      else
        S = min(S, tmp);
    }
  cout << S;
  return 0;
}
Problem p02943 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;

int n, k, L[N];
string s;

int main() {
  cin >> n >> k >> s;
  char mn = *min_element(s.begin(), s.end());
  string t = s;
  reverse(t.begin(), t.end());
  t = s + t;
  for (int i = 0; i < n + n; i++) {
    if (i && t[i] == mn)
      L[i] = L[i - 1] + 1;
    else
      L[i] = 0;
  }
  int mx = *max_element(L, L + n + n), len = mx;
  while (k > 1 && len < n)
    --k, len <<= 1;
  if (len >= n)
    cout << string(n, mn);
  else {
    string ans;
    for (int i = n - 1; i < n + n; i++)
      if (L[i] == mx) {
        string tmp = string(len, mn) + t.substr(n + n - 1 - i + mx, n - len);
        if (ans.empty() || ans > tmp)
          ans = tmp;
      }
    cout << ans;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;

int n, k, L[N];
string s;

int main() {
  cin >> n >> k >> s;
  char mn = *min_element(s.begin(), s.end());
  string t = s;
  reverse(t.begin(), t.end());
  t = s + t;
  for (int i = 0; i < n + n; i++) {
    if (i && t[i] == mn)
      L[i] = L[i - 1] + 1;
    else
      L[i] = 0;
  }
  int mx = *max_element(L, L + n + n), len = mx;
  while (k > 1 && len < n)
    --k, len <<= 1;
  if (len >= n)
    cout << string(n, mn);
  else {
    string ans;
    for (int i = n - 1; i < n + n; i++)
      if (L[i] == mx) {
        string tmp = string(len, mn) + t.substr(n + n - 1 - i + mx, n - len);
        if (ans.empty() || ans > tmp)
          ans = tmp;
      }
    cout << ans;
  }
  return 0;
}
Problem p02945 (Python)

Buggy submission (status: Runtime Error):
A, B = int(input().split())
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))


Fixed submission:
A, B = map(int, input().split())
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))
Problem p02945 (Python)

Buggy submission (status: Runtime Error):
a, b = input("").split("")

seki = int(a) * int(b)
sa = int(a) - int(b)
wa = int(a) + int(b)

if wa >= seki and wa >= sa:
    print(wa)
elif sa >= wa and sa >= seki:
    print(sa)
else:
    print(seki)


Fixed submission:
a, b = input().split()

seki = int(a) * int(b)
sa = int(a) - int(b)
wa = int(a) + int(b)

if wa >= seki and wa >= sa:
    print(wa)
elif sa >= wa and sa >= seki:
    print(sa)
else:
    print(seki)
Problem p02945 (Python)

Buggy submission (status: Runtime Error):
A = int(input())
B = int(input())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)


Fixed submission:
A, B = map(int, input().split())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)
Problem p02945 (Python)

Buggy submission (status: Runtime Error):
A = int(input())
B = input()

answer = max(
    A + B,
    A - B,
    A * B,
)

print(answer)


Fixed submission:
data = input()
data = data.split(" ")

A = int(data[0])
B = int(data[1])

answer = max(
    A + B,
    A - B,
    A * B,
)

print(answer)
Problem p02945 (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 a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b);
}


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 a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b);
}
Problem p02945 (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, m;
  cin >> n >> m;
  cout << max(n + m, max(n - m, m * n));
  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();

  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  ll n, m;
  cin >> n >> m;
  cout << max(n + m, max(n - m, m * n));
  return 0;
}
Problem p02945 (C++)

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

int main(void) {
  int A, B;
  cin >> A >> B;
  int max = -20000;

  if (A + B > max)
    max = A + B;
  if (A - B > max)
    max = A - B;
  if (A * B > max)
    max = A * B;
  return max;
}

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

int main(void) {
  int A, B;
  cin >> A >> B;
  int max = -20000;

  if (A + B > max)
    max = A + B;
  if (A - B > max)
    max = A - B;
  if (A * B > max)
    max = A * B;
  cout << max << endl;

  return 0;
}
Problem p02945 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int sum(int x, int y) { return x + y; }
int sub(int x, int y) { return x - y; }
int mul(int x, int y) { return x * y; }
int main() {
  int a, b, sm, sb, ml, gr;
  scanf("%d %d", &a, &b);
  sm = sum(a, b);
  sb = sub(a, b);
  ml = mul(a, b);
  if (sm > sb && sm > ml)
    gr = sm;
  else if (sb > sm && sb > ml)
    gr = sb;
  else if (ml > sm && ml > sb)
    gr = ml;

  printf("%d\n", gr);
  main();
  return 0;
}

Fixed submission:
#include <stdio.h>
int sum(int x, int y) { return x + y; }
int sub(int x, int y) { return x - y; }
int mul(int x, int y) { return x * y; }
int main() {
  int a, b, sm, sb, ml, gr;
  scanf("%d %d", &a, &b);
  sm = sum(a, b);
  sb = sub(a, b);
  ml = mul(a, b);
  if (sm > sb && sm > ml)
    gr = sm;
  else if (sb > sm && sb > ml)
    gr = sb;
  else if (ml > sm && ml > sb)
    gr = ml;

  printf("%d\n", gr);
  return 0;
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  freopen("INP.txt", "r", stdin);
  freopen("OUT.txt", "w", stdout);
  ll a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("INP.txt", "r", stdin);
  // freopen("OUT.txt", "w", stdout);
  ll a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << '\n';
  return 0;
}
Problem p02945 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
s = [list(input()) for _ in range(N)]
S = []
for i in range(N):
    S.append("".join(sorted(s[i])))
print(S)

cnt = 0
for i in range(N):
    cnt += S.count(S[i]) - 1
print(int(cnt / 2))


Fixed submission:
A, B = map(int, input().split())
print(max(A + B, A - B, A * B))
Problem p02945 (C++)

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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> V;
  V.at(0) = A + B;
  V.at(1) = A - B;
  V.at(2) = A * B;
  sort(V.begin(), V.end());
  cout << V.at(2) << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> V(3);
  V.at(0) = A + B;
  V.at(1) = A - B;
  V.at(2) = A * B;
  sort(V.begin(), V.end());
  cout << V.at(2) << endl;
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int max(int x, int y) { return (x > y ? x : y); }

int main() {
  int a, b;
  cin >> a >> b;
  int ans = max(a + b, a - b);
  ans = max(ans, a * b);
  return ans;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int max(int x, int y) { return (x > y ? x : y); }

int main() {
  int a, b;
  cin >> a >> b;
  int ans = max(a + b, a - b);
  ans = max(ans, a * b);
  cout << ans;
}
Problem p02945 (C++)

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

int a, b;

void solve() {
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << endl;
}

signed main() {
  while (1)
    solve();
}

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

int a, b;

void solve() {
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << endl;
}

signed main() {
  // while(1)
  solve();
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {

  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int a, b;
  cin >> a >> b;
  cout << max(a - b, max(a + b, a * b));
}


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {

  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  // #ifndef ONLINE_JUDGE
  //    freopen("input.txt" , "r" , stdin);
  // freopen("output.txt" , "w" , stdout);
  // #endif
  int a, b;
  cin >> a >> b;
  cout << max(a - b, max(a + b, a * b));
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define fill(a, val) memset(a, val, sizeof(a))
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(),v.end()]
#define endl "\n"
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const ll N = 1000 * 100 + 5;
const ll N2 = 1000 * 1000;
const double PI = 3.14159265;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
// comment for all except cc/cf
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  fastio();
  int a, b;
  cin >> a >> b;
  int s[3];
  s[0] = a + b;
  s[1] = a - b;
  s[2] = a * b;
  sort(s, s + 3);
  cout << s[2];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define fill(a, val) memset(a, val, sizeof(a))
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(),v.end()]
#define endl "\n"
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const ll N = 1000 * 100 + 5;
const ll N2 = 1000 * 1000;
const double PI = 3.14159265;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  // comment for all except cc/cf
  /*
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("out.txt","w",stdout);
#endif*/
  fastio();
  int a, b;
  cin >> a >> b;
  int s[3];
  s[0] = a + b;
  s[1] = a - b;
  s[2] = a * b;
  sort(s, s + 3);
  cout << s[2];
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, b;
  scanf("%d%d", a, b);
  int c, d, e;
  c = a + b;
  d = a - b;
  e = a * b;
  if (c >= d && c >= e) {
    printf("%d", c);
  } else if (d > c && d >= e) {
    printf("%d", d);
  } else {
    printf("%d", e);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int c, d, e;
  c = a + b;
  d = a - b;
  e = a * b;
  if (c >= d && c >= e) {
    printf("%d", c);
  } else if (d > c && d >= e) {
    printf("%d", d);
  } else {
    printf("%d", e);
  }
  return 0;
}
Problem p02945 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int A, B, sum, sub, mult;
  cin >> A >> B;
  while (A <= 100 && A >= -100) {
    if (B <= 100 && B >= -100)
      continue;
    sum = A + B;
    sub = A - B;
    mult = A * B;
    if (sum > sub && sum > mult) {
      cout << sum;
      break;
    } else if (sub > sum && sub > mult) {
      cout << sub;
      break;
    } else {
      cout << mult;
      break;
    }
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b));
  return 0;
}
Problem p02945 (C++)

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

int main() {
  int A, B;
  cin >> A >> B;

  int X = A + B;
  int Y = A - B;
  int Z = A * B;

  vector<int> vec;
  vec = {X, Y, Z};

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

  cout << vec.at(3) << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;

  int X = A + B;
  int Y = A - B;
  int Z = A * B;

  vector<int> vec;
  vec = {X, Y, Z};

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

  cout << vec.at(2) << endl;
}
Problem p02945 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<ll, int>
#define vi vector<double>
#define vvi vector<vector<double>>
#define vpii vector<pii>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("text.txt", "r", stdin);
#endif

  int t = 1;
  // cin>>t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int u = max((a + b), max(a - b, a * b));
    cout << u << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<ll, int>
#define vi vector<double>
#define vvi vector<vector<double>>
#define vpii vector<pii>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int t = 1;
  // cin>>t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int u = max((a + b), max(a - b, a * b));
    cout << u << endl;
  }
  return 0;
}
Problem p02945 (C++)

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

#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) (x).size()
#define fir first
#define sec second

void scan() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], pre[maxn];

int main() {
  scan();

  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int a, b, c;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;

  return 0;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) (x).size()
#define fir first
#define sec second

void scan() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], pre[maxn];

int main() {
  // scan();

  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int a, b, c;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;

  return 0;
}
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int K, X;
  cin >> K >> X;
  int c[K];
  if (X + K <= 1000000 && X - K >= -1000000) {

    for (int i = 0; i < K + K - 1; i++) {
      c[i] = X - K + i + 1;
      cout << c[i];
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int K, X;
  cin >> K >> X;
  int c[100000];
  for (int i = 0; i < 2 * K - 1; i++) {
    c[i] = X - K + i + 1;
    cout << c[i] << " ";
  }
  return 0;
}
Problem p02946 (C++)

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

using namespace std;

int k;
int x;

int main() {
  cin >> k >> x;
  int a[k];

  for (int i = 0; i < (2 * k - 1); ++i) {
    a[i] = x - k + 1 + i;
  }

  for (int j = 0; j < (2 * k - 1); ++j) {
    cout << a[j] << " ";
  }
  cout << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int k;
int x;

int main() {
  cin >> k >> x;
  int a[2 * k - 1];

  for (int i = 0; i < (2 * k - 1); ++i) {
    a[i] = x - k + 1 + i;
  }

  for (int j = 0; j < (2 * k - 1); ++j) {
    cout << a[j] << " ";
  }
  cout << endl;
}
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, x;
  while (cin >> k >> x) {
    int s = 0;
    if (x - k <= 0)
      s = x + k;
    int a[200] = {0};
    for (int i = x - k + 1 + s; i <= k + s; i++)
      a[i] = 1;
    for (int i = k + 1 + s; i < k + x + s; i++)
      a[i] = 1;
    for (int i = x - k + 1 + s; i < k + x + s; i++) {
      if (a[i] == 1)
        cout << i - s;
      if (i == k + x - 1 + s)
        cout << endl;
      else
        cout << " ";
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, x;
  while (cin >> k >> x) {
    int s = 0;
    if (x - k + 1 < 0)
      s = -(x - k + 1);
    int a[200] = {0};
    for (int i = x - k + 1 + s; i <= k + s; i++)
      a[i] = 1;
    for (int i = k + 1 + s; i < k + x + s; i++)
      a[i] = 1;
    for (int i = x - k + 1 + s; i < k + x + s; i++) {
      if (a[i] == 1)
        cout << i - s;
      if (i == k + x - 1 + s)
        cout << endl;
      else
        cout << " ";
    }
  }
  return 0;
}
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int K, X;
  cin >> K >> X;
  vector<int> ans(2 * X - 1);
  REP(i, 2 * X - 1) { ans[i] = X - K + i; }
  REP(i, 2 * X - 1) cout << ans[i];
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int K, X;
  cin >> K >> X;
  vector<int> ans(2 * K - 1);
  REP(i, 2 * K - 1) { ans[i] = X - K + 1 + i; }
  REP(i, 2 * K - 1) cout << ans[i] << ' ';
}
Problem p02946 (Python)

Buggy submission (status: Runtime Error):
import numpy as np

K, X = map(int, input().split())

tmp = X + K
tmp2 = X - K + 1

ans = np.arange(tmp2, tmp)
for i, v in enumerate(ans):
    print(f" {v}", end="") if i > 0 else print(f"{v}", end="")
print("")


Fixed submission:
import numpy as np

K, X = map(int, input().split())

tmp = X + K
tmp2 = X - K + 1

ans = np.arange(tmp2, tmp)
for i, v in enumerate(ans):
    print(" {}".format(v), end="") if i > 0 else print("{}".format(v), end="")
print("")
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;

void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const ll MN = 200 + 10;
const ll mod = 1e6;

ll a[MAXN * 2];
bool mark[3 * MAXN];

int main() {
  faster();
  ll x, k, ans = 0;
  cin >> k >> x;
  for (int i = -1e6; i <= 1e6; i++) {
    if (abs(x - i) < k)
      mark[i] = true;
  }
  for (int i = -1e6; i <= 1e6; i++) {
    if (mark[i])
      cout << i << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;

void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const ll MN = 200 + 10;
const ll mod = 1e6;

ll a[MAXN * 2];
bool mark[3 * MAXN];

int main() {
  faster();
  ll x, k, ans = 0;
  cin >> k >> x;
  for (int i = -1e6; i <= 1e6; i++) {
    if (abs(x - i) < k)
      cout << i << " ";
  }
  cout << endl;
}
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, i, e[110];
  cin >> a >> b;
  c = b - a + 1;
  d = b + a;
  for (i = 0; i < 2 * a; i++) {
    e[i] = c;
    c++;
    if (c >= d)
      break;
  }
  for (i = 0; i < 2 * a - 1; i++) {
    cout << e[i] << " ";
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, i, e[1000];
  cin >> a >> b;
  c = b - a + 1;
  d = b + a;
  for (i = 0; i < 2 * a; i++) {
    e[i] = c;
    c++;
    if (c >= d)
      break;
  }
  for (i = 0; i < 2 * a - 1; i++) {
    cout << e[i] << " ";
  }
  return 0;
}
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
int main() {
  int k, x;
  int m, p;
  int ans[105];

  cin >> k >> x;
  m = x - k + 1;
  rep(i, k * 2 - 1) {
    ans[i] += m + i;
    cout << ans[i] << " ";
  }

  cout << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
int main() {
  int k, x;
  int m, p;
  int ans[105];

  cin >> k >> x;
  m = x - k + 1;
  rep(i, k * 2 - 1) {
    ans[i] = m + i;
    cout << ans[i] << " ";
  }

  cout << endl;
  return 0;
}
Problem p02946 (Python)

Buggy submission (status: Runtime Error):
k, x = map(int, input().split())
print(" ".join([x for x in range(x - k + 1, x + k)]))


Fixed submission:
k, x = map(int, input().split())
print(" ".join([str(i) for i in range(x - k + 1, x + k)]))
Problem p02946 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int k, x;
  scanf("%d %d", k, x);

  for (int i = x - k + 1; i <= x + k - 1; i++) {
    printf("%d ", i);
  }
  printf("\n");

  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int k, x;
  scanf("%d %d", &k, &x);

  for (int i = x - k + 1; i <= x + k - 1; i++) {
    printf("%d ", i);
  }
  printf("\n");

  return 0;
}
Problem p02947 (C++)

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

int main() {
  ll N, count = 0;
  cin >> N;
  vector<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; i++) {
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j]) {
        count++;
      }
    }
  }
  cout << count << endl;
}


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

int main() {
  ll N, count = 0;
  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());
  ll huga = 0;
  for (int i = 0; i < N - 1; i++) {
    if (s[i] == s[i + 1]) {
      count = count + huga + 1;
      huga++;
    } else {
      huga = 0;
    }
  }
  cout << count << endl;
}
Problem p02947 (C++)

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

#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

  S[N] = ("zzzzzzzzzzz");
  sort(S.begin(), S.end());

  long long count = 0;
  for (int i = 0; i < N + 1; i++) {
    // cout<<S[i]<<endl;
    if (S[i] == S[i + 1]) {
      count++;
    } else {
      ans += count * (count + 1) / 2;
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>

#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

  S[N] = ("zzzzzzzzzzz");
  sort(S.begin(), S.end());

  long long count = 0;
  for (int i = 0; i < N; i++) {
    // cout<<S[i]<<endl;
    if (S[i] == S[i + 1]) {
      count++;
    } else {
      ans += count * (count + 1) / 2;
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll = (1ull << 63) - 1, mod = 1e9 + 7;
const int inf = (1ull << 31) - 1;
int n;
ll ans = 0;
string a;
unordered_map<string, int> mp;

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(18);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    sort(a.begin(), a.end());
    mp[a]++;
    a.clear();
  }
  for (auto t : mp) {
    ll r = t.second;
    ans += (((r - 1) * r) >> 1);
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll = (1ull << 63) - 1, mod = 1e9 + 7;
const int inf = (1ull << 31) - 1;
int n;
ll ans = 0;
string a;
unordered_map<string, int> mp;

int main() {
  // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(18);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    sort(a.begin(), a.end());
    mp[a]++;
    a.clear();
  }
  for (auto t : mp) {
    ll r = t.second;
    ans += (((r - 1) * r) >> 1);
  }
  cout << ans;
  return 0;
}
Problem p02947 (C++)

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

#define FOR(i, a, b) for (ll(i) = a; (i) < (b); ++(i))
#define RFOR(i, a, b) for (ll(i) = a; (i) >= (b); --(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v)                                                                \
  sort(ALL(v));                                                                \
  v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL << (n))
#define DEBUG(a) cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9 + 7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int N;
int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
               43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
ull s;
unordered_map<ull, ll> num;

ull convert(string input) {
  ull ret = 1;
  for (char &c : input) {
    ret *= prime[c - 'a'];
  }
  // cout << ret << endl;
  return ret;
}

int main() {
  cin >> N;
  string input;
  for (int i = 0; i < N; i++) {
    cin >> input;
    s = convert(input);
    bool exist = false;
    for (auto n : num) {
      if (n.first == s) {
        num[n.first] = n.second + 1;
        exist = true;
        break;
      }
    }
    if (exist == false) {
      num[s] = 1;
    }
  }

  ll result = 0;
  for (auto n : num) {
    // cout << n.first << "=" << n.second << endl;
    result += n.second * (n.second - 1) / 2;
  }
  cout << result << endl;
}


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

#define FOR(i, a, b) for (ll(i) = a; (i) < (b); ++(i))
#define RFOR(i, a, b) for (ll(i) = a; (i) >= (b); --(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v)                                                                \
  sort(ALL(v));                                                                \
  v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL << (n))
#define DEBUG(a) cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9 + 7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int N;
int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
               43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
ull s;
unordered_map<ull, ll> num;

ull convert(string input) {
  ull ret = 1;
  for (char &c : input) {
    ret *= prime[c - 'a'];
  }
  // cout << ret << endl;
  return ret;
}

int main() {
  cin >> N;
  string input;
  for (int i = 0; i < N; i++) {
    cin >> input;
    s = convert(input);
    num[s]++;
  }

  ll result = 0;
  for (auto n : num) {
    // cout << n.first << "=" << n.second << endl;
    result += n.second * (n.second - 1) / 2;
  }
  cout << result << endl;
}
Problem p02947 (C++)

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

int main() {
  const int MAX_N = 1e3 + 10;
  int N;
  string S[MAX_N];
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    int a[10];
    for (int j = 0; j < 10; ++j) {
      a[j] = s[j] - 0;
    }
    sort(a, a + 10);
    for (int j = 0; j < 10; ++j) {
      s[j] = a[j];
    }
    S[i] = s;
  }
  sort(S, S + N);

  long long ans = 0;
  long long sum = 1;
  string n, p = S[0];
  for (int i = 1; i < N; ++i) {
    n = S[i];
    if (p == n) {
      sum += 1;
    } else {
      ans += sum * (sum - 1) / 2;
      sum = 1;
    }
    p = n;
  }
  ans += sum * (sum - 1) / 2;

  cout << ans << endl;
}

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

int main() {
  const int MAX_N = 1e5 + 10;
  int N;
  string S[MAX_N];
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    int a[10];
    for (int j = 0; j < 10; ++j) {
      a[j] = s[j] - 0;
    }
    sort(a, a + 10);
    for (int j = 0; j < 10; ++j) {
      s[j] = a[j];
    }
    S[i] = s;
  }
  sort(S, S + N);

  long long ans = 0;
  long long sum = 1;
  string n, p = S[0];
  for (int i = 1; i < N; ++i) {
    n = S[i];
    if (p == n) {
      sum += 1;
    } else {
      ans += sum * (sum - 1) / 2;
      sum = 1;
    }
    p = n;
  }
  ans += sum * (sum - 1) / 2;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  int i = 0;
  ll cnt = 0;
  cin >> n;
  vector<string> s(n);
  for (int j = 0; j < n; j++) {
    cin >> s[j];
    sort(s[j].begin(), s[j].end());
  }
  sort(s.begin(), s.end());
  while (i < n) {
    ll tempcnt = 0;
    while (i < n && s[i] != s[i - 1]) {
      i++;
    }
    while (i < n && s[i] == s[i - 1]) {
      tempcnt++;
      cnt += tempcnt;
      i++;
    }
  }
  cout << cnt;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  int i = 1;
  ll cnt = 0;
  cin >> n;
  vector<string> s(n);
  for (int j = 0; j < n; j++) {
    cin >> s[j];
    sort(s[j].begin(), s[j].end());
  }
  sort(s.begin(), s.end());
  while (i < n) {
    ll tempcnt = 0;
    while (i < n && s[i] != s[i - 1]) {
      i++;
    }
    while (i < n && s[i] == s[i - 1]) {
      tempcnt++;
      cnt += tempcnt;
      i++;
    }
  }
  cout << cnt;

  return 0;
}
Problem p02947 (C++)

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

using namespace std;

int main(void) {
  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());
  }
  long long cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S[i] == S[j])
        cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  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());
  }
  long long cnt = 0;
  unordered_map<string, int> arr{
      {"non", 0},
  };

  for (int i = 0; i < N; i++) {
    if (arr.find(S[i]) != arr.find("non")) {
      cnt += arr[S[i]];
      arr[S[i]]++;
    } else
      arr.emplace(S[i], 1);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MX 1000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<string> vec(N);
  set<string> st;
  for (int i = 0; i < N; ++i) {
    cin >> vec[i];
    sort(vec[i].begin(), vec[i].end());
  }
  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; ++j)
      if (vec[i] == vec[j])
        ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MX 1000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  map<string, int> mp;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (mp[s] == 0)
      mp[s] = 1;
    else
      ans += mp[s]++;
  }
  cout << ans << endl;
}
Problem p02947 (C++)

Buggy submission (status: Time Limit Exceeded):
#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.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  long long cnt = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (s.at(i) == s.at(j))
        cnt++;
  cout << cnt << endl;
}

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.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  long long cnt = 0, x;
  for (long long i = 0; i < n - 1; i++) {
    x = 1;
    while (s.at(i) == s.at(i + 1)) {
      if (i + 1 == n - 1) {
        x++;
        break;
      }
      i++;
      x++;
    }
    cnt += x * (x - 1) / 2;
  }
  cout << cnt << endl;
}
Problem p02947 (C++)

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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
 * stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?), set tle
 */

map<string, ll> f;
ll fat[20];

void init() {
  fat[0] = fat[1] = 1;
  for (int i = 2; i <= 20; i++)
    fat[i] = i * fat[i - 1];
}

ll choose(ll a, ll b) {
  if (a < b)
    return 0;
  if (a == b)
    return 1;
  if (a - b < b)
    b = a - b;
  ll p = fat[a];
  ll q = fat[b] * fat[a - b];
  return p / q;
}

int main() {
  fcin;
  int n;
  cin >> n;

  init();

  while (n--) {
    string a;
    cin >> a;
    sort(a.begin(), a.end());
    f[a]++;
  }

  ll ans = 0;
  for (auto i : f) {
    ans += choose(i.second, 2);
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
 * stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?), set tle
 */

map<string, ll> f;
ll fat[20];

void init() {
  fat[0] = fat[1] = 1;
  for (int i = 2; i <= 20; i++)
    fat[i] = i * fat[i - 1];
}

ll choose(ll a, ll b) {
  if (a < b)
    return 0;
  if (a == b)
    return 1;
  return a * (a - 1) / 2;
}

int main() {
  fcin;
  int n;
  cin >> n;

  init();

  while (n--) {
    string a;
    cin >> a;
    sort(a.begin(), a.end());
    f[a]++;
  }

  ll ans = 0;
  for (auto i : f) {
    ans += choose(i.second, 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02947 (C++)

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

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

// Function to return LCM of two numbers
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int main() {
  ll n;
  cin >> n;
  map<string, ll> hash;
  string s;
  vector<string> vc;
  for (ll i = 1; i <= n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    vc.push_back(s);
    hash[s]++;
  }
  ll count = 0;
  for (ll i = 1; i <= n; i++) {
    if (hash[vc[i]]) {
      count = count + ((hash[vc[i]] * (hash[vc[i]] - 1)) / 2);
      hash[vc[i]] = hash[vc[i]] - hash[vc[i]];
    }
  }
  cout << count << endl;
}

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

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

// Function to return LCM of two numbers
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int main() {
  ll n;
  cin >> n;
  map<string, ll> hash;
  string s;
  vector<string> vc;
  for (ll i = 1; i <= n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    vc.push_back(s);
    hash[s]++;
  }
  ll count = 0;
  for (ll i = 0; i < vc.size(); i++) {
    if (hash[vc[i]]) {
      count = count + ((hash[vc[i]] * (hash[vc[i]] - 1)) / 2);
      hash[vc[i]] = hash[vc[i]] - hash[vc[i]];
    }
  }
  cout << count << endl;
}
Problem p02947 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, j, count = 0;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s + n);
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (s[i] == s[j])
        count++;
      else
        break;
    }
  }
  cout << count;

  return 0;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, j, count = 0;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s + n);
  vector<ll> v;
  ll temp = 0;
  for (i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      temp++;
    else {
      v.push_back(temp);
      temp = 0;
    }
  }
  v.push_back(temp);
  for (j = 0; j < v.size(); j++) {
    if (v[j] != 0) {
      count += ((v[j] * (v[j] + 1)) / 2);
    }
  }
  cout << count;

  return 0;
}