#include <iostream>
#include <map>
using namespace std;
map<int,int>mp;
int cont=0;
void tree(int n)
{
int t;
cin>>t;
if(t==-1)
return ;
mp[n]+=t;
tree(n-1);
tree(n+1);
cont++;
}
int main()
{
int kase=1;
while(1)
{
cont=0;
mp.clear();
tree(0);
if(!cont) break;
printf("Case %d:\n",kase++);
map<int,int>::iterator it;
for(it=mp.begin();it!=mp.end();it++)
if(it==mp.begin()) cout<<it->second;
else cout<<" "<<it->second;
cout<<endl<<endl;
}
return 0;
}