import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { try { new Main().execute(); } catch (Exception e) { e.printStackTrace(); } } public void execute() throws IOException { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); Integer[] handA = new Integer[N]; Integer[] handB = new Integer[N]; for (int i = 0; i < N; i++) { handA[i] = sc.nextInt(); } for (int i = 0; i < N; i++) { handB[i] = sc.nextInt(); } Permutation possibleHandsA = new Permutation<>(Arrays.asList(handA), true); int patterns = 0; int wins = 0; for (List ptnA : possibleHandsA) { Permutation possibleHandsB = new Permutation<>(Arrays.asList(handB), true); for (List ptnB : possibleHandsB) { if (aWins(ptnA, ptnB)) { wins++; } patterns++; } } System.out.println((double) wins / (double) patterns); sc.close(); } private boolean aWins(List a, List b) { int n = a.size(); int na = 0; for (int i = 0; i < n; i++) { if (a.get(i) > b.get(i)) { na++; } } return (na > (n - na)); } class Permutation> implements Iterable>, Iterator> { private final ArrayList permutation; private final int N; private boolean hasNext = true; public Permutation(List l) { this(l, false); } public Permutation(List l, boolean sort) { permutation = new ArrayList<>(l); N = permutation.size(); if (sort) { Collections.sort(permutation); } } private boolean _nextPermutation() { // Reference: https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order // Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation int k = N - 2; while (k >= 0) { if (permutation.get(k).compareTo(permutation.get(k + 1)) < 0) { break; } k--; } if (k == -1) { return false; } // Find the largest index l greater than k such that a[k] < a[l]. int l = N - 1; while (l > k) { if (permutation.get(k).compareTo(permutation.get(l)) < 0) { break; } l--; } Collections.swap(permutation, k, l); Collections.reverse(permutation.subList(k + 1, N)); return true; } @Override public Iterator> iterator() { return this; } @Override public boolean hasNext() { return this.hasNext; } @Override public List next() { if (this.hasNext) { List next = new ArrayList<>(permutation); hasNext = _nextPermutation(); return next; } else { return null; } } } }