Problem p02732 (C++)

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

using namespace std;

#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define bs(a, x) binary_search(a.begin(), a.end(), x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007
#define N 10000000
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>

const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 100005;

inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += mod;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= mod)
    c -= mod;
  return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }

struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

ll dp[100005][2];

ll binomialCoeff(ll n, ll k) {
  ll C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (ll i = 1; i <= n; i++) {
    for (ll j = min(i, k); j > 0; j--)
      C[j] = C[j] + C[j - 1];
    dp[i][k] = C[k];
  }
  return dp[n][k] = C[k];
}

int main() {
  fio;
  ll n;
  cin >> n;
  vl a(n);
  f(n) cin >> a[i];
  umpl mp;
  f(n) mp[a[i]]++;
  ll ans = 0;
  memset(dp, 0, sizeof(dp));
  binomialCoeff(n, 2);
  for (auto i = mp.begin(); i != mp.end(); i++) {
    ans = ans + dp[i->second][2];
  }
  for (ll i = 0; i < n; i++) {
    ll ele = a[i];
    ll temp = ans;
    temp = temp - dp[mp[a[i]]][2];
    temp = temp + dp[mp[a[i]] - 1][2];
    cout << temp << "\n";
  }
}


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

using namespace std;

#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define bs(a, x) binary_search(a.begin(), a.end(), x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007
#define N 10000000
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>

const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 100005;

inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += mod;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= mod)
    c -= mod;
  return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }

struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

ll dp[200005][3];

ll binomialCoeff(ll n, ll k) {
  ll C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (ll i = 1; i <= n; i++) {
    for (ll j = min(i, k); j > 0; j--)
      C[j] = C[j] + C[j - 1];
    dp[i][k] = C[k];
  }
  return dp[n][k] = C[k];
}

int main() {
  fio;
  ll n;
  cin >> n;
  vl a(n);
  f(n) cin >> a[i];
  umpl mp;
  f(n) mp[a[i]]++;
  ll ans = 0;
  memset(dp, 0, sizeof(dp));
  binomialCoeff(n, 2);
  for (auto i = mp.begin(); i != mp.end(); i++) {
    ans = ans + dp[i->second][2];
  }
  for (ll i = 0; i < n; i++) {
    ll ele = a[i];
    ll temp = ans;
    temp = temp - dp[mp[a[i]]][2];
    temp = temp + dp[mp[a[i]] - 1][2];
    cout << temp << "\n";
  }
}