<?php
$N = (int)trim(fgets(STDIN));
$A = explode(' ', fgets(STDIN));
$A = array_map(function ($a) {
    return (int)$a;
}, $A);
$ans = 0;
$prefix = 0;
$suffix = 0;

while ($prefix + $suffix < $N) {
    $max = 0;
    $to_front = false;
    $max_i = 0;
    for ($i = 0; $i < $N; $i++) {
        if ($i < ($N - $suffix) / 2) {
            $new_happy = $A[$i] * ($N - $i - 1 - $suffix);
            if ($new_happy > $max || ($new_happy === $max && $A[$i] > $A[$max_i])) {
                $max = $new_happy;
                $to_front = false;
                $max_i = $i;
            }
        } else {
            $new_happy = $A[$i] * ($i - $prefix);
            if ($new_happy > $max || ($new_happy === $max && $A[$i] > $A[$max_i])) {
                $max = $new_happy;
                $to_front = true;
                $max_i = $i;
            }
        }
    }
    if ($to_front) {
        $prefix += 1;
    } else {
        $suffix += 1;
    }
    $A[$max_i] = 0;
    $ans += $max;
    $max = 0;
}

echo $ans;