N = gets.to_i cards_a = gets.split.map(&:to_i) cards_b = gets.split.map(&:to_i) cnt = 0 total = 0 cards_a.permutation do |perm_a| cards_b.permutation do |perm_b| total += 1 vic_a = 0 vic_b = 0 N.times do |i| a = perm_a[i] b = perm_b[i] if a > b vic_a += 1 elsif b > a vic_b += 1 end end cnt += 1 if vic_a > vic_b end end p cnt.to_f / total