#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long int
typedef pair<int,int> pii;
ll tme , ans[50005];
int n , ner , idx , ls , val , k , it , bit[50005];
void update( int idx , int val , int n )
{
while( idx <= n )
{
bit[idx] += val;
idx += idx&(-idx);
}
}
int query( int idx )
{
int sum = 0 ;
while( idx > 0 )
{
sum += bit[idx];
idx -= idx&(-idx);
}
return sum;
}
bool cmp( pii a , pii b )
{
if( a.fi == b.fi )
{
return a.se < b.se;
}
return a.fi < b.fi;
}
int main() {
cin >> n;
vector<pii> arr;
for( int i = 1 ; i <= n ;i++)
{
int a ;
cin >> a;
arr.pb({a,i});
/*update the ith index that it is initially present and the ith
task has not been completed
1-not completed
0-completed*/
update(i,1,n);
}
//sorting in increasing order
sort( arr.begin() , arr.end() , cmp);
for( int i = 0 ; i < n ; i++)
{
val = arr[i].fi;
idx = arr[i].se;
//ner :- number of elements(tasks) remaining
ner = n-i;
/* find out number of task before current task which are not completed in
the origninal array*/
ls = query( idx );
/* iteration required to make the current task zero = value of the task
so if the iteration is not the 1 less than val then we need to make it
come to iteration 1 less than the iteration required
eg:- val - 5 , it = 2 , then we make it = 4 by adding ner*(5-2-1) = ner*4
*/
if( val-1 > it )
{
tme += (val - 1 - it)*1ll*ner ;
}
/* in tme add the position of the current element
after considerating how many task has been done.*/
ans[idx] = ls + tme;
/*k is for counting how many elements have same
value as the current element*/
k = 0;
for( int j = i+1 ; j < n ; j++)
{
if( val == arr[j].fi )
{
/* if element has same value then it's iteration will be equal
to the iteration of current element
then just add the position of the task in tme to get it's answer
*/
ls = query( arr[j].se );
k++;
ans[arr[j].se] = tme + ls;
}
else
{
break;
}
}
for( int j = i ; j < n ; j++)
{
if( val != arr[j].fi )
{
break;
}
/*updating values to -1 because the task have been ompleted
and won't be considered in next iteration*/
update(idx,-1,n);
}
/*make itreation equal to current value , similar update tme
for representing time past till current iteration
and update i */
tme += ner;
it = val;
i = i+k;
}
for( int i = 1 ; i <= n ;i++)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