Problem p02732 (C++)

Buggy submission (status: Runtime Error):
///*
// 正在播放《フリージア》
// 1:21  ━━━━━━●─────   5:35
//    ?   ?   ??   ?   ?
//```````'`...```````''`````````````'````````````````'`.`''
//```````''..`';;'```''```'''''''''''''`````````````````'':
//.````''''':;;!!:````'````'''''''''''``````````````````'':
//``''''''':;;;;;'```'``````''```````````____________```'':
//`````````:;;!;'```````````'```````'```|   所以说   |'``'':
//```````'|$&$%:````````````'```````````|不要停下来啊|''''':
//````'''!$&&&|'```````````'''::''::''''/ （指AC）  |':'':::
//````'':|&&&$!'`````'''''''::.....`;!;'/_________|''``'::
//   ....'|&&@$!'........```:!;'....`:;:```````````````````'
//..````;$&&&$!:''``````'':|%%!::;|%$$!::::::::''::::::::::
//``````!&&@&&|:'````````':|$$$$$$$$$|:':::::::::::::::::::
//`````:%&@@@@@@@@&&&@@@@&&&&@@@@@@@&&&|::::::::':::::::::;
//`````.```':|$@@@@@@@@@@@@@@@@@@@@@@@@###@@&&$|;:::'::::::
//````````````';|$&@@@@@@@@@###@@@@@@########@@@@$!''''::::
//`````````..````:|%$@@@@@#########@#########@@@@&!''''::::
//`````````````````:|&########################@@@$;::::::::
//``````````````````:!$@########################@%;:::'::::
//``````````..``````':|&#######################@@&!''''''::
//''''::'''`.`''''''':|@#######################@@&|:'`.`';!
//:::::::::``'''''';%@######################@@##@@&!::'';;;
//::;::::::`.''''';%@@@@####################$%@##@@%;:'':;!
//:;;;;::::``':;%@@@#########################&%&##@@|:'';;!
//;;!;;;;;;'`::;%@#############################@@##@$!'';!!
//;;;;;;;;:``':::::;|$@############################@$!'`;!!
//::;;;;;;:'`'::::::;!$@#######################&&@$$$;``:;;
//`````````..````````'|@#####################$;!$$$&@@|''':
//'''''''''''''':'''''|@#########@&@##########@@####@@&%|!!
//''''''''':'''::'':''!&########&!|&@##########&&####&%|!||
//:::::'''::::::::::::!&########|:;|$@#########@&###&%||||!
//:::::::'''''':::::::!&#######@!:;!!$@########@$&##@%||||!
//
//                    だからよ...止まるじゃねえぞ
// */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define  ll long long
const int N = 1e6 + 10;
#define PII pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;

#define __i __int128
// ll mod = 1e9+7;

string manacher(string s) {
  if (s.size() < 2)
    return s;
  string t;
  t += '$';
  for (int i = 0; i < s.size(); i++)
    t += '#' + s[i];
  t += '@';
  int num = t.size();
  int p[num];
  int id = 0, mx = 0;
  int maxl = -1;
  int index = 0;
  for (int j = 1; j < num - 1; j++) {
    p[j] = mx > j ? min(p[2 * id - j], mx - j) : 1;
    while (t[j + p[j]] == t[j - p[j]])
      p[j]++;
    if (mx < p[j] + j) {
      mx = p[j] + j;
      id = j;
    }
    if (maxl < p[j] + 1) {
      maxl = p[j] - 1;
      index = j;
    }
  }
  int start = (index - maxl) / 2;
  // cout <<start<<endl;
  return s.substr(start, start + maxl);
}
int ar[100010];
int br[100010];
vector<int> v[100010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  map<ll, ll> mp;
  for (int i = 1; i <= n; i++)
    cin >> ar[i], mp[ar[i]]++;
  map<ll, ll> mm;
  ll sum = 0;
  for (auto it : mp)
    sum += (it.second) * (it.second - 1) / 2;
  for (int i = 1; i <= n; i++) {

    cout << sum - (mp[ar[i]] - 1) << endl;
  }
  return 0;
}


Fixed submission:
///*
// 正在播放《フリージア》
// 1:21  ━━━━━━●─────   5:35
//    ?   ?   ??   ?   ?
//```````'`...```````''`````````````'````````````````'`.`''
//```````''..`';;'```''```'''''''''''''`````````````````'':
//.````''''':;;!!:````'````'''''''''''``````````````````'':
//``''''''':;;;;;'```'``````''```````````____________```'':
//`````````:;;!;'```````````'```````'```|   所以说   |'``'':
//```````'|$&$%:````````````'```````````|不要停下来啊|''''':
//````'''!$&&&|'```````````'''::''::''''/ （指AC）  |':'':::
//````'':|&&&$!'`````'''''''::.....`;!;'/_________|''``'::
//   ....'|&&@$!'........```:!;'....`:;:```````````````````'
//..````;$&&&$!:''``````'':|%%!::;|%$$!::::::::''::::::::::
//``````!&&@&&|:'````````':|$$$$$$$$$|:':::::::::::::::::::
//`````:%&@@@@@@@@&&&@@@@&&&&@@@@@@@&&&|::::::::':::::::::;
//`````.```':|$@@@@@@@@@@@@@@@@@@@@@@@@###@@&&$|;:::'::::::
//````````````';|$&@@@@@@@@@###@@@@@@########@@@@$!''''::::
//`````````..````:|%$@@@@@#########@#########@@@@&!''''::::
//`````````````````:|&########################@@@$;::::::::
//``````````````````:!$@########################@%;:::'::::
//``````````..``````':|&#######################@@&!''''''::
//''''::'''`.`''''''':|@#######################@@&|:'`.`';!
//:::::::::``'''''';%@######################@@##@@&!::'';;;
//::;::::::`.''''';%@@@@####################$%@##@@%;:'':;!
//:;;;;::::``':;%@@@#########################&%&##@@|:'';;!
//;;!;;;;;;'`::;%@#############################@@##@$!'';!!
//;;;;;;;;:``':::::;|$@############################@$!'`;!!
//::;;;;;;:'`'::::::;!$@#######################&&@$$$;``:;;
//`````````..````````'|@#####################$;!$$$&@@|''':
//'''''''''''''':'''''|@#########@&@##########@@####@@&%|!!
//''''''''':'''::'':''!&########&!|&@##########&&####&%|!||
//:::::'''::::::::::::!&########|:;|$@#########@&###&%||||!
//:::::::'''''':::::::!&#######@!:;!!$@########@$&##@%||||!
//
//                    だからよ...止まるじゃねえぞ
// */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define  ll long long
const int N = 1e6 + 10;
#define PII pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;

#define __i __int128
// ll mod = 1e9+7;

string manacher(string s) {
  if (s.size() < 2)
    return s;
  string t;
  t += '$';
  for (int i = 0; i < s.size(); i++)
    t += '#' + s[i];
  t += '@';
  int num = t.size();
  int p[num];
  int id = 0, mx = 0;
  int maxl = -1;
  int index = 0;
  for (int j = 1; j < num - 1; j++) {
    p[j] = mx > j ? min(p[2 * id - j], mx - j) : 1;
    while (t[j + p[j]] == t[j - p[j]])
      p[j]++;
    if (mx < p[j] + j) {
      mx = p[j] + j;
      id = j;
    }
    if (maxl < p[j] + 1) {
      maxl = p[j] - 1;
      index = j;
    }
  }
  int start = (index - maxl) / 2;
  // cout <<start<<endl;
  return s.substr(start, start + maxl);
}
int ar[200010];
int br[100010];
vector<int> v[100010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  map<ll, ll> mp;
  for (int i = 1; i <= n; i++)
    cin >> ar[i], mp[ar[i]]++;
  map<ll, ll> mm;
  ll sum = 0;
  for (auto it : mp)
    sum += (it.second) * (it.second - 1) / 2;
  for (int i = 1; i <= n; i++) {

    cout << sum - (mp[ar[i]] - 1) << endl;
  }
  return 0;
}