Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef long long ll; // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI; // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII; // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll z = 0, k, n, m, h, w, ans = 0, sum = 0, Max = 1, Min = 1e9 + 1;
  bool ok = false;
  string s, t, r;
  cin >> n;
  VL a(n), b(n), c(n);
  rep(i, n) {
    cin >> a[i];
    b[a[i]]++;
  }

  rep(i, 2 * 1e5) { sum = sum + (b[i] * (b[i] - 1) / 2); }

  rep(i, n) {
    ans = sum;
    ans -= b[a[i]] * (b[a[i]] - 1) / 2;
    ans += (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef long long ll; // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI; // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII; // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll z = 0, k, n, m, h, w, ans = 0, sum = 0, Max = 1, Min = 1e9 + 1;
  bool ok = false;
  string s, t, r;
  cin >> n;
  VL a(n), b(2 * 1e5 - 1), c(n);
  rep(i, n) {
    cin >> a[i];
    b[a[i]]++;
  }

  rep(i, 2 * 1e5) { sum = sum + (b[i] * (b[i] - 1) / 2); }

  rep(i, n) {
    ans = sum;
    ans -= b[a[i]] * (b[a[i]] - 1) / 2;
    ans += (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
    cout << ans << endl;
  }

  return 0;
}