C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 40;
int a[N];
int main(){
int res = 0 ,add = 0 , x;
while(cin>>x){
if(x == 0){
cout<<res<<endl;
return 0;
}
if(x == 1){
res++ ; add = 0;
}else{
add += 2;
res +=add;
}
}
return 0;
}