#include #include #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; #define REP(i, a, b) for(int i = (a); i < int(b); ++i) #define rep(i, n) REP(i, 0, n) #define ALL(x) begin(x), end(x) template inline void chmax(T &a, const T &b) { if(a < b) a = b; } template inline void chmin(T &a, const T &b) { if(a > b) a = b; } vector> calc(int n, double p) { const double q = 1.0 - p; vector> res(n, vector(n, 0)); vector dp(1 << n, 0.0); vector next_dp(1 << n, 0.0); dp[(1 << n) - 1] = 1.0; for(int i = 0; i < n; ++i) { const int num = n - i; fill(begin(next_dp), end(next_dp), 0.0); double sum = 0.0; for(int card = 0; card < (1 << n); ++card) { if(__builtin_popcount(card) != num) continue; const auto cp = dp[card]; bool first = true; for(int j = 0; j < n; ++j) { if((card >> j) & 1) { double np; if(num == 1) { np = cp; } else if(first) { np = cp * p; } else { np = cp * q / (num - 1); } first = false; res[j][i] += np; next_dp[card ^ (1 << j)] += np; } } sum += cp; } // assert(abs(sum - 1.0) < 1e-8); dp.swap(next_dp); } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); int n; double pa, pb; cin >> n >> pa >> pb; vector a(n); vector b(n); for(auto &e : a) cin >> e; for(auto &e : b) cin >> e; sort(begin(a), end(a)); sort(begin(b), end(b)); const auto pa_card = calc(n, pa); const auto pb_card = calc(n, pb); double ans = 0.0; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(a[i] < b[j]) continue; for(int k = 0; k < n; ++k) { ans += (a[i] + b[j]) * pa_card[i][k] * pb_card[j][k]; } } } cout << ans << endl; return EXIT_SUCCESS; }