#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
int Clock[10],path[50000000],ok=0,step=0;
int change[][10]=
{{0},
{0,1,1,0,1,1,0,0,0,0},
{0,1,1,1,0,0,0,0,0,0},
{0,0,1,1,0,1,1,0,0,0},
{0,1,0,0,1,0,0,1,0,0},
{0,0,1,0,1,1,1,0,1,0},
{0,0,0,1,0,0,1,0,0,1},
{0,0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,0,1,1,1},
{0,0,0,0,0,1,1,0,1,1}};
int check()
{
for(int i=1;i<=9;i++)
if(Clock[i]!=0)
return 0;
return 1;
}
void add(int *c,int x,int *ch)
{
for(int i=1;i<=9;i++){
c[i]+=x*ch[i];
c[i]%=4;
}
}
void run(int i,int k)
{
if(check()){
ok=1;
step=k;
return;
}
if(i>9)
return;
for(int x=0;x<=3;x++){
if(!ok){
if(x!=0){
add(Clock,x,change[i]);
path[k+x]=i;
}
run(i+1,k+x);
}
}
}
void out()
{
for(int i=1;i<=step;i++)
cout<<path[i]<<" ";
cout<<endl;
}
int main()
{
freopen("P1.in","r",stdin);
freopen("P1.out","w",stdout);
for(int i=1;i<=9;i++){
cin>>Clock[i];
Clock[i]/=3;
Clock[i]%=4;
}
/*for(int i=1;i<=9;i++)
cout<<Clock[i]<<" ";
cout<<endl;*/
run(1,0);
out();
return 0;
}
#include<fstream>
#include<cstdio>
using namespace std;
int Clock[10],path[50000000],ok=0,step=0;
int change[][10]=
{{0},
{0,1,1,0,1,1,0,0,0,0},
{0,1,1,1,0,0,0,0,0,0},
{0,0,1,1,0,1,1,0,0,0},
{0,1,0,0,1,0,0,1,0,0},
{0,0,1,0,1,1,1,0,1,0},
{0,0,0,1,0,0,1,0,0,1},
{0,0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,0,1,1,1},
{0,0,0,0,0,1,1,0,1,1}};
int check()
{
for(int i=1;i<=9;i++)
if(Clock[i]!=0)
return 0;
return 1;
}
void add(int *c,int x,int *ch)
{
for(int i=1;i<=9;i++){
c[i]+=x*ch[i];
c[i]%=4;
}
}
void run(int i,int k)
{
if(check()){
ok=1;
step=k;
return;
}
if(i>9)
return;
for(int x=0;x<=3;x++){
if(!ok){
if(x!=0){
add(Clock,x,change[i]);
path[k+x]=i;
}
run(i+1,k+x);
}
}
}
void out()
{
for(int i=1;i<=step;i++)
cout<<path[i]<<" ";
cout<<endl;
}
int main()
{
freopen("P1.in","r",stdin);
freopen("P1.out","w",stdout);
for(int i=1;i<=9;i++){
cin>>Clock[i];
Clock[i]/=3;
Clock[i]%=4;
}
/*for(int i=1;i<=9;i++)
cout<<Clock[i]<<" ";
cout<<endl;*/
run(1,0);
out();
return 0;
}