c = [4,1,4,1,2,1,2,1]
readlines.each do |l|
  p = l.split.map(&:to_i)
  ans = 7.times.map{ c=c.rotate }.sort do |a,b|
    t = (a.zip(p).map{|i,j| [i-j,0].max}.inject(:+) <=>
         b.zip(p).map{|i,j| [i-j,0].max}.inject(:+))
    t==0 ? a.join.to_i <=> b.join.to_i : t
  end.first
  puts ans.join(" ")
end