while gets
  l=$_.split.map(&:to_i)
  fj=[1,4,1,4,1,2,1,2]
  max,ans=0,0
  8.times do |i|
    count=0
    8.times do |j|
      count+=[fj[j],l[j]].min
    end
    fj.rotate!(1)
    if count > max
      max = count
      ans = i
    end
  end
  puts "#{fj.rotate(ans).join(" ")}"
end