1 #include <iostream> 2 //#include <bits/stdc++.h> 3 #include <string> 4 5 using namespace std; 6 7 int main() 8 { 9 int number; 10 int sum=0; 11 int base=2; 12 bool flag=false; 13 while(cin>>number) 14 { 15 if(number==0) 16 { 17 cout<<sum; 18 return 0; 19 } 20 else if(number==1) 21 { 22 sum++; 23 flag=false; 24 base=2; 25 } 26 else if(number==2) 27 { 28 flag=true; 29 sum+=base; 30 if(flag==true) 31 base+=2; 32 } 33 } 34 cout<<sum; 35 return 0; 36 }