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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    super_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll << x)
const ll DIM = 1e5 + 7;
const ll INF = 1e9;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll A[DIM], cnt[DIM];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  forn(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  ll sum = 0;
  forn(i, n) { sum += cnt[i] * (cnt[i] - 1) / 2; }
  forn(i, n) {
    ll r = sum - cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    r += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
    cout << r << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    super_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll << x)
const ll DIM = 2e5 + 7;
const ll INF = 1e9;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll A[DIM], cnt[DIM];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  forn(i, n) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  ll sum = 0;
  forn(i, n) { sum += cnt[i] * (cnt[i] - 1) / 2; }
  forn(i, n) {
    ll r = sum - cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    r += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
    cout << r << endl;
  }

  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;

#define int long long
#define INF 1001001001

int arr[200001];

int nChoosek(int n, int k) {
  if (k > n)
    return 0;
  if (k * 2 > n)
    k = n - k;
  if (k == 0)
    return 1;

  int result = n;
  for (int i = 2; i <= k; ++i) {
    result *= (n - i + 1);
    result /= i;
  }
  return result;
}

int32_t main() {

  int N;

  cin >> N;
  vector<int> v(N);
  for (int i = 1; i <= N; i++) {
    int tmp;
    cin >> tmp;
    arr[tmp]++;
    v[i] = tmp;
  }

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += nChoosek(arr[i], 2);
  }
  int ans = sum;
  for (int i = 1; i <= N; i++) {
    ans = sum;
    ans -= nChoosek(arr[v[i]], 2);

    ans += nChoosek(arr[v[i]] - 1, 2);

    cout << ans << endl;
  }
}

Fixed submission:
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;

#define int long long
#define INF 1001001001

int arr[200001];

int nChoosek(int n, int k) {
  if (k > n)
    return 0;
  if (k * 2 > n)
    k = n - k;
  if (k == 0)
    return 1;

  int result = n;
  for (int i = 2; i <= k; ++i) {
    result *= (n - i + 1);
    result /= i;
  }
  return result;
}

int32_t main() {

  int N;

  cin >> N;
  vector<int> v(N + 1);
  for (int i = 1; i <= N; i++) {
    int tmp;
    cin >> tmp;
    arr[tmp]++;
    v[i] = tmp;
  }

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += nChoosek(arr[i], 2);
  }
  int ans = sum;
  for (int i = 1; i <= N; i++) {
    ans = sum;
    ans -= nChoosek(arr[v[i]], 2);

    ans += nChoosek(arr[v[i]] - 1, 2);

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

const int N = 100001;
int freq[N];

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &i : v) {
    cin >> i;
    freq[i]++;
  }

  int an = 0;
  for (int i = 0; i <= n; i++) {
    an += freq[i] * (freq[i] - 1) / 2;
  }

  int cur = 0;
  for (int i = 0; i < n; i++) {
    cur = an;
    int nm = v[i];

    cur -= freq[nm] * (freq[nm] - 1) / 2;
    cur += (freq[nm] - 1) * (freq[nm] - 2) / 2;
    cout << cur << "\n";
  }
}

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

const int N = 200001;
int freq[N];

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &i : v) {
    cin >> i;
    freq[i]++;
  }

  int an = 0;
  for (int i = 0; i <= n; i++) {
    an += freq[i] * (freq[i] - 1) / 2;
  }

  int cur = 0;
  for (int i = 0; i < n; i++) {
    cur = an;
    int nm = v[i];

    cur -= freq[nm] * (freq[nm] - 1) / 2;
    cur += (freq[nm] - 1) * (freq[nm] - 2) / 2;
    cout << cur << "\n";
  }
}

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

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 1e5 + 10;
int n, a[maxn], cnt[maxn];

