#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main( void )
{
vector <int> p(8);int i;
while ( cin>>p[0] )
{
for(i=1;i<8;i++)cin>>p[i];
vector <int> c(8,1),k(8);
c[4]=c[5]=2;c[6]=c[7]=4;

int mc=0, mn;

do
{
int e=1;
int cf=0;
for ( i=0; i<7; i++ )
{
if ( (c[i]==2 && c[i+2]==2) || (c[i]==4 && c[i+2]==4) )
e = 0;
if ( c[i]%2==c[i+1]%2 )
{
cf=1;
break;
}
}
if ( e || cf )
continue;

vector <int> w=p;
int w_sum=0;
for ( i=0; i<8; i++ )
{
w[i] = w[i]>c[i] ? (int)ceil((double)w[i]/c[i]) : 1;
w_sum += w[i];
}

int wn=0;
for ( i=7; i>=0; i-- )
{
int d=1;
for ( int j=0; j<i; j++ )
{
d *= 10;
}
wn += c[7-i] * d;
}

if ( !mc || w_sum<mc )
{
k=c;
mc=w_sum;
mn=wn;
}
else if( w_sum==mc )
{
if ( wn<mn )
{
k=c;
mn=wn;
}
}

} while( next_permutation( c.begin(), c.end() ) );

for ( i=0; i<8; i++ )
{
cout<<k[i]<<(i<7?" ":"");
}
cout<<endl;
}
}