using
System;
using
System.Collections.Generic;
class
GFG
{
public
static
List<
long
> Solve(List<
long
> arr)
{
int
n = arr.Count;
var
unmap =
new
Dictionary<
long
, Tuple<
long
,
long
>>();
var
unmap2 =
new
Dictionary<
long
, Tuple<
long
,
long
>>();
for
(
int
i = 0; i < n; i++)
{
long
key = arr[i];
if
(!unmap.TryGetValue(key,
out
var
value))
{
value =
new
Tuple<
long
,
long
>(0, 0);
}
unmap[key] =
new
Tuple<
long
,
long
>(value.Item1 + 1, value.Item2 + i);
}
List<
long
> result =
new
List<
long
>();
for
(
int
i = 0; i < n; i++)
{
long
key = arr[i];
if
(!unmap2.TryGetValue(key,
out
var
curr))
{
curr =
new
Tuple<
long
,
long
>(0, 0);
}
long
leftSum = curr.Item2;
long
leftFreq = curr.Item1;
var
value = unmap[key];
long
rightSum = value.Item2 - leftSum - i;
long
rightFreq = value.Item1 - leftFreq - 1;
result.Add(((leftFreq * i) - leftSum) + (rightSum - (rightFreq * i)));
unmap2[key] =
new
Tuple<
long
,
long
>(curr.Item1 + 1, curr.Item2 + i);
}
return
result;
}
static
void
Main(
string
[] args)
{
List<
long
> arr =
new
List<
long
> { 2, 1, 4, 1, 2, 4, 4 };
List<
long
> result = Solve(arr);
foreach
(
var
item
in
result)
{
Console.Write(item +
" "
);
}
}
}