use std::cmp::max;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut a = Vec::new();
    for i in 0..n {
        let b: i64 = itr.next().unwrap().parse().unwrap();
        a.push((b, i as i64));
    }
    a.sort();
    a.reverse();

    let mut dp = vec![vec![0; 2020]; 2020];
    for i in 0..n {
        let mut next = dp.clone();
        for j in 0..i + 1 {
            let k = n - (i - j);
            next[j + 1][k] = max(
                next[j + 1][k],
                dp[j][k] + a[i].0 * (j as i64 - a[i].1).abs(),
            );
            next[j][k - 1] = max(
                next[j][k - 1],
                dp[j][k] + a[i].0 * (k as i64 - 1 - a[i].1).abs(),
            );
        }
        dp = next;
    }

    let mut ans = 0;
    for i in 0..n + 1 {
        ans = max(ans, dp[i][n - i]);
    }
    println!("{}", ans);
}