use std::collections::BinaryHeap;
use std::collections::HashSet;
use std::io::BufRead;
use std::str::FromStr;
use std::fmt;
use std::str;

struct InputScanner<R: BufRead> {
    reader: R,
    buf: Vec<u8>, // Should never be empty
    pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}

impl<R: BufRead> InputScanner<R> {
    fn new(reader: R, capacity: usize) -> Self {
        InputScanner {
            reader: reader,
            buf: Vec::with_capacity(capacity),
            pos: 0,
        }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        if self.buf.is_empty() {
            self._read_next_line();
        }
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) => self.pos += 1,
                (b'\n', false) => self._read_next_line(),
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    #[inline]
    fn _read_next_line(&mut self) {
        self.pos = 0;
        self.buf.clear();
        if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
            panic!("Reached EOF");
        }
    }
}

fn cost(i: usize, j: usize, d: i32, a: &Vec<i32>) -> i64 {
    (i as i64 - j as i64).abs() * d as i64 + a[i] as i64 + a[j] as i64
}

fn main() {
    let stdin = std::io::stdin();
    let mut scanner = InputScanner::new(stdin.lock(), 1000);
    let n: usize = scanner.next();
    let d: i32 = scanner.next();
    let a: Vec<i32> = (0..n).map(|_| scanner.next()).collect();

    let mut heap = BinaryHeap::new();
    heap.push((0, 0));
    let mut visited = HashSet::new();
    let mut res = 0;
    while let Some((c, i)) = heap.pop() {
        if visited.contains(&i) { continue; }
        visited.insert(i);
        res -= c;
        for j in 0..n {
            if !visited.contains(&j) {
                heap.push((-cost(i, j, d, &a), j))
            }
        }
    };

    println!("{}", res)
}
