use proconio::input;

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

    if n > 100 {
        std::process::exit(0);
    }

    let mut ans = 0_usize;
    for i in 0..n {
        for j in 0..n {
            ans += i.abs_diff(j) * aa[i].abs_diff(aa[j]);
        }
    }

    println!("{}", ans);
}