Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
 
int main() {
  using namespace std;

  auto n = 0;
  cin >> n;

  vector<int> balls(n);
  for(int i = 0; i < n; i++) {
    cin >> balls[i];
  }

  set<int> uniqueBalls(balls.begin(), balls.end());
  sort(uniqueBalls.begin(), uniqueBalls.end());
  const auto && result = std::unique(uniqueBalls.begin(), uniqueBalls.end());
  for(int k = 0; k < n; k++) {
    int sum = 0;
    for (auto && itr = uniqueBalls.begin(); itr != result;)
    {
      auto && ct = count(balls.begin(), balls.end(), *itr);
      
      if (balls[k] == *itr)
      {
        ct -= 1;
      }
      sum += ct * (ct - 1);
      itr++;
    }
    cout << sum / 2 << endl;
  }
  
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = _Rb_tree_const_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/14/bits/stl_algo.h:4772:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = _Rb_tree_const_iterator<int>]'
 4772 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:18:7:   required from here
   18 |   sort(uniqueBalls.begin(), uniqueBalls.end());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1906:50: error: no match for 'operator-' (operand types are 'std::_Rb_tree_const_iterator<int>' and 'std::_Rb_tree_const_iterator<int>')
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                           ~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:1906:50: note:   'std::_Rb_tree_const_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                           ~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:1906:50: note:   'std::_Rb_tree_const_iterator<int>' is not derived from 'const std::move_iterator<_IteratorL>'
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                           ~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_ForwardIterator std::__unique(_ForwardIterator, _ForwardIterator, _BinaryPredicate) [with _ForwardIterator = _Rb_tree_const_iterator<int>; _BinaryPredicate = __gnu_cxx::__ops::_Iter_equal_to_iter]':
/usr/include/c++/14/bits/stl_algo.h:900:27:   required from '_FIter std::unique(_FIter, _FIter) [with _FIter = _Rb_tree_const_iterator<int>]'
  900 |       return std::__unique(__first, __last,
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
  901 |                            __gnu_cxx::__ops::__iter_equal_to_iter());
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:37:   required from here
   19 |   const auto && result = std::unique(uniqueBalls.begin(), uniqueBalls.end());
      |                          ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:870:21: error: assignment of read-only location '(& __dest.std::_Rb_tree_const_iterator<int>::operator++())->std::_Rb_tree_const_iterator<int>::operator*()'
  870 |           *++__dest = _GLIBCXX_MOVE(*__first);
      |                     ^