随便写写
#include <iostream>
using namespace std;
int main(){
int flag, prev = 0, ans = 0;
while(cin >> flag, flag != 0){
if (flag == 2) {
if(prev == 1) prev = 0;
prev += 2;
} else prev = 1;
ans += prev;
}
cout << ans;
return 0;
}