class Yukicoder def initialize n = gets.chomp size = n.size max_val = n.to_i 0.upto(size-2) do |i| i.upto(size-1) do |j| num = n.dup num[i], num[j] = num[j], num[i] num = num.to_i if max_val < num max_val = num end end end puts max_val end end Yukicoder.new