#![allow(dead_code, unused_mut, unused_variables, unused_imports)]

use std::collections::{HashMap, HashSet, VecDeque};
use std::io::*;
struct Io<'a> {
    r: BufReader<StdinLock<'a>>,
    w: BufWriter<StdoutLock<'a>>,
    buf: VecDeque<String>,
    buf_str: String,
}
impl<'a> Io<'a> {
    fn r<T: std::str::FromStr>(&mut self) -> T {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!())
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.w, "{}", v).unwrap();
    }
    fn iter<'b, T: std::str::FromStr>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter {
            io: self,
            p: std::marker::PhantomData,
        }
    }
}
struct IoIter<'a: 'b, 'b, T: std::str::FromStr> {
    io: &'b mut Io<'a>,
    p: std::marker::PhantomData<T>,
}
impl<'a, 'b, T: std::str::FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let r = BufReader::new(stdin.lock());
    let w = BufWriter::new(stdout.lock());
    let io = Io {
        r: r,
        w: w,
        buf: VecDeque::new(),
        buf_str: String::new(),
    };
    problem(io);
}

fn problem(mut io: Io) {
    let n: usize = io.r();
    let a: Vec<usize> = io.iter().take(n).collect();

    let mut arr = Vec::with_capacity(n);
    io.w(put(&mut arr, &a));
}

fn put(arr: &mut Vec<usize>, a: &Vec<usize>) -> usize {
    if arr.len() == a.len() {
        calc(arr, a)
    } else {
        let mut max = 0;
        for i in 0..a.len() {
            if !arr.contains(&i) {
                arr.push(i);
                max = max.max(put(arr, a));
                arr.pop();
            }
        }
        max
    }
}
fn calc(arr: &Vec<usize>, a: &Vec<usize>) -> usize {
    let mut sum = 0;
    for i in 0..arr.len() {
        sum += a[arr[i]] * (arr[i] as isize - i as isize).abs() as usize;
    }
    sum
}
