# frozen_string_literal: true X = gets.chomp.chars.map(&:to_i).sort if X.uniq.size == 1 || X[-2].zero? puts(-1) else result = [] swapped = false X.each_cons(2) do |a, b| if swapped result << b elsif a != b result << b << a swapped = true else result << a end end puts result.reverse.join end