#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int calc(const std::vector<int> &p, int c){
	int ret = 0;

	for(int i = 0; i < p.size(); i++){
		ret += std::min(p[i], c % 10);
		c /= 10;
	}

	return ret;
}

int next_c(int c){
	int ret = c / 10 + (c % 10) * 10000000;

	return ret;
}

int main(int argc, char **argv){
	std::vector<int> p(8, 0);


#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7]){
#else
	while(std::cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7]){
#endif
		int c = 41412121;
		int max = -1;
		int max_c = 0;

		for(int i = 0; i < 8; i++){
			int m = calc(p, c);

			if(max < m){
				max = m;
				max_c = c;
			}
			else if(max == m && max_c < c){
				max_c = c;
			}
			c = next_c(c);
		}

		std::cout << max_c % 10;
		max_c /= 10;
		for(int i = 1; i < 8; i++){
			std::cout << " " << max_c % 10;;
			max_c /= 10;
		}
		std::cout << std::endl;
	}


 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}
