$<.each_line do |l|
  ps = l.split.map(&:to_i)
  cs = [1, 2, 1, 2, 1, 4, 1, 4]
  m = nil
  mins = []
  8.times do |i|
    c = 8.times.map {|j| [ps[j] - cs[(i+j)%8], 0].max }.inject :+
    if !m || m > c
      m = c
      mins = [i]
    elsif m == c
      mins << i
    end
  end
  puts mins.map {|i| 8.times.map {|j| cs[(i+j)%8] }.join ' ' }.sort.first
end