int main() {
  cin >> n;
  rep(i, 1, n) a[i] = read(), cnt[a[i]]++;
  ll sum = 0;
  rep(i, 1, n) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
  rep(i, 1, n) { printf("%lld\n", sum - cnt[a[i]] + 1); }
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 3e5 + 10;
int n, a[maxn], cnt[maxn];

int main() {
  cin >> n;
  rep(i, 1, n) a[i] = read(), cnt[a[i]]++;
  ll sum = 0;
  rep(i, 1, n) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
  rep(i, 1, n) { printf("%lld\n", sum - cnt[a[i]] + 1); }
  return 0;
}
Problem p02732 (C++)

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

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5 + 1;

void solve() {
  ll n;
  cin >> n;
  vll a(n);
  map<ll, ll> m;
  for (int i = 0; i < n; i++) {
    // ll a;
    cin >> a[i];
    m[a[i]]++;
  }

  vll v(N, 0), z(N, 0);
  ll sum = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ll k = (*itr).ff;
    ll p = m[k];
    if (p >= 2) {
      v[k] = (p * (p - 1)) / 2;
      sum += v[k];
    }
    p--;
    if (p >= 2) {
      z[k] = (p * (p - 1)) / 2;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << (sum - v[a[i]] + z[a[i]]) << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

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

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 2e5 + 5;

void solve() {
  ll n;
  cin >> n;
  vll a(n);
  map<ll, ll> m;
  for (int i = 0; i < n; i++) {
    // ll a;
    cin >> a[i];
    m[a[i]]++;
  }

  vll v(N, 0), z(N, 0);
  ll sum = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ll k = (*itr).ff;
    ll p = m[k];
    if (p >= 2) {
      v[k] = (p * (p - 1)) / 2;
      sum += v[k];
    }
    p--;
    if (p >= 2) {
      z[k] = (p * (p - 1)) / 2;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << (sum - v[a[i]] + z[a[i]]) << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02732 (C++)

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

using namespace std;

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

  vector<int> a(n);
  vector<vector<long long>> ball_type_num(pow(10, 5), vector<long long>(2, 0));

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ball_type_num[a[i]][0]++;
  }

  long long total = 0;

  for (int i = 0; i < ball_type_num.size(); i++) {
    if (ball_type_num[i][0] == 0) {
      ball_type_num[i][1] = 0;
    } else {
      ball_type_num[i][1] = ball_type_num[i][0] - 1;
    }
    total += ball_type_num[i][0] * (ball_type_num[i][0] - 1) / 2;
    // cout << ball_type_num[i][0] << " " << ball_type_num[i][1] << endl;
  }
  // cout << "total " << total << endl;

  for (int i = 0; i < n; i++) {
    cout << total - ball_type_num[a[i]][1] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

  vector<int> a(n);
  vector<vector<long long>> ball_type_num(2 * pow(10, 5),
                                          vector<long long>(2, 0));

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ball_type_num[a[i]][0]++;
  }

  long long total = 0;

  for (int i = 0; i < ball_type_num.size(); i++) {
    if (ball_type_num[i][0] == 0) {
      ball_type_num[i][1] = 0;
    } else {
      ball_type_num[i][1] = ball_type_num[i][0] - 1;
    }
    total += ball_type_num[i][0] * (ball_type_num[i][0] - 1) / 2;
    // cout << ball_type_num[i][0] << " " << ball_type_num[i][1] << endl;
  }
  // cout << "total " << total << endl;

  for (int i = 0; i < n; i++) {
    cout << total - ball_type_num[a[i]][1] << endl;
  }

  return 0;
}
Problem p02732 (C++)

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

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

#define K 2
#define LIMIT 20010

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return GCD(b, a % b);
  }
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

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

int cnt[LIMIT] = {0};
int main() {
  int N;
  cin >> N;

  vector<int> v(N, 0);
  int maxV = 0;
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
    maxV = max(maxV, v.at(i));
    cnt[v.at(i)]++;
  }

  ll sum = 0;
  for (int i = 0; i <= maxV; ++i) {
    sum += max(cnt[i] * (cnt[i] - 1LL) / K, 0LL);
  }

  for (auto i = v.begin(); i != v.end(); ++i) {
    cout << sum - (max(cnt[*i] * (cnt[*i] - 1LL) / K, 0LL) -
                   max((cnt[*i] - 1LL) * (cnt[*i] - 2LL) / K, 0LL))
         << endl;
  }
}


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

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

#define K 2
#define LIMIT 200010

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return GCD(b, a % b);
  }
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

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

int cnt[LIMIT] = {0};
int main() {
  int N;
  cin >> N;

  vector<int> v(N, 0);
  int maxV = 0;
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
    maxV = max(maxV, v.at(i));
    cnt[v.at(i)]++;
  }

  ll sum = 0;
  for (int i = 0; i <= maxV; ++i) {
    sum += max(cnt[i] * (cnt[i] - 1LL) / K, 0LL);
  }

  for (auto i = v.begin(); i != v.end(); ++i) {
    cout << sum - (max(cnt[*i] * (cnt[*i] - 1LL) / K, 0LL) -
                   max((cnt[*i] - 1LL) * (cnt[*i] - 2LL) / K, 0LL))
         << endl;
  }
}
Problem p02732 (C++)

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

