#include <bits/stdc++.h>
using namespace std;
string customer = "";
char character[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
string _log[8]; //パターンはたかだか８つ
int sumOfCustomer = 0;

//１ずらす
string _rotate(string pattern) {
    int top = pattern[0];
    for(int r = 0; r < pattern.length() - 1; r++) {
        pattern[r] = pattern[r+1];
    }
    pattern[pattern.length() - 1] = top;
    return(pattern);
}

int count(string pattern, string customer) {
    int cnt = 0;
    for(int r = 0; r < pattern.length(); r++) {
        int pat = pattern[r] - '0', cus = customer[r] - '0';
        if(pat - cus < 0) continue; //乗れた人だけ数える
        cnt += pat - cus;
    }
    return(sumOfCustomer - cnt); //乗れなかった人を返す
}

void print(string output) {
    for(int r = 0; r < output.length(); r++) {
        cout << output[r];
        if(r == output.length() - 1) putchar('\n');
        else putchar(' ');
    }
}

void solve() {
    string pattern = "41412121";
    int idx = 0;
    int min_idx = INT_MAX, min_val = INT_MAX;
    
    //全パターン試す
    for(int r = 0; r < pattern.length(); r++) {
        int result = count(pattern, customer);
        cout << result << endl;
        if(min_val > result) {
            min_val = result;
            min_idx = idx;
            _log[idx++] = pattern;
        }
        pattern = _rotate(pattern);
    }
    //出力
    print(_log[min_idx]);
}

int main(void) {
    while(true) {
        int input; customer = "";
        for(int r = 0; r < 8; r++) {
            if(!(cin >> input)) break;
            customer += character[input];
            sumOfCustomer += input;
        }
        solve();
    }
    return(0);
}