Language: C++

using namespace std;

int main(){
	int n;
  	cin>>n;
  	vector<pair<int, int> > a;
  	for(int i=0;i<n;i++){
      	int t;
    	cin>>t;
      	a.push_back(make_pair(t, i));
    }
  	sort(a.begin(), a.end());

  	int ck[2]={a[0].first, 0};
  	long int sck=0; int b[n]={0};
  	for(int i=0;i<n;i++){
      	if(i==n-1){
        	int k=n-1-ck[1];
          	if(ck[0]==a[n-1].first) k++;
          	if(k>1){
          		sck+=(long int)k*(k-1)/2;
            }
          	for(int j=n-1;j>=ck[1];j--){
            	b[a[j].second]=k;
            }
          	if(ck[0]!=a[n-1].first) b[a[n-1].second]=1;
          	break;
        }
      	if(ck[0]!=a[i].first){
          	int k=i-ck[1];
            if(k>1){
        		sck+=(long int)k*(k-1)/2;
        	}
          	for(int j=i-1;j>=ck[1];j--){
            	b[a[j].second]=k;
            }
          	ck[0]=a[i].first; ck[1]=i;
        } 	
    }
  
  	for(int i=0;i<n;i++){
      	long int l=b[i]-1;
      	cout<<sck-l<<endl;
    }
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:9: error: 'cin' was not declared in this scope
    5 |         cin>>n;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:6:9: error: 'vector' was not declared in this scope
    6 |         vector<pair<int, int> > a;
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:6:16: error: 'pair' was not declared in this scope
    6 |         vector<pair<int, int> > a;
      |                ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | using namespace std;
a.cc:6:21: error: expected primary-expression before 'int'
    6 |         vector<pair<int, int> > a;
      |                     ^~~
a.cc:10:9: error: 'a' was not declared in this scope
   10 |         a.push_back(make_pair(t, i));
      |         ^
a.cc:10:21: error: 'make_pair' was not declared in this scope
   10 |         a.push_back(make_pair(t, i));
      |                     ^~~~~~~~~
a.cc:10:21: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:12:14: error: 'a' was not declared in this scope
   12 |         sort(a.begin(), a.end());
      |              ^
a.cc:12:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   12 |         sort(a.begin(), a.end());
      |         ^~~~
      |         short
a.cc:43:9: error: 'cout' was not declared in this scope
   43 |         cout<<sck-l<<endl;
      |         ^~~~
a.cc:43:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:22: error: 'endl' was not declared in this scope
   43 |         cout<<sck-l<<endl;
      |                      ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;