macro_rules! input {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
        bytes
            .by_ref()
            .map(|r|r.unwrap() as char)
            .skip_while(|c|c.is_whitespace())
            .take_while(|c|!c.is_whitespace())
            .collect()
    };
    input! {next,
        n: usize,
        a: [usize; n],
    }
    let a: Vec<_> = a.into_iter().enumerate().map(|(i,v)| (v,i)).collect();
    let mut best = 0;
    for pos in 1..n-1 {
        let mut total = 0;
        let mut a = a.clone();
        let (left, right) = a.split_at_mut(pos);
        left.sort();
        right.sort();
        right.reverse();
        // dbg!(&left);
        // dbg!(&right);
        let mut b = Vec::new();
        b.extend(right);
        b.extend(left);
        for (i, (activity, old_i)) in b.into_iter().enumerate() {
            total += *activity * (if i > *old_i { i - *old_i } else { *old_i - i });
        }
        best = std::cmp::max(best, total);
    }
    println!("{:?}", best);
}
