1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int const maxn=10000; 8 int sum[maxn]; 9 10 11 void built(int p) 12 { 13 int v; 14 cin>>v; 15 16 if(v==-1) return; 17 18 sum[p]+=v; 19 built(p-1); 20 built(p+1); 21 } 22 23 bool init() 24 { 25 memset(sum,0,sizeof(sum)); 26 27 int v; 28 cin>>v; 29 if (v==-1) return false; 30 31 int p=maxn/2; 32 sum[p]=v; 33 34 built(p-1); 35 built(p+1); 36 37 return true; 38 } 39 40 int main() 41 { 42 while(init()) 43 { 44 int p=0; 45 46 while(sum[p]==0) p++; 47 48 cout<<sum[p]; 49 50 while(sum[++p]!=0) cout<<" "<<sum[p]; 51 52 cout<<endl; 53 } 54 55 return 0; 56 }