class Yukicoder LIST = [*('0'..'9')] + [*('A'..'Z')] def initialize n = gets.chomp.to_i num_list = [] max_value = 0 n.times do str = gets.chomp num_list << str max_value = [max_value, str.chars.map{|ch| LIST.index(ch)}.max].max end puts num_list.map{|num| encode(num, max_value+1)}.min end def encode(str, e) str.to_i(e) end end Yukicoder.new