Problem p02732 (C++)

Buggy submission (status: Runtime Error):
/*<---------------------------CONCEPTS LEARNT------------------------------>

<-------------------------------------------------------------------------->
            _           __                _      _____ _____ _____
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / /
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n) cout << n << "\n"
#define pff(n) cout << n << " ";
long const M = 1e9 + 7;
const long mxN = 1e5 + 2;
const long mxNN = 1e6 + 2;
ll a[mxN];

void solve() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  For(i, n) {
    cin >> a[i];
    m[a[i]]++;
  }
  ll ans = 0;
  for (auto x : m) {
    ans += x.S * (x.S - 1) / 2;
  }
  // cout << ans << endl ;
  For(i, n) {
    ll c = m[a[i]];
    ll temp;
    temp = ans - c * (c - 1) / 2;
    c--;
    temp += c * (c - 1) / 2;
    cout << temp << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  // ll t ; cin >> t ; while(t--)solve();
  return 0;
}


Fixed submission:
/*<---------------------------CONCEPTS LEARNT------------------------------>

<-------------------------------------------------------------------------->
            _           __                _      _____ _____ _____
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / /
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n) cout << n << "\n"
#define pff(n) cout << n << " ";
long const M = 1e9 + 7;
const long mxN = 2e5 + 2;
const long mxNN = 1e6 + 2;
ll a[mxN];

void solve() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  For(i, n) {
    cin >> a[i];
    m[a[i]]++;
  }
  ll ans = 0;
  for (auto x : m) {
    ans += x.S * (x.S - 1) / 2;
  }
  // cout << ans << endl ;
  For(i, n) {
    ll c = m[a[i]];
    ll temp;
    temp = ans - c * (c - 1) / 2;
    c--;
    temp += c * (c - 1) / 2;
    cout << temp << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  // ll t ; cin >> t ; while(t--)solve();
  return 0;
}