while line = gets
    arr = line.chomp.split.map(&:to_i)
    arr2 = [4,1,4,1,2,1,2,1]
    result = {}
    8.times{|i|
        arr2.rotate!(1)
        rest = 0
        0.upto(7){|i| rest += arr[i] - arr2[i] if arr[i] > arr2[i]}
        result[rest] = arr2.join.to_i if result[rest].nil? || result[rest] > arr2.join.to_i
    }
    puts (result.sort.first)[1].to_s.split("").join(" ")
end

