#include int main() { int n,m,v[1000],i; scanf("%d",&n); scanf("%d",&v[0]); if (n>=2) {scanf("%d",&m);v[1]=(v[0]>m)?v[0]:m;} for (i=2;iv[i-2]+m)?v[i-1]:v[i-2]+m; } printf("%d",v[n-1]); return 0; }