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]
    elsif count == max
      ans << i
    end
  end
  if ans.size > 1
    mnum = []
    ans.each do |a|
      mnum << fj.rotate(a).join.to_i
    end
    puts "#{fj.rotate(ans[mnum.index(mnum.min)]).join(" ")}"
  else
    puts "#{fj.rotate(ans[0]).join(" ")}"
  end
end