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

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

signed main() {
  string s;
  int s_center = (s.length() + 1) / 2;
  string mae = s.substr(s_center - 1);
  string usiro = s.substr(s_center + 1, (s.length() / 2));
  if (mae == usiro) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

signed main() {
  string s;
  cin >> s;
  int s_center = ((s.length() + 1) / 2) - 1;
  string mae = s.substr(0, s_center);
  string usiro = s.substr(s_center + 1);
  if (mae == usiro) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++)

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

bool judge(string &s) {
  for (int i = 0, j = s.size() - 1; i != j; ++i, --j) {
    if (s.at(i) != s.at(j))
      return true;
  }
  return false;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool yes = true;
  int n = s.size(), n2;
  if (judge(s))
    yes = false;
  string s2 = s.substr(0, (n - 1) / 2);
  n2 = s2.size();
  if (yes == true && judge(s2))
    yes = false;
  s2 = s.substr((n + 3) / 2 - 1, n2);
  if (yes == true && judge(s2))
    yes = false;
  if (yes)
    cout << "Yes\n"s;
  else
    cout << "No\n"s;
}

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

bool judge(string &s) {
  string s2 = s;
  reverse(s2.begin(), s2.end());
  return s != s2;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool yes = true;
  int n = s.size(), n2;
  if (judge(s))
    yes = false;
  string s2 = s.substr(0, (n - 1) / 2);
  n2 = s2.size();
  if (yes == true && judge(s2))
    yes = false;
  s2 = s.substr((n + 3) / 2 - 1, n2);
  if (yes == true && judge(s2))
    yes = false;
  if (yes)
    cout << "Yes\n"s;
  else
    cout << "No\n"s;
}
Problem p02730 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main() {
  string S;
  cin >> S;

  ll N = S.size();
  ll left = 0, right = N - 1;
  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
  }

  left = 0;
  right = (N - 1) / 2 - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = (N + 3) / 2 - 1;
  right = N - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main() {
  string S;
  cin >> S;

  ll N = S.size();
  ll left = 0, right = N - 1;
  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = 0;
  right = (N - 1) / 2 - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = (N + 3) / 2 - 1;
  right = N - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p02730 (C++)

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

using namespace std;
using ll = long long;

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;

const ll MOD = 1000000007;

bool f(string s) {
  string ss = s;
  reverse(ALL(ss));
  if (s == ss) {
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;

  int n = s.size();
  if (f(s) && f(s.substr(0, n / 2)) &&
      f(s.substr((n + 3) / 2 + 1, (n - (n + 3) / 2 + 1)))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;

const ll MOD = 1000000007;

bool f(string s) {
  string ss = s;
  reverse(ALL(ss));
  if (s == ss) {
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;

  int n = s.size();
  if (f(s) && f(s.substr(0, n / 2)) &&
      f(s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = 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) cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9 + 7;
// const ll inf = 1e15;
// const ll mod = 1e9+7;

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

int main() {
  string s;
  cin >> s;
  string rs = s;
  int l = s.size();
  reverse(ALL(rs));

  string kai = s.substr(0, (l - 1) / 2);
  while (kai.size() != 1) {
    if (kai.back() != kai.front()) {
      cout << "No" << endl;
      return 0;
    }
    kai.pop_back();
    kai.erase(0, 1);
  }

  if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = 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) cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9 + 7;
// const ll inf = 1e15;
// const ll mod = 1e9+7;

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

int main() {
  string s;
  cin >> s;
  string rs = s;
  int l = s.size();
  reverse(ALL(rs));

  string kai = s.substr(0, (l - 1) / 2);
  while (kai.size() > 1) {
    if (kai.back() != kai.front()) {
      cout << "No" << endl;
      return 0;
    }
    kai.pop_back();
    kai.erase(0, 1);
  }

  if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++)

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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"

lli n, m;
string a, a2, a3;

int main() {
#ifndef ONLINE_JUDGE
  freopen("zgir.gir", "r", stdin);
  freopen("zcik.cik", "w", stdout);
#endif
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != a[a.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < (a.size() - 1) / 2; i++) {
    a2.pb(a[i]);
  }
  for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) {
    a3.pb(a[i]);
  }
  for (int i = 0; i < a2.size(); i++) {
    if (a2[i] != a2[a2.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < a3.size(); i++) {
    if (a3[i] != a3[a3.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"

lli n, m;
string a, a2, a3;

int main() {
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != a[a.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < (a.size() - 1) / 2; i++) {
    a2.pb(a[i]);
  }
  for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) {
    a3.pb(a[i]);
  }
  for (int i = 0; i < a2.size(); i++) {
    if (a2[i] != a2[a2.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < a3.size(); i++) {
    if (a3[i] != a3[a3.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

bool isKaibun(string s) {
  int n = s.length();
  int l = n / 2;
  for (int i = 0; i < l; i++) {
    if (s[i] != s[n - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) &&
            isKaibun(s.substr((n + 3) / 2 + 1, n));
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

bool isKaibun(string s) {
  int n = s.length();
  int l = n / 2;
  for (int i = 0; i < l; i++) {
    if (s[i] != s[n - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) &&
            isKaibun(s.substr((n + 3) / 2 - 1, n));
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false)
#define rmod(x, y) ((((x) % (y)) + (y)) % (y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template <typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() {
  return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string s1 = s.substr(0, ((n - 1) / 2));
  string s2 = s.substr((n + 3) / 2 + 1);
  string rs1 = s1;
  reverse(rs1.begin(), rs1.end());
  string rs2 = s2;
  reverse(rs2.begin(), rs2.end());
  string rs = s;
  reverse(s.begin(), s.end());
  if (s == rs && s1 == rs1 && s2 == rs2)
    puts("Yes");
  else
    puts("No");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false)
#define rmod(x, y) ((((x) % (y)) + (y)) % (y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template <typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() {
  return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string s1 = s.substr(0, ((n - 1) / 2));
  string s2 = s.substr((n + 3) / 2 - 1);
  string rs1 = s1;
  reverse(rs1.begin(), rs1.end());
  string rs2 = s2;
  reverse(rs2.begin(), rs2.end());
  string rs = s;
  reverse(s.begin(), s.end());
  if (s == rs && s1 == rs1 && s2 == rs2)
    puts("Yes");
  else
    puts("No");

  return 0;
}
Problem p02730 (C++)

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

string s, a, b;
int n, mid;

bool pal(string a) {
  string b = a;
  reverse(b.begin(), b.end());
  if (b == a)
    return true;
  else
    return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  cin >> s;
  n = s.length();
  mid = n / 2;
  a = s.substr(0, mid);
  b = s.substr(mid + 1);

  if (pal(s) and pal(a) and pal(b))
    cout << "Yes";
  else
    cout << "No";
}


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

string s, a, b;
int n, mid;

bool pal(string a) {
  string b = a;
  reverse(b.begin(), b.end());
  if (b == a)
    return true;
  else
    return false;
}

int main() {

  cin >> s;
  n = s.length();
  mid = n / 2;
  a = s.substr(0, mid);
  b = s.substr(mid + 1);

  if (pal(s) and pal(a) and pal(b))
    cout << "Yes";
  else
    cout << "No";
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool ispal(string s) {
  int n = s.length();
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - 1 - i])
      return false;
  }
  return true;
}
int main() {
  string S;
  cin >> S;
  int N = S.length();
  if (ispal(S) && ispal(S.substr(0, (N - 1) / 2)) &&
      ispal(S.substr((N + 3) / 2 + 1, (N - 3) / 2 + 1)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool ispal(string s) {
  int n = s.length();
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - 1 - i])
      return false;
  }
  return true;
}
int main() {
  string S;
  cin >> S;
  int N = S.length();
  if (ispal(S) && ispal(S.substr(0, (N - 1) / 2)) &&
      ispal(S.substr((N + 3) / 2 - 1, (N - 3) / 2 + 1)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02730 (C++)

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

bool isPalin(string S) {
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != S[S.length() - i - 1]) {
      return false;
    }
  }
  return true;
}

int main(void) {
  string S;
  cin >> S;

  int N = S.length();

  bool strongPalindrome = true;

  // 1st condition
  if (!isPalin(S)) {
    cout << "No" << endl;
    return 0;
  }

  // 2nd condition
  if (!isPalin(S.substr(0, (N - 1) / 2))) {
    cout << "No" << endl;
    return 0;
  }

  // 3rd condition
  if (!isPalin(S.substr((N + 3) / 2 + 1))) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
}


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

bool isPalin(string S) {
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != S[S.length() - i - 1]) {
      return false;
    }
  }
  return true;
}

int main(void) {
  string S;
  cin >> S;

  int N = S.length();

  bool strongPalindrome = true;

  // 1st condition
  if (!isPalin(S)) {
    cout << "No" << endl;
    return 0;
  }

  // 2nd condition
  if (!isPalin(S.substr(0, (N - 1) / 2))) {
    cout << "No" << endl;
    return 0;
  }

  // 3rd condition
  if (!isPalin(S.substr((N + 3) / 2 - 1))) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define loop for (int i = 0; i < n; i++)
using namespace std;
string reverese(string n) {
  string st = "";
  for (int i = n.length() - 1; i >= 0; i--)
    st += n[i];
  return st;
}
int main() {
  string k;
  cin >> k;
  int flag = 1;
  int n = k.length();
  if (n % 2 == 0)
    flag = 1;
  else if ((k.substr(0, n / 2) == reverese(k.substr(0, n / 2))) and
           (k.substr(((n + 3) / 2) + 1, n) ==
            reverese(k.substr((((n + 3) / 2) + 1), n))))
    flag = 2;
  if (flag == 2)
    puts("Yes");
  else
    puts("No");
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define loop for (int i = 0; i < n; i++)
using namespace std;
string reverese(string n) {
  string st = "";
  for (int i = n.length() - 1; i >= 0; i--)
    st += n[i];
  return st;
}
int main() {
  string k;
  cin >> k;
  int flag = 1;
  int n = k.length();
  if ((k.substr(0, n / 2) == reverese(k.substr(0, n / 2))) and
      (k.substr(((n + 3) / 2) - 1, n - 1) ==
       reverese(k.substr((((n + 3) / 2) - 1), n - 1))))
    if (k == reverese(k))
      flag = 2;
  if (flag == 2)
    puts("Yes");
  else
    puts("No");
}
Problem p02730 (C++)

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

bool KBjudge(string x) {

  string x_ = x;
  reverse(x.begin(), x.end());
  return (x_ == x);
}

int main() {

  string S;
  cin >> S;
  int N = S.size();

  if (KBjudge(S.substr(0, S.size()))) {
    if (KBjudge(S.substr(0, (N - 1) / 2))) {
      if (KBjudge(S.substr((N + 3) / 2 + 1, N - (N + 3) / 2))) {

        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

bool KBjudge(string x) {

  string x_ = x;
  reverse(x.begin(), x.end());
  return (x_ == x);
}

int main() {

  string S;
  cin >> S;
  int N = S.size();

  if (KBjudge(S.substr(0, S.size()))) {
    if (KBjudge(S.substr(0, (N - 1) / 2))) {
      if (KBjudge(S.substr((N + 3) / 2 - 1, N - (N + 3) / 2 + 2))) {

        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02730 (C++)

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length() / 2; ++i) {
    if (s[i] != s[s.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  int n = s.length();
  string t(s.c_str(), s.c_str() + (n - 1) / 2);
  for (int i = 0; i < t.length() / 2; ++i) {
    if (t[i] != t[t.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  string u(s.c_str() + (n + 3) / 2, s.c_str() - 1 + s.length());
  for (int i = 0; i < u.length() / 2; ++i) {
    if (u[i] != u[u.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length() / 2; ++i) {
    if (s[i] != s[s.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  if (s.length() == 3) {
    cout << "Yes";
    return 0;
  }
  int n = s.length();
  string t(s.c_str(), s.c_str() + (n - 1) / 2);
  for (int i = 0; i < t.length() / 2; ++i) {
    if (t[i] != t[t.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  string u(s.c_str() + (n + 3) / 2, s.c_str() - 1 + s.length());
  for (int i = 0; i < u.length() / 2; ++i) {
    if (u[i] != u[u.length() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02730 (C++)

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

int main() {
  string S;
  cin >> S;
  int N;
  N = S.size();
  int res = 0;
  int check = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at(N - 1 - i)) {
      check = check + 0;
    } else {
      check = check + 1;
    }
  }
  if (check == 0) {
    res = res + 1;
  }
  int M = (N - 1) / 2;
  int chec = 0;
  for (int i = 0; i < M; i++) {
    if (S.at(i) == S.at(M - 1 - i)) {
      chec = chec + 0;
    } else {
      chec = chec + 1;
    }
  }
  if (chec == 0) {
    res = res + 1;
  }
  int L = (N + 3) / 2;
  int che = 0;
  for (int i = 0; i < L; i++) {
    if (S.at(L + i) == S.at(N - 1 - i)) {
      che = che + 0;
    } else {
      che = che + 1;
    }
  }
  if (che == 0) {
    res = res + 1;
  }
  if (res == 3) {
    cout << "Yes";
  }
  if (res < 3) {
    cout << "No";
  }
}


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

int main() {
  string S;
  cin >> S;
  int N;
  N = S.size();
  int res = 0;
  int check = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at(N - 1 - i)) {
      check = check + 0;
    } else {
      check = check + 1;
    }
  }
  if (check == 0) {
    res = res + 1;
  }
  int M = (N - 1) / 2;
  int chec = 0;
  for (int i = 0; i < M; i++) {
    if (S.at(i) == S.at(M - 1 - i)) {
      chec = chec + 0;
    } else {
      chec = chec + 1;
    }
  }
  if (chec == 0) {
    res = res + 1;
  }
  int L = (N + 3) / 2;
  int che = 0;
  for (int i = 0; i < N - L; i++) {
    if (S.at(L + i - 1) == S.at(N - 1 - i)) {
      che = che + 0;
    } else {
      che = che + 1;
    }
  }
  if (che == 0) {
    res = res + 1;
  }
  if (res == 3) {
    cout << "Yes";
  }
  if (res < 3) {
    cout << "No";
  }
}
Problem p02731 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int L;
  cin >> L;
  vector<double> p;
  for (int i = 1; i < L - 1; i++) {
    p.push_back((double)i * (L - i) * (L - i) / 4);
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  cout << p.at(0) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int L;
  cin >> L;
  cout << fixed << setprecision(10) << (double)L * L * L / 27 << endl;
  return 0;
}
Problem p02731 (C++)

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

#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int l;
  cin >> l;
  l = l * l * l;
  double bb = (double)l / 27;
  cout << ps(bb, 12) << endl;
  return 0;
}

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

#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
#endif
  int l;
  cin >> l;
  l = l * l * l;
  double bb = (double)l / 27;
  cout << ps(bb, 12) << endl;
  return 0;
}
Problem p02731 (C++)

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

int main() {
  int l;
  int ans = 0;
  for (int i = 1; i <= l; i++) {
    int a = i;
    for (int j = 1; j <= l; j++) {
      int b = j;
      int c = l - a - b;
      if (c > 0) {
        ans = max(ans, a * b * c);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main() {
  double l;
  cin >> l;
  double m = l / 3;
  double ans = m * m * m;
  printf("%.12f\n", ans);
  return 0;
}
Problem p02731 (C++)

Buggy submission (status: Runtime Error):
// AnkitCode99 here....
// every ups and downs matter!

#include <bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define Ryuga                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)

using namespace std;

const ll sz = 100005;
const ll szz = 1000006;

int main() {
  Ryuga;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("op.txt", "w", stdout);
#endif

  ll L;
  cin >> L;
  cout << fixed << setprecision(12) << (L * L * L) / 27.0;

} // Goodbye...

Fixed submission:
// AnkitCode99 here....
// every ups and downs matter!

#include <bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define Ryuga                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)

using namespace std;

const ll sz = 100005;
const ll szz = 1000006;

int main() {
  Ryuga;

  ll L;
  cin >> L;
  cout << fixed << setprecision(12) << (L * L * L) / 27.0;

} // Goodbye...
Problem p02731 (C++)

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

int main() {
  double l;
  cin >> l;
  double maxi = 0;
  for (double i = 0; i <= l / 3; i += 0.001) {
    for (double j = 0; j <= (l - i) / 2; j += 0.001) {
      maxi = max(maxi, i * j * (l - i - j));
    }
  }
  cout << maxi << endl;
}

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

int main() {
  double l;
  cin >> l;
  printf("%.12f\n", pow(l / 3, 3.0));
}
Problem p02731 (Python)

Buggy submission (status: Runtime Error):
f = int(input()) / 3.0
print("{.9f}".format(f * f * f))


Fixed submission:
f = int(input()) / 3.0
print("{:.9f}".format(f * f * f))
Problem p02731 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
void solve() {
  ld n;
  in(n);
  ld div = n / 3.0;
  ld rem = n - 2 * div;
  cout << fixed << setprecision(10) << rem * div * div << '\n';
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  clock_t t1 = clock();
  gear_change;
  ll test = 1;
  // in(test);
  while (test--) {
    solve();
  }
  clock_t t2 = clock();
  cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
void solve() {
  ld n;
  in(n);
  ld div = n / 3.0;
  ld rem = n - 2 * div;
  cout << fixed << setprecision(10) << rem * div * div << '\n';
}
int main() {
  clock_t t1 = clock();
  gear_change;
  ll test = 1;
  // in(test);
  while (test--) {
    solve();
  }
  clock_t t2 = clock();
  cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\n';
}
Problem p02731 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(), v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 105
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
long double d;
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> d;
  d = (long double)d / 3;
  cout << setprecision(32) << d * d * d;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(), v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 105
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
long double d;
int main() {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> d;
  d = (long double)d / 3;
  cout << setprecision(32) << d * d * d;
}
Problem p02732 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

  int n;
  cin >> n;
  map<int, int> mp;
  vector<int> bn(n);
  int a;
  rep(i, n) {
    cin >> a;
    mp[a]++;
    bn[i] = a;
  }
  for (int i = 0; i < n; i++) { // banするやつきめる
    int cnt = 0;
    for (auto p : mp) {
      if (p.first == bn[i])
        cnt += (p.second - 1) * (p.second - 2) / 2;
      else
        cnt += p.second * (p.second - 1) / 2;
    }
    cout << cnt << "\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

  int n;
  cin >> n;
  map<int, int> mp;
  vector<int> bn(n);
  int a;
  rep(i, n) {
    cin >> a;
    mp[a]++;
    bn[i] = a;
  }
  int sum = 0;
  for (auto p : mp) {
    sum += p.second * (p.second - 1) / 2;
  }
  rep(i, n) {
    int k = mp.at(bn[i]) - 1;
    cout << sum - k << "\n";
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 1e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;
int a[MAXN], cnt[MAXN], sum[MAXN], b[MAXN];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    cnt[a[i]]++;
  }
  sort(b, b + n);
  int tn = unique(b, b + n) - b;
  int ans = 0;
  for (int i = 0; i < tn; i++) {
    sum[b[i]] = cnt[b[i]] * (cnt[b[i]] - 1) / 2;
    ans += sum[b[i]];
  }
  for (int i = 0; i < n; i++) {
    ans -= sum[a[i]];
    cout << ans + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2 << endl;
    ans += sum[a[i]];
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 2e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;
int a[MAXN], cnt[MAXN], sum[MAXN], b[MAXN];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    cnt[a[i]]++;
  }
  sort(b, b + n);
  int tn = unique(b, b + n) - b;
  int ans = 0;
  for (int i = 0; i < tn; i++) {
    sum[b[i]] = cnt[b[i]] * (cnt[b[i]] - 1) / 2;
    ans += sum[b[i]];
  }
  for (int i = 0; i < n; i++) {
    ans -= sum[a[i]];
    cout << ans + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2 << endl;
    ans += sum[a[i]];
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B;
  map<int, int> m, k;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    m[A[i]]++;
  }
  {
    int i = 0;
    for (auto itr = m.begin(); itr != m.end(); itr++) {
      B.push_back((*itr).second);
      k[(*itr).first] = i;
      i++;
    }
  }
  vector<ll> C(B.size()), D(B.size(), 0), E(B.size(), 0);
  for (int i = 0; i < N; i++) {
    if (B[i] < 2)
      C[i] = 0;
    else
      C[i] = B[i] * (B[i] - 1) / 2;
  }
  D[0] = C[0], E.back() = C.back();
  for (int i = 0; i < D.size() - 1; i++) {
    D[i + 1] = D[i] + C[i + 1];
  }
  for (int i = E.size() - 1; i >= 1; i--) {
    E[i - 1] = E[i] + C[i - 1];
  }
  for (int i = 0; i < N; i++) {
    ll ans = 0;
    if (B[k[A[i]]] >= 3)
      ans += (B[k[A[i]]] - 1) * (B[k[A[i]]] - 2) / 2;
    if (k[A[i]] != 0)
      ans += D[k[A[i]] - 1];
    if (k[A[i]] != B.size() - 1)
      ans += E[k[A[i]] + 1];
    cout << ans << endl;
  }
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B;
  map<int, int> m, k;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    m[A[i]]++;
  }
  {
    int i = 0;
    for (auto itr = m.begin(); itr != m.end(); itr++) {
      B.push_back((*itr).second);
      k[(*itr).first] = i;
      i++;
    }
  }
  vector<ll> C(B.size()), D(B.size(), 0), E(B.size(), 0);
  for (int i = 0; i < B.size(); i++) {
    if (B[i] < 2)
      C[i] = 0;
    else
      C[i] = B[i] * (B[i] - 1) / 2;
  }
  D[0] = C[0], E.back() = C.back();
  for (int i = 0; i < D.size() - 1; i++) {
    D[i + 1] = D[i] + C[i + 1];
  }
  for (int i = E.size() - 1; i >= 1; i--) {
    E[i - 1] = E[i] + C[i - 1];
  }
  for (int i = 0; i < N; i++) {
    ll ans = 0;
    if (B[k[A[i]]] >= 3)
      ans += (B[k[A[i]]] - 1) * (B[k[A[i]]] - 2) / 2;
    if (k[A[i]] != 0)
      ans += D[k[A[i]] - 1];
    if (k[A[i]] != B.size() - 1)
      ans += E[k[A[i]] + 1];
    cout << ans << endl;
  }
}
Problem p02732 (C++)

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

int64_t ncr2(int64_t n);
int main(void) {
  int64_t N;
  int64_t total = 0;
  cin >> N;

  vector<int64_t> A(N);
  vector<int64_t> B(100001, 0);

  for (int64_t i = 0; i < N; i++) {
    cin >> A[i];
    B[A[i] - 1]++;
  }

  for (int64_t i = 0; i < B.size(); i++) {
    total += ncr2(B[i]);
  }
  for (int64_t i = 0; i < N; i++) {
    cout << total - ncr2(B[A[i] - 1]) + ncr2(B[A[i] - 1] - 1) << "\n";
  }

  return 0;
}

int64_t ncr2(int64_t n) {
  if (n < 2)
    return 0;
  if (n == 2)
    return 1;
  return (n * (n - 1)) / 2;
}


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

int64_t ncr2(int64_t n);
int main(void) {
  int64_t N;
  int64_t total = 0;
  cin >> N;

  vector<int64_t> A(N);
  vector<int64_t> B(200001, 0);

  for (int64_t i = 0; i < N; i++) {
    cin >> A[i];
    B[A[i] - 1]++;
  }

  for (int64_t i = 0; i < B.size(); i++) {
    total += ncr2(B[i]);
  }
  for (int64_t i = 0; i < N; i++) {
    cout << total - ncr2(B[A[i] - 1]) + ncr2(B[A[i] - 1] - 1) << "\n";
  }

  return 0;
}

int64_t ncr2(int64_t n) {
  if (n < 2)
    return 0;
  if (n == 2)
    return 1;
  return (n * (n - 1)) / 2;
}
Problem p02732 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import defaultdict


def num_combinations(_n):
    return _n * (_n - 1) // 2


if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    freq = defaultdict(int)

    for n in xs:
        freq[n] += 1

    res = 0

    for k in range(len(xs)):
        res = 0
        for num in freq.keys():
            res += num_combinations(freq[num] - (1 if xs[k] == num else 0))
        print(res)


Fixed submission:
from collections import defaultdict


def num_combinations(_n):
    return _n * (_n - 1) // 2


if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    freq = defaultdict(int)

    for n in xs:
        freq[n] += 1

    total = sum([num_combinations(n) for n in freq.values()])
    for x in xs:
        print(total - (freq[x] - 1))
Problem p02732 (Python)

Buggy submission (status: Runtime Error):
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


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


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == "__main__":
    main()


Fixed submission:
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


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


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        if col[key] < 2:
            com[key] = 0
        else:
            com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


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

Buggy submission (status: Time Limit Exceeded):
from collections import Counter


def choose(n: int) -> int:
    if n < 2:
        return 0
    else:
        return (n * (n - 1)) // 2


N = int(input())
A = list(map(int, input().split()))
for k in range(N):
    c = Counter(A[:k] + A[k + 1 :])

    print(sum(map(choose, c.values())))


Fixed submission:
from collections import Counter


def choose(n: int) -> int:
    if n < 2:
        return 0
    else:
        return (n * (n - 1)) // 2


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
d = {key: choose(value) for key, value in c.items()}
if len(d) > 1:
    sum_d = sum(d.values())
    for a in A:
        print(sum_d - d[a] + choose(c[a] - 1))
else:
    ans = choose(N - 1)
    for _ in range(N):
        print(ans)
Problem p02732 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter
from scipy.special import comb
import numpy as np

N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")


Fixed submission:
from collections import Counter
from scipy.misc import comb
import numpy as np

N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")
Problem p02732 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

for i in range(N):
    print(total - (cnt[i] - 1))


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

for a in A:
    print(total - (cnt[a] - 1))
Problem p02732 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
    dictA[x] = 0
for x1 in A:
    dictA[x1] += 1

for x2 in A:
    dictB = dictA.copy()
    combisum = 0
    dictB[x2] -= 1
    for x3 in dictB.values():
        combisum += x3 * (x3 - 1) // 2
    print(combisum)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
    dictA[x] = 0
for x1 in A:
    dictA[x1] += 1

combisum = 0
for y in dictA.values():
    combisum += y * (y - 1) // 2

for z in range(N):
    print(combisum - dictA[A[z]] + 1)
Problem p02732 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

m = [0] * N
for i in range(N):
    m[A[i]] += 1
ans = 0
for i in range(len(m)):
    ans += m[i] * (m[i] - 1) // 2
for i in range(N):
    print(ans - m[A[i]] + 1)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

m = [0] * (N + 1)
for i in range(N):
    m[A[i]] += 1
ans = 0
for i in range(len(m)):
    ans += m[i] * (m[i] - 1) // 2
for i in range(N):
    print(ans - m[A[i]] + 1)
Problem p02732 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int a[300000];
int ans[300000];
int tri(int n) { return n * (n - 1) / 2; }
signed main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (auto &x : mp) {
    x.second--;
    for (auto y : mp) {
      ans[x.first] += tri(y.second);
    }
    x.second++;
  }
  rep(i, n) { cout << ans[a[i]] << endl; }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int a[300000];
int ans[300000];
int tri(int n) { return n * (n - 1) / 2; }
signed main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int cnt = 0;
  for (auto x : mp) {
    cnt += tri(x.second);
  }
  for (auto x : mp) {
    int nor = tri(x.second);
    int sma = tri(x.second - 1);
    ans[x.first] = cnt - (nor - sma);
  }
  rep(i, n) { cout << ans[a[i]] << endl; }
  return 0;
}
Problem p02732 (C++)

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

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

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<long long> Acnt(N + 1, 0);

  for (auto x : A) {
    Acnt.at(x) = count(A.begin(), A.end(), x);
  }

  long long s = 0;
  for (int i = 1; i < N + 1; i++) {
    if (Acnt.at(i) != 0) {
      s = s + Acnt.at(i) * (Acnt.at(i) - 1) / 2;
    }
  }

  for (auto Ak : A) {
    long long ans = s - Acnt.at(Ak) + 1;
    printf("%lld\n", ans);
  }
}

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

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

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<long long> Acnt(N + 1, 0);

  for (auto x : A) {
    Acnt.at(x)++;
  }

  long long s = 0;
  for (int i = 1; i < N + 1; i++) {
    if (Acnt.at(i) != 0) {
      s = s + Acnt.at(i) * (Acnt.at(i) - 1) / 2;
    }
  }

  for (auto Ak : A) {
    long long ans = s - Acnt.at(Ak) + 1;
    printf("%lld\n", ans);
  }
}