Language: C++

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
int n,a[N],rank[N];
ll ans[N];
int cmp(int aa,int bb){
//	if(a[aa]==a[bb]) return aa>bb;
	return a[aa]>a[bb];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<=n;i++) rank[i]=i;
	sort(rank,rank+n+1,cmp);
	int now,nxt=0;
	ll tot1=0,tot2=0;
	while(nxt<n){
		now=nxt;
		while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
		ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
		tot1=tot2*a[rank[nxt]];
	}
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:31: error: reference to 'rank' is ambiguous
   14 |         for(int i=0;i<=n;i++) rank[i]=i;
      |                               ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:15:14: error: reference to 'rank' is ambiguous
   15 |         sort(rank,rank+n+1,cmp);
      |              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:15:19: error: reference to 'rank' is ambiguous
   15 |         sort(rank,rank+n+1,cmp);
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:20:23: error: reference to 'rank' is ambiguous
   20 |                 while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
      |                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:20:34: error: reference to 'rank' is ambiguous
   20 |                 while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
      |                                  ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:20:53: error: reference to 'rank' is ambiguous
   20 |                 while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
      |                                                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:21:21: error: reference to 'rank' is ambiguous
   21 |                 ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:21:45: error: reference to 'rank' is ambiguous
   21 |                 ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
      |                                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~
a.cc:22:29: error: reference to 'rank' is ambiguous
   22 |                 tot1=tot2*a[rank[nxt]];
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:5:12: note:                 'int rank [100010]'
    5 | int n,a[N],rank[N];
      |            ^~~~