use proconio::input;

fn main() {
  input! {
    n: usize,
    a: [i64; n],
  }

  let mut v: Vec<(i64, i64, usize, usize)> = Vec::with_capacity(n*n);
  let mut occupied = vec![false; n];
  let mut used = vec![false; n];
  for i in 0..n {
    for j in 0..n {
      v.push((a[i] * (i as i64 - j as i64).abs(), -a[i],  i, j));
    }
  }
  v.sort();
  v.reverse();
  let mut res: i64 = 0;
  for (cost, _, i, j) in v {
    if !used[i] && !occupied[j] {
      res += cost;
      used[i] = true;
      occupied[j] = true;
    }
  }
  println!("{}", res);
}