class Findmedian attr_reader :n, :a def initialize(n: 0, a: []) @n, @a = n, a end def datainput begin @n = Integer(gets.chomp) @a = gets.chomp.split.map { |v| Integer(v) } rescue end end def findmedian(n, array) array = array.sort if n % 2 == 0 v = array[(n / 2)-1] + array[n / 2] (v % 2 == 0)? v / 2 : v / 2.to_f else array[(n / 2).floor] end end def dataoutput puts findmedian(@n, @a) end def run datainput dataoutput end end if $0 == __FILE__ Findmedian.new.run end