while line = gets
    arr = line.chomp.split.map(&:to_i)
    result = {}
    (0..7).to_a.combination(4).each{|a,b,c,d|
        arr2 = [1,1,1,1,1,1,1,1]
        arr2[a], arr2[b], arr2[c], arr2[d] = 4, 4, 2, 2
        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

