Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;

ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
ll power_mod(ll a, ll n, ll mod_) {
  ll p = 1;
  while (n) {
    if (n % 2) {
      p = (p * a) % mod_;
    }
    n /= 2;
    a = (a * a) % mod_;
  }
  return p % mod_;
}
/*Code Begins*/

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  _cin;
  cout << setprecision(15);
  ll mn = MAX, mx = MIN;
  ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
  ll x = 0, y = 0, fx, diff, tot = 0, l, r;
  int TC = 1;
  // cin >> TC;
  while (TC--) {
    cin >> n;
    vll a(n);
    mapll f;
    tot = 0;
    fo(i, n) {
      cin >> a[i];
      f[a[i]]++;
    }
    for (auto p : f) {
      tie(x, y) = p;
      tot += y * (y - 1) / 2;
    }
    vll dp(n);
    fo(i, n) {
      dp[i] =
          tot - f[a[i]] * (f[a[i]] - 1) / 2 + (f[a[i]] - 1) * (f[a[i]] - 2) / 2;
    }
    fo(i, n) cout << dp[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;

ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
  ll p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
ll power_mod(ll a, ll n, ll mod_) {
  ll p = 1;
  while (n) {
    if (n % 2) {
      p = (p * a) % mod_;
    }
    n /= 2;
    a = (a * a) % mod_;
  }
  return p % mod_;
}
/*Code Begins*/

int main() {

  _cin;
  cout << setprecision(15);
  ll mn = MAX, mx = MIN;
  ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
  ll x = 0, y = 0, fx, diff, tot = 0, l, r;
  int TC = 1;
  // cin >> TC;
  while (TC--) {
    cin >> n;
    vll a(n);
    mapll f;
    tot = 0;
    fo(i, n) {
      cin >> a[i];
      f[a[i]]++;
    }
    for (auto p : f) {
      tie(x, y) = p;
      tot += y * (y - 1) / 2;
    }
    vll dp(n);
    fo(i, n) {
      dp[i] =
          tot - f[a[i]] * (f[a[i]] - 1) / 2 + (f[a[i]] - 1) * (f[a[i]] - 2) / 2;
    }
    fo(i, n) cout << dp[i] << endl;
  }
  return 0;
}