void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; long p; rd(n, p); auto h=readln.split.to!(long[]); auto rec=new long[][](n, 3); const R=0, L=1, JP=2; rec[1][L]=1_000_000_000_000_000_000; foreach(i; 1..n){ rec[i][R]=min(rec[i-1][R], rec[i-1][JP])+max(0, h[i]-h[i-1]); if(i>=2) rec[i][L]=min(rec[i-1][L], rec[i-1][JP])+max(0, h[i-1]-h[i]); rec[i][JP]=min(rec[i-1][R], rec[i-1][L], rec[i-1][JP])+p; } writeln(reduce!(min)(rec[n-1])); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }