#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        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_inner!{next, $($r)*}
    };
}

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

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$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, usize1) => {
        read_value!($next, usize) - 1
    };

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

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

/**
 * Union-Find tree.
 * Verified by yukicoder No.94 (http://yukicoder.me/submissions/82111)
 */
struct UnionFind { disj: Vec<usize> }

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut disj = vec![0; n];
        for i in 0 .. n {
            disj[i] = i;
        }
        UnionFind { disj: disj }
    }
    fn root(self: &mut Self, x: usize) -> usize {
        if x != self.disj[x] {
            let par = self.disj[x];
            let r = self.root(par);
            self.disj[x] = r;
        }
        return self.disj[x];
    }
    fn unite(self: &mut Self, x: usize, y: usize) {
        let xr = self.root(x);
        let yr = self.root(y);
        self.disj[xr] = yr;
    }
    fn is_same_set(self: &mut Self, x: usize, y: usize) -> bool {
        return self.root(x) == self.root(y);
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        d: i64,
        a: [i64; n],
    }
    let mut tot = 0;
    let mut conn = n;
    let mut uf = UnionFind::new(n);
    let mut lft = vec![0; n];
    let mut rgt = vec![0; n];
    for i in 0 .. n {
        lft[i] = a[i] - i as i64 * d;
        rgt[i] = a[i] + i as i64 * d;
    }
    const INF: i64 = 1 << 50;
    while conn > 1 {
        let mut mi = vec![(INF, n * n); n];
        let mut col = vec![0; n];
        for i in 0 .. n { col[i] = uf.root(i); }
        let mut pool: Vec<(i64, usize)> = Vec::new();
        for i in 0 .. n {
            if i > 0 {
                let mut tmp = (INF, n * n);
                if col[i] != col[pool[0].1] {
                    tmp = (pool[0].0 + rgt[i], pool[0].1 * n + i);
                } else if pool.len() >= 2 {
                    tmp = (pool[1].0 + rgt[i], pool[1].1 * n + i);
                }
                mi[col[i]] = min(mi[col[i]], tmp);
            }
            pool.push((lft[i], i));
            pool.sort();
            if pool.len() >= 3 {
                pool.pop();
            }
        }
        pool.clear();
        for i in (0 .. n).rev() {
            if i + 1 < n {
                let mut tmp = (INF, n * n);
                if col[i] != col[pool[0].1] {
                    tmp = (pool[0].0 + lft[i], pool[0].1 + n * i);
                } else if pool.len() >= 2 {
                    tmp = (pool[1].0 + lft[i], pool[1].1 + n * i);
                }
                mi[col[i]] = min(mi[col[i]], tmp);
            }
            pool.push((rgt[i], i));
            pool.sort();
            if pool.len() >= 3 {
                pool.pop();
            }
        }
        for i in 0 .. n {
            if mi[i].0 < INF {
                let x = mi[i].1 / n;
                let y = mi[i].1 % n;
                if !uf.is_same_set(x, y) {
                    uf.unite(x, y);
                    tot += mi[i].0;
                    conn -= 1;
                }
            }
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
