#include<iostream> using namespace std; int ans; int main(){ int n,sum=0; while(cin>>n,n){ if(n==1) sum=1; else if(sum==1)sum=2; else sum+=2; ans+=sum; } cout<<ans; return 0; }