use List::Util qw(max min sum);

my ($n) = split(/\s+/, <>);
my (@a) = split(/\s+/, <>);
#print "\n";

my @b;
for (0..$n-1) { push @b, { val=>$a[$_], key=>$_+1 }; }

my ($head, $tail) = (1, $n);
my @c;

for (0..$n-1) {
    my ($max, $maxi, $i) = (0, -1, 0);
    for (@b) {
	$_->{score}=$_->{val}*max($_->{key}-$head,$tail-$_->{key});
	if ($max < $_->{score}) { $max = $_->{score}; $maxi=$i; }
	$i++;
    }
    #print "$max, $maxi, $b[$maxi]->{key}\n";
    if ($b[$maxi]->{key}-$head > $tail-$b[$maxi]->{key}) {
	$c[$head++] = $b[$maxi];
    } else {
	$c[$tail--] = $b[$maxi];
    }
    splice @b, $maxi, 1;
}

my $sum = 0;
for (1..$n) {
    #print "$c[$_]->{key} $c[$_]->{val}\n";
    $sum += abs($c[$_]->{key}-$_)*$c[$_]->{val};
}
print $sum, "\n";
