//这种题读懂题都会做,细心就行了

#include"stdio.h"
int main(){
int m;
while(scanf("%d",&m),m){
int tmp=0,total=0,floor;
for(int i=0;i<m;i++)
{
scanf("%d",&floor);
if(floor>tmp) //上升
total+=(floor-tmp)*6;
if(floor<tmp) //下降
total+=(tmp-floor)*4;
tmp=floor;
}
printf("%d\n",total+m*5);


}
return 0;

}>