Language: C++

#include <stdio.h>
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline long long read(){
	long long now=0;int f=0;register char c=gc();
	for(;c<48||c>57;c=='-'&&(f=1),c=gc());for(;c>47&&c<58;now=(now<<3)+(now<<1)+c-'0',c=gc());
	return f?-now:now;
}
#define Maxn 200005
long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
signed main()
{
	n=read(),d=read();
	for (int i=0;i<n;++i) a[i]=read(),ans+=a[i];
	ans+=(n-1)*d;dpl[0]=a[0];dpr[n-1]=a[n-1];
	for (int i=1;i<n;++i) dpl[i]=Min(a[i],dpl[i-1]+d);
	for (int i=n-2;~i;--i) dpr[i]=Min(a[i],dpr[i+1]+d);
	for (int i=1;i<n-1;++i) ans+=Min(dpl[i],dpr[i]);
	printf("%lld\n",ans);
	return 0;
}#include <stdio.h>
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline long long read(){
	long long now=0;int f=0;register char c=gc();
	for(;c<48||c>57;c=='-'&&(f=1),c=gc());for(;c>47&&c<58;now=(now<<3)+(now<<1)+c-'0',c=gc());
	return f?-now:now;
}
#define Maxn 200005
long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
signed main()
{
	n=read(),d=read();
	for (int i=0;i<n;++i) a[i]=read(),ans+=a[i];
	ans+=(n-1)*d;dpl[0]=a[0];dpr[n-1]=a[n-1];
	for (int i=1;i<n;++i) dpl[i]=Min(a[i],dpl[i-1]+d);
	for (int i=n-2;~i;--i) dpr[i]=Min(a[i],dpr[i+1]+d);
	for (int i=1;i<n-1;++i) ans+=Min(dpl[i],dpr[i]);
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
a.cc:25:2: error: stray '#' in program
   25 | }#include <stdio.h>
      |  ^
a.cc: In function 'long long int read()':
a.cc:8:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    8 |         long long now=0;int f=0;register char c=gc();
      |                                               ^
a.cc: At global scope:
a.cc:25:3: error: 'include' does not name a type
   25 | }#include <stdio.h>
      |   ^~~~~~~
a.cc:31:18: error: redefinition of 'long long int read()'
   31 | inline long long read(){
      |                  ^~~~
a.cc:7:18: note: 'long long int read()' previously defined here
    7 | inline long long read(){
      |                  ^~~~
a.cc: In function 'long long int read()':
a.cc:32:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         long long now=0;int f=0;register char c=gc();
      |                                               ^
a.cc: At global scope:
a.cc:37:11: error: redefinition of 'long long int n'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |           ^
a.cc:13:11: note: 'long long int n' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |           ^
a.cc:37:13: error: redefinition of 'long long int d'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |             ^
a.cc:13:13: note: 'long long int d' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |             ^
a.cc:37:15: error: redefinition of 'long long int a [200005]'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |               ^
a.cc:13:15: note: 'long long int a [200005]' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |               ^
a.cc:37:23: error: redefinition of 'long long int dpl [200005]'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                       ^~~
a.cc:13:23: note: 'long long int dpl [200005]' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                       ^~~
a.cc:37:33: error: redefinition of 'long long int dpr [200005]'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                                 ^~~
a.cc:13:33: note: 'long long int dpr [200005]' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                                 ^~~
a.cc:37:43: error: redefinition of 'long long int ans'
   37 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                                           ^~~
a.cc:13:43: note: 'long long int ans' previously declared here
   13 | long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
      |                                           ^~~
a.cc:38:11: error: redefinition of 'long long int Min(long long int, long long int)'
   38 | long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
      |           ^~~
a.cc:14:11: note: 'long long int Min(long long int, long long int)' previously defined here
   14 | long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
      |           ^~~
a.cc:39:8: error: redefinition of 'int main()'
   39 | signed main()
      |        ^~~~
a.cc:15:8: note: 'int main()' previously defined here
   15 | signed main()
      |        ^~~~