int main() {
  long long n, a[20005];
  map<int, int> mp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += mp[i] * (mp[i] - 1) / 2;
  }
  // cout << "ans:" << ans << endl;

  for (int i = 0; i < n; i++) {
    cout << ans - mp[a[i]] + 1 << endl;
  }
  return 0;
}


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

int main() {
  long long n, a[200005];
  map<long long, long long> mp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += mp[i] * (mp[i] - 1) / 2;
  }
  // cout << "ans:" << ans << endl;

  for (int i = 0; i < n; i++) {
    cout << ans - mp[a[i]] + 1 << endl;
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main(void) {
  ll N, ans;
  scanf("%lld", &N);
  vector<ll> A(N);
  map<ll, ll> mp;
  REP(ll, i, 0, N) {
    scanf("%lld", &A.at(i));
    mp[A.at(i)]++;
  }
  REP(ll, i, 0, N) {
    ll Num = A.at(i);
    ans = 0;
    for (auto &p : mp) {
      if (Num == p.first) {
        ans += (p.second - 1) * (p.second - 2) / 2;
      } else {
        ans += (p.second - 1) * p.second / 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main(void) {
  ll N, ans;
  scanf("%lld", &N);
  vector<ll> A(N);
  map<ll, ll> mp;
  REP(ll, i, 0, N) {
    scanf("%lld", &A.at(i));
    mp[A.at(i)]++;
  }
  for (auto &p : mp)
    ans += (p.second - 1) * p.second / 2;
  REP(ll, i, 0, N) { printf("%lld\n", ans - mp[A.at(i)] + 1); }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100005;
ll A[MAX_N], B[MAX_N];

int main() {
  int N;
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    A[i]--;
    B[A[i]]++;
  }
  ll ans = 0;
  rep(i, N) { ans += B[i] * (B[i] - 1) / 2; }
  rep(i, N) { cout << ans - (B[A[i]] - 1) << endl; }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 200005;
ll A[MAX_N], B[MAX_N];

int main() {
  int N;
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    A[i]--;
    B[A[i]]++;
  }
  ll ans = 0;
  rep(i, N) { ans += B[i] * (B[i] - 1) / 2; }
  rep(i, N) { cout << ans - (B[A[i]] - 1) << endl; }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LOOP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main() {
  ll N, sum;
  scanf("%lld", &N);

  vector<ll> A(N), count(N);
  LOOP(ll, i, 1, N + 1) count[i] = 0;
  LOOP(ll, i, 0, N) {
    scanf("%lld", &A[i]);
    count[A[i]]++;
  }

  sum = 0;
  LOOP(ll, i, 1, N + 1) sum += count[i] * (count[i] - 1) / 2;

  LOOP(ll, i, 0, N) printf("%lld\n", sum - count[A[i]] + 1);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LOOP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main() {
  ll N, sum;
  scanf("%lld", &N);

  vector<ll> A(N), count(N + 1);
  LOOP(ll, i, 1, N + 1) count[i] = 0;
  LOOP(ll, i, 0, N) {
    scanf("%lld", &A[i]);
    count[A[i]]++;
  }

  sum = 0;
  LOOP(ll, i, 1, N + 1) sum += count[i] * (count[i] - 1) / 2;

  LOOP(ll, i, 0, N) printf("%lld\n", sum - count[A[i]] + 1);

  return 0;
}
Problem p02732 (C++)

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

int main() {
  int n, ary[20000];
  cin >> n;
  vector<ll> cnt(n + 1);
  rep(i, n) {
    cin >> ary[i];
    cnt[ary[i]]++;
  }
  ll tmp = 0;
  rep(i, n + 1) { tmp += cnt[i] * (cnt[i] - 1) / 2; }
  rep(i, n) {
    ll ans = tmp;
    ll x = cnt[ary[i]];
    ans -= x * (x - 1) / 2;
    ans += (x - 1) * (x - 2) / 2;
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int n, ary[(int)2e+5];
  cin >> n;
  vector<ll> cnt(n + 1);
  rep(i, n) {
    cin >> ary[i];
    cnt[ary[i]]++;
  }
  ll tmp = 0;
  rep(i, n + 1) { tmp += cnt[i] * (cnt[i] - 1) / 2; }
  rep(i, n) {
    ll ans = tmp;
    ll x = cnt[ary[i]];
    ans -= x * (x - 1) / 2;
    ans += (x - 1) * (x - 2) / 2;
    cout << ans << endl;
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX 100001
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long
using namespace std;

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

  map<ll, ll> m;
  map<ll, pair<ll, ll>> mpp;
  ll arr[MAX];
  ll n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
  }

  for (int i = 0; i < n; i++) {
    ll temp = m[arr[i]];
    ll co1 = temp * (temp - 1) * 0.5;
    ll co2 = (temp - 1) * (temp - 2) * 0.5;
    mpp[arr[i]] = make_pair(co1, co2);
  }

  // for(auto a: mpp){
  //     cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<endl;
  // }
  ll sum1;
  sum1 = 0;

  for (auto a : mpp) {
    sum1 += a.second.first;
  }

  for (int i = 0; i < n; i++) {
    ll e = sum1 - mpp[arr[i]].first + mpp[arr[i]].second;
    cout << e << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAX 1000000
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long
using namespace std;

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

  map<ll, ll> m;
  map<ll, pair<ll, ll>> mpp;
  ll arr[MAX];
  ll n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
  }

  for (int i = 0; i < n; i++) {
    ll temp = m[arr[i]];
    ll co1 = temp * (temp - 1) * 0.5;
    ll co2 = (temp - 1) * (temp - 2) * 0.5;
    mpp[arr[i]] = make_pair(co1, co2);
  }

  // for(auto a: mpp){
  //     cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<endl;
  // }
  ll sum1;
  sum1 = 0;

  for (auto a : mpp) {
    sum1 += a.second.first;
  }

  for (int i = 0; i < n; i++) {
    ll e = sum1 - mpp[arr[i]].first + mpp[arr[i]].second;
    cout << e << endl;
  }

  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define fori(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += (int)(c))
#define ford(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define MOD 998244353

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lol;
typedef vector<lol> vlol;

ifstream in("input");

const int NR = 3e3 + 5;

lol a[NR], ap[NR], n, sol;
bool used[NR];

int main() {
  ios::sync_with_stdio(false);
  int i;
  cin >> n;
  fori(i, 1, n, 1) {
    cin >> a[i];
    ap[a[i]]++;
  }
  fori(i, 1, n, 1) if (!used[a[i]]) sol += ap[a[i]] * (ap[a[i]] - 1) / 2,
      used[a[i]] = 1;
  fori(i, 1, n, 1) cout << sol - ap[a[i]] * (ap[a[i]] - 1) / 2 +
                               (ap[a[i]] - 2) * (ap[a[i]] - 1) / 2
                        << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define fori(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += (int)(c))
#define ford(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define MOD 998244353

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lol;
typedef vector<lol> vlol;

ifstream in("input");

const int NR = 2e5 + 5;

lol a[NR], ap[NR], n, sol;
bool used[NR];

int main() {
  ios::sync_with_stdio(false);
  int i;
  cin >> n;
  fori(i, 1, n, 1) {
    cin >> a[i];
    ap[a[i]]++;
  }
  fori(i, 1, n, 1) if (!used[a[i]]) sol += ap[a[i]] * (ap[a[i]] - 1) / 2,
      used[a[i]] = 1;
  fori(i, 1, n, 1) cout << sol - ap[a[i]] * (ap[a[i]] - 1) / 2 +
                               (ap[a[i]] - 2) * (ap[a[i]] - 1) / 2
                        << '\n';
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%lld", &x)
#define scaa(x, y) scanf("%lld%lld", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
const ll mod = 998244353;
int main() {
  ll n;
  ll a[100005];
  ll v[100005];
  mem(v);
  sca(n);
  for (int i = 0; i < n; i++) {
    sca(a[i]);
    v[a[i]]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i])
      ans += (v[i] * (v[i] - 1)) / 2ll;
  }
  for (int i = 0; i < n; i++) {
    ll tt = ans - v[a[i]] + 1;
    printf("%lld\n", tt);
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%lld", &x)
#define scaa(x, y) scanf("%lld%lld", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
const ll mod = 998244353;
int main() {
  ll n;
  ll a[200005];
  ll v[200005];
  mem(v);
  sca(n);
  for (int i = 0; i < n; i++) {
    sca(a[i]);
    v[a[i]]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i])
      ans += (v[i] * (v[i] - 1)) / 2ll;
  }
  for (int i = 0; i < n; i++) {
    ll tt = ans - v[a[i]] + 1;
    printf("%lld\n", tt);
  }
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                                                              \
  {                                                                            \
    cerr << "\033[32;1m" << #x << " -> ";                                      \
    err(x);                                                                    \
  }
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
  cerr << a << ' ';
  err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1e5 + 50;
int cnt[N];
int n;
int a[N];

int main(int argc, char const *argv[]) {
  // code
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
  }

  LL ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
  }

  for (int i = 0; i < n; ++i) {
    printf("%lld\n", ans - cnt[a[i]] + 1);
  }
  return 0;
}


Fixed submission:
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                                                              \
  {                                                                            \
    cerr << "\033[32;1m" << #x << " -> ";                                      \
    err(x);                                                                    \
  }
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
  cerr << a << ' ';
  err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 2e5 + 50;
int cnt[N];
int n;
int a[N];

int main(int argc, char const *argv[]) {
  // code
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
  }

  LL ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
  }

  for (int i = 0; i < n; ++i) {
    printf("%lld\n", ans - cnt[a[i]] + 1);
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100001
int main() {
  ll n;
  cin >> n;
  ll c[MAX] = {0};
  ll a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    c[a[i]]++;
  }
  ll s = 0;
  for (int i = 1; i <= n; ++i) {
    s = s + (c[i] * (c[i] - 1)) / 2;
  }
  for (int i = 0; i < n; ++i) {
    cout << (s - c[a[i]] + 1) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 200001
int main() {
  ll n;
  cin >> n;
  ll c[MAX] = {0};
  ll a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    c[a[i]]++;
  }
  ll s = 0;
  for (int i = 1; i <= n; ++i) {
    s = s + (c[i] * (c[i] - 1)) / 2;
  }
  for (int i = 0; i < n; ++i) {
    cout << (s - c[a[i]] + 1) << endl;
  }
  return 0;
}
Problem p02732 (C++)

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

#define MAX_N 100000

using namespace std;

string s;

int n;

bool pal(int st, int dr) {
  for (int i = st, j = dr; i < j; i++, j--) {
    if (s[i] != s[j])
      return 0;
  }

  return 1;
}

int a[MAX_N + 1];
int ap[MAX_N + 1];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ap[a[i]]++;
  }

  long long rez = 0;
  for (int i = 1; i <= n; i++)
    rez = rez + 1LL * ap[i] * (ap[i] - 1) / 2;

  for (int i = 1; i <= n; i++) {
    long long ant = rez;
    int x = a[i];
    rez = rez - 1LL * ap[x] * (ap[x] - 1) / 2;
    rez = rez + 1LL * (ap[x] - 1) * (ap[x] - 2) / 2;

    cout << rez << "\n";
    rez = ant;
  }

  return 0;
}


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

#define MAX_N 200000

using namespace std;

string s;

int n;

bool pal(int st, int dr) {
  for (int i = st, j = dr; i < j; i++, j--) {
    if (s[i] != s[j])
      return 0;
  }

  return 1;
}

int a[MAX_N + 1];
int ap[MAX_N + 1];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ap[a[i]]++;
  }

  long long rez = 0;
  for (int i = 1; i <= n; i++)
    rez = rez + 1LL * ap[i] * (ap[i] - 1) / 2;

  for (int i = 1; i <= n; i++) {
    long long ant = rez;
    int x = a[i];
    rez = rez - 1LL * ap[x] * (ap[x] - 1) / 2;
    rez = rez + 1LL * (ap[x] - 1) * (ap[x] - 2) / 2;

    cout << rez << "\n";
    rez = ant;
  }

  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
ll a[100005], b[100005];
int main() {
  ll n, cou = 0;
  scl(n);
  rep(i, 1, n) {
    scl(a[i]);
    b[a[i]]++;
  }
  rep(i, 1, n) if (b[i] >= 2) cou += b[i] * (b[i] - 1) / 2;
  rep(i, 1, n) {
    ll v = cou;
    cou -= b[a[i]] * (b[a[i]] - 1) / 2;
    b[a[i]]--;
    if (b[a[i]] > 0)
      cou += b[a[i]] * (b[a[i]] - 1) / 2;
    pf("%lld\n", cou);
    cou = v;
    b[a[i]]++;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
ll a[200005], b[200005];
int main() {
  ll n, cou = 0;
  scl(n);
  rep(i, 1, n) {
    scl(a[i]);
    b[a[i]]++;
  }
  rep(i, 1, n) if (b[i] >= 2) cou += b[i] * (b[i] - 1) / 2;
  rep(i, 1, n) {
    ll v = cou;
    cou -= b[a[i]] * (b[a[i]] - 1) / 2;
    b[a[i]]--;
    if (b[a[i]] > 0)
      cou += b[a[i]] * (b[a[i]] - 1) / 2;
    pf("%lld\n", cou);
    cou = v;
    b[a[i]]++;
  }
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) a / gcd(a, b) * b
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORr(i, a, b) for (int i = a; i >= b; i--)
#define MAX3(a, b, c) max(a, max(b, c))
#define MIN3(a, b, c) min(a, min(b, c))
#define eachTest                                                               \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)                                                                  \
    solve();

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;

const int MOD = 1000000007;

void solve() { ; }

int main() {

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

  // eachTest

  ll n;
  cin >> n;
  vector<ll> arr(n);
  map<ll, ll> same;
  FOR(i, 0, n) {
    cin >> arr[i];
    same[arr[i]]++;
  }
  ll temp;
  ll total = 0;
  for (auto v : same) {
    temp = v.second;
    total += temp * (temp - 1) / 2;
  }
  FOR(i, 0, n) { cout << total - same[arr[i]] + 1 << "\n"; }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) a / gcd(a, b) * b
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORr(i, a, b) for (int i = a; i >= b; i--)
#define MAX3(a, b, c) max(a, max(b, c))
#define MIN3(a, b, c) min(a, min(b, c))
#define eachTest                                                               \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)                                                                  \
    solve();

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;

const int MOD = 1000000007;

void solve() { ; }

int main() {

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

  // eachTest

  ll n;
  cin >> n;
  vector<ll> arr(n);
  map<ll, ll> same;
  FOR(i, 0, n) {
    cin >> arr[i];
    same[arr[i]]++;
  }
  ll temp;
  ll total = 0;
  for (auto v : same) {
    temp = v.second;
    total += temp * (temp - 1) / 2;
  }
  FOR(i, 0, n) { cout << total - same[arr[i]] + 1 << "\n"; }

  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int n, a[100100], cnt[100100];
inline long long cal(int x) { return 1ll * x * (x - 1) / 2; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), cnt[a[i]]++;
  for (int i = 1; i <= n; i++)
    ans += cal(cnt[i]);
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans - cal(cnt[a[i]]) + cal(cnt[a[i]] - 1));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int n, a[200100], cnt[200100];
inline long long cal(int x) { return 1ll * x * (x - 1) / 2; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), cnt[a[i]]++;
  for (int i = 1; i <= n; i++)
    ans += cal(cnt[i]);
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans - cal(cnt[a[i]]) + cal(cnt[a[i]] - 1));
  return 0;
}
Problem p02732 (C++)

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

#define ll long long
#define int ll

int fact(int n);

int nCr(int n, int r) {
  if (n < r) {
    return 0;
  }
  return fact(n) / (fact(r) * fact(n - r));
}

// Returns factorial of n
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int32_t main() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]] += 1;
  }
  int sum = 0;

  map<int, int>::iterator itr;

  map<int, int> self;

  for (itr = m.begin(); itr != m.end(); ++itr) {
    int key = itr->first;
    int val = itr->second;

    int x = (val * (val - 1)) / 2;

    sum += x;

    self.insert(pair<int, int>(key, x));
  }

  map<int, int> ans;

  for (int i = 0; i < n; i++) {
    int selph = self[a[i]];
    int ekum = m[a[i]] - 1;
    int nc = nCr(ekum, 2);

    int result = sum - selph + nc;

    ans[a[i]] = result;
  }

  // for (itr = ans.begin(); itr != ans.end(); ++itr) {
  //     cout << itr -> first << " " << itr -> second << endl;
  // }

  for (int i = 0; i < n; i++) {
    cout << ans[a[i]] << endl;
  }
}

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

#define ll long long
#define int ll

int fact(int n);

int nCr(int n, int r) {
  if (n < r) {
    return 0;
  }
  return fact(n) / (fact(r) * fact(n - r));
}

// Returns factorial of n
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int32_t main() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]] += 1;
  }
  int sum = 0;

  map<int, int>::iterator itr;

  map<int, int> self;

  for (itr = m.begin(); itr != m.end(); ++itr) {
    int key = itr->first;
    int val = itr->second;

    int x = (val * (val - 1)) / 2;

    sum += x;

    self.insert(pair<int, int>(key, x));
  }

  map<int, int> ans;

  for (int i = 0; i < n; i++) {
    int selph = self[a[i]];
    int ekum = m[a[i]] - 1;
    // int nc = nCr(ekum, 2);

    int nc = (ekum * (ekum - 1)) / 2;

    int result = sum - selph + nc;

    ans[a[i]] = result;
  }

  // for (itr = ans.begin(); itr != ans.end(); ++itr) {
  //     cout << itr -> first << " " << itr -> second << endl;
  // }

  for (int i = 0; i < n; i++) {
    cout << ans[a[i]] << endl;
  }
}
Problem p02732 (C++)

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

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

int main() {
  // your code goes here
  int n;
  cin >> n;
  int a[n];
  vector<ll> cnt(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int k = 1; k <= n; k++) {
    cnt[a[k - 1]]--;
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
      if (cnt[i] > 0)
        sum += (cnt[i] * (cnt[i] - 1)) / 2;
    }
    cout << sum << "\n";
    cnt[a[k - 1]]++;
  }

  return 0;
}


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

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

int main() {
  // your code goes here
  int n;
  cin >> n;
  int a[n];
  vector<ll> cnt(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  // vector<ll>res(n+1,0);
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] > 0)
      sum += (cnt[i] * (cnt[i] - 1)) / 2;
  }

  for (int k = 0; k < n; k++) {
    ll ans = 0;
    ans = sum - (cnt[a[k]] * (cnt[a[k]] - 1)) / 2;
    if (cnt[a[k]] > 2)
      ans += ((cnt[a[k]] - 1) * (cnt[a[k]] - 2)) / 2;
    cout << ans << "\n";
  }

  return 0;
}
Problem p02732 (C++)

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

int N;
vector<long long> A(100010, 0);
vector<long long> NA(100010, 0);
long long SA = 0;

int main() {
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ++NA[A[i]];
  }
  for (int i = 1; i <= N; i++)
    SA += NA[i] * (NA[i] - 1) / 2;

  /*x番目のボールの番号はA[i]、個数はNA[A[i]]*/
  for (int i = 0; i < N; i++)
    cout << SA - NA[A[i]] + 1 << endl;

  return 0;
}


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

int N;
vector<long long> A(200010, 0);
vector<long long> NA(200010, 0);
long long SA = 0;

int main() {
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ++NA[A[i]];
  }
  for (int i = 1; i <= N; i++)
    SA += NA[i] * (NA[i] - 1) / 2;

  /*x番目のボールの番号はA[i]、個数はNA[A[i]]*/
  for (int i = 0; i < N; i++)
    cout << SA - NA[A[i]] + 1 << endl;

  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
map<int, ll> mp;
set<int> s;
int a[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
    mp[a[i]]++;
  }
  ll cnt = 0;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    ll k = mp[*it];
    cnt += k * (k - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << cnt - mp[a[i]] + 1 << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
map<int, ll> mp;
set<int> s;
int a[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
    mp[a[i]]++;
  }
  ll cnt = 0;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    ll k = mp[*it];
    cnt += k * (k - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << cnt - mp[a[i]] + 1 << endl;
  }
  return 0;
}
Problem p02732 (C++)

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

#define pb push_back
#define ll long long

using namespace std;

int A[100001], nums[100000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    A[x]++;
    nums[i] = x;
  }
  ll total = 0;
  for (int i = 1; i <= n; i++) {
    ll val = A[i];
    total += val * (val - 1);
  }
  total /= 2;
  for (int i = 0; i < n; i++) {
    int rem = A[nums[i]];
    if (rem == 0)
      rem = 0;
    else
      rem--;
    cout << (total - rem) << "\n";
  }
  return 0;
}


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

#define pb push_back
#define ll long long

using namespace std;

int A[200001], nums[200000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    A[x]++;
    nums[i] = x;
  }
  ll total = 0;
  for (int i = 1; i <= n; i++) {
    ll val = A[i];
    total += val * (val - 1);
  }
  total /= 2;
  for (int i = 0; i < n; i++) {
    int rem = A[nums[i]];
    if (rem == 0)
      rem = 0;
    else
      rem--;
    cout << (total - rem) << "\n";
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  Long n;
  cin >> n;
  map<Long, Long> m;
  vector<Long> v;
  Rep(i, 0, n) {
    Long a;
    cin >> a;
    m[a]++;
    v.pb(a);
  }
  Long resp = 0;
  for (auto x : m) {
    resp += x.second * (x.second - 1) / 2;
  }
  Rep(i, 0, n) {
    for (auto x : m) {
      if (v[i] == x.first) {
        cout << resp - (x.second - 1) << '\n';
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  Long n;
  cin >> n;
  map<Long, Long> m;
  vector<Long> v;
  Rep(i, 0, n) {
    Long a;
    cin >> a;
    m[a]++;
    v.pb(a);
  }
  Long resp = 0;
  for (auto x : m) {
    resp += x.second * (x.second - 1) / 2;
  }
  Rep(i, 0, n) { cout << resp - (m[v[i]] - 1) << '\n'; }
  return 0;
}
Problem p02732 (C++)

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

int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i) {
    mp[a[i]]++;
  }
  for (int k = 0; k < n; ++k) {
    mp[a[k]]--;
    long long sum = 0;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      sum += ((itr->second) * (itr->second - 1) / 2);
    }
    cout << sum << endl;
    mp[a[k]]++;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i) {
    mp[a[i]]++;
  }
  long long sum = 0;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    sum += ((itr->second) * (itr->second - 1) / 2);
  }
  for (int i = 0; i < n; ++i) {
    cout << sum - (mp[a[i]] - 1) << endl;
  }
  return 0;
}
Problem p02732 (C++)

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

ll cnt[114514], a[114514];

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

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << ans - cnt[a[i]] * (cnt[a[i]] - 1) / 2 +
                (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2
         << endl;
  }
  return 0;
}


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

ll cnt[214514], a[214514];

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

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << ans - cnt[a[i]] * (cnt[a[i]] - 1) / 2 +
                (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2
         << endl;
  }
  return 0;
}
Problem p02732 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>
using ll = long long;
using namespace std;

int main(void) {
  ll n, a, sum = 0, one = 0;
  map<ll, ll> m, m2;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    m[a]++;
  }

  for (auto j = m.begin(); j != m.end(); j++) {
    one += (m[j->first] * ((m[j->first]) - 1)) / 2;
  }

  for (int i = 0; i < n; i++) {
    sum = 0;
    m2 = m;
    m2[v[i]]--;
    cout << one - m2[v[i]] << endl;
  }
}


Fixed submission:
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>
using ll = long long;
using namespace std;

int main(void) {
  ll n, a, sum = 0, one = 0;
  map<ll, ll> m, m2;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    m[a]++;
  }

  for (auto j = m.begin(); j != m.end(); j++) {
    one += (m[j->first] * ((m[j->first]) - 1)) / 2;
  }

  for (int i = 0; i < n; i++) {
    sum = 0;
    // m2=m;
    m[v[i]]--;
    cout << one - m[v[i]] << endl;
    m[v[i]]++;
  }
}
Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mx 200005
#define ll long long
ll arr[mx] = {0};
ll contribute[mx] = {0};
int in[mx];
int main() {
  ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, a;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    arr[a]++;
    in[i] = a;
  }
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i]) {
      ll add = arr[i];
      add *= (add - 1);
      add /= 2;
      sum += add;
      contribute[i] += add;
    }
  }
  for (int i = 1; i <= n; i++) {
    ll cont = contribute[in[i]];
    ll ans = sum - cont;
    ll add = arr[in[i]] - 1;
    add *= (add - 1);
    add /= 2;
    ans += add;
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mx 200005
#define ll long long
ll arr[mx] = {0};
ll contribute[mx] = {0};
int in[mx];
int main() {
  ios_base::sync_with_stdio(0);

  int n, a;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    arr[a]++;
    in[i] = a;
  }
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i]) {
      ll add = arr[i];
      add *= (add - 1);
      add /= 2;
      sum += add;
      contribute[i] += add;
    }
  }
  for (int i = 1; i <= n; i++) {
    ll cont = contribute[in[i]];
    ll ans = sum - cont;
    ll add = arr[in[i]] - 1;
    add *= (add - 1);
    add /= 2;
    ans += add;
    cout << ans << endl;
  }
}