def solve(arr)
  return arr.select{|l| l > 0} == [2] if arr.sum == 2

  (0..6).each do |i|
    if arr[i] >= 1 && arr[i + 1] >= 1 && arr[i + 2] >= 1
      da = arr.dup
      da[i] -= 1
      da[i + 1] -= 1
      da[i + 2] -= 1
      return true if solve(da)
    end
  end
  (0..8).each do |i|
    if arr[i] >= 3
      da = arr.dup
      da[i] -= 3
      return true if solve(da)
    end
  end
  false
end

loop do
  l = gets
  break if l.nil?
  next unless l.length == 14

  q = l.strip.split('').map(&:to_i)
  res = []
  9.times do |i|
    line = q + [i + 1]
    arr = [0] * 9
    line.each {|j| arr[j - 1] += 1 }
    next if arr.find{|a| a == 5 }
    res << (i + 1) if solve(arr)
  end
  puts res.empty? ? 0 : res.join(' ')
end

