AC代码
#include <bits/stdc++.h>
using namespace std;
#define ms(a,b) memset(a,b,sizeof(a))
typedef long long ll;
int a[100005];
int n;
inline int read(){
int X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
int main(int argc,char* argv[]){
n=read();
for (int i=1;i<=n;i++) a[i]=read();
ll ans=0;
for (int i=2;i<=n;i++) ans+=max(a[i],a[i-1]);
printf("%lld
",ans);
return 0;
}