#include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template int choose(double p, vector const & a, vector & used, int i, Generator & gen) { int n = a.size(); int k = 0; if (i != n-1 and uniform_real_distribution()(gen) > p) { k = uniform_int_distribution(1,n-i-1)(gen); } repeat (j,n) if (not used[j]) if (k -- == 0) { used[j] = true; return a[j]; } } int main() { random_device device; default_random_engine gen(device()); int n; double p, q; cin >> n >> p >> q; vector a(n); repeat (i,n) cin >> a[i]; sort(a.begin(), a.end()); vector b(n); repeat (i,n) cin >> b[i]; sort(b.begin(), b.end()); int win = 0, lose = 0; repeat (iteration,1000000) { vector > used(2, vector(n)); int score = 0; repeat (i,n) { int x = choose(p, a, used[0], i, gen); int y = choose(q, b, used[1], i, gen); score += (x > y ? 1 : -1) * (x + y); } (score > 0 ? win : lose) += 1; } printf("%.8lf\n", win /(double) (win + lose)); return 0; }