
import std.stdio;
import std.conv;
import std.array;
import std.algorithm;
import std.string;

void main() {
  uint[] pos = [4, 1, 4, 1, 2, 1, 2, 1];
  while(true) {
    string line = readln.chomp;
    if (stdin.eof) break;
    uint[] passengers =
      line.strip.split(" ").map!((x) => to!(uint)(x[0] - '0')).array;
    uint ans;
    uint[] arr;
    uint min = uint.max;
    foreach(i; 0..8) {
      uint[] rotate_pos = pos[i..$] ~ pos[0..i];
      uint[] p = passengers.dup;
      foreach(j; 0..8) {
        if (rotate_pos[j] < p[j]) p[j] -= rotate_pos[j];
        else p[j] = 0;
      }
      auto sum = p.reduce!("a + b");
      if (sum == min) {arr ~= i;}
      if (sum < min) {min = sum; arr = [i];}
    }
    min = uint.max;
    foreach(i; arr) {
      uint[] rotate_pos = pos[i..$] ~ pos[0..i];      
      auto digit = rotate_pos.reduce!("10 * a + b");
      if (digit < min) {min = digit; ans = i;}
    }
    (pos[ans..$] ~ pos[0..ans]).map!(to!(string)).join(" ").writeln;
  }
}