horses = [4, 1, 4, 1, 2, 1, 2, 1]

readlines.each do |passengers|
  ps = passengers.chomp.split.map(&:to_i)
  hs = horses.dup
  h_result = horses.dup
  max = 0
  (0..7).each do |i|
    temp = ps.map.with_index{ |p, j| (p < hs[j] ? p : hs[j])}.inject(&:+)
    if max < temp
      max = temp
      h_result = hs.dup
    elsif max == temp
      h_result = hs.dup if hs.join.to_i < h_result.join.to_i
    end
    hs.rotate!
  end

  puts h_result.join(' ')
end