list = [4,1,4,1,2,1,2,1]

readlines.each{|line|
  arr = line.split.map(&:to_i)
  min = 1.0 / 0.0
  it = ""
  8.times{|j|
    list.push(list.shift)
    sum = 0
    8.times{|i|
      sum += arr[i] - list[i] if arr[i] > list[i]
    }
    if min > sum
      min = sum
      it = list.join("")
    elsif min == sum
      it = list.join("") if it > list.join("")
    end
  }
  puts it.split("").join(" ")
}