// #define NDEBUG #include #define REP_(i, a_, b_, a, b, ...) for (int i = (a), END_##i = (b); i < END_##i; ++i) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(x) std::begin(x), std::end(x) using Int = long long; using Uint = unsigned long long; using Real = long double; template inline bool chmax(T &a, U b) { return a < b and ((a = b), true); } template inline bool chmin(T &a, U b) { return a > b and ((a = b), true); } template constexpr T kBig = std::numeric_limits::max() / 2; #if __cplusplus < 202002L template inline int ssize(const T &a) { return (int) a.size(); } #endif template class InputReader { public: void skip() { [[maybe_unused]] static const bool lazy_init = [this]() { const size_t len = fread(buf_, 1, sizeof(buf_) - 1, stdin); buf_[len] = '\0'; ptr_ = buf_; bufend_ = buf_ + len; return true; }(); while (isspace(*ptr_)) ++ptr_; } template operator T() { T x; skip(); assert(not is_eof()); // Couldn't read reached the end of input. read_one(x); return x; } struct Sized { InputReader &reader; int n; template operator T() const { T xs(n); for (auto &x: xs) { reader.skip(); assert(not reader.is_eof()); reader.read_one(x); } return xs; } }; Sized operator()(int n) { return {*this, n}; } bool is_eof() const { return ptr_ >= bufend_; } private: template std::enable_if_t> read_one(T &x) { [[maybe_unused]] int sign = 1; if constexpr (std::is_signed_v) { sign = (*ptr_ == '-') ? (++ptr_, -1) : 1; } x = 0; while (isdigit(*ptr_)) x = x * 10 + (*ptr_++ & 0x0F); if constexpr (std::is_signed_v) { x *= sign; } } template std::enable_if_t> read_one(T &x) { [[maybe_unused]] int sign = 1; if constexpr (std::is_signed_v) { sign = (*ptr_ == '-') ? (++ptr_, -1) : 1; } x = 0; while (isdigit(*ptr_)) x = x * 10 + (*ptr_++ & 0x0F); if (*ptr_ == '.') { ++ptr_; for (T base = 0.1; isdigit(*ptr_); ++ptr_, base *= 0.1) { x += (*ptr_ & 0x0F) * base; } } if constexpr (std::is_signed_v) { x *= sign; } } void read_one(std::string &s) { char *p0 = ptr_; while (not isspace(*ptr_)) ptr_++; s.assign(p0, ptr_); } void read_one(std::string_view &s) { const char *p0 = ptr_; while (not isspace(*ptr_)) ptr_++; s = std::string_view(p0, ptr_ - p0); } static inline char buf_[BufSize]; char *ptr_, *bufend_; }; InputReader<(1 << 26)> in; template std::ostream &out_seq(const Container &seq, const char *sep = " ", const char *ends = "\n", std::ostream &os = std::cout) { const auto itl = std::begin(seq), itr = std::end(seq); for (auto it = itl; it != itr; ++it) { if (it != itl) os << sep; os << *it; } return os << ends; } template std::ostream &out_one(const T &x, char endc) { if constexpr (std::is_same::value) { return std::cout << (x ? "Yes" : "No") << endc; } else { return std::cout << x << endc; } } template std::ostream &out(const T &x) { return out_one(x, '\n'); } template std::ostream &out(const T &head, Ts... tail) { return out_one(head, ' '), out(tail...); } void init_() { // std::ios::sync_with_stdio(false); // std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(18); } [[noreturn]] void exit_() { #ifdef MY_DEBUG in.skip(); assert(in.is_eof()); // Some input is left. #endif fflush(stdout), fflush(stderr); std::cout.flush(), std::cerr.flush(); std::_Exit(0); } #ifdef MY_DEBUG #include "debug_dump.hpp" #include "backward.hpp" backward::SignalHandling kSignalHandling; #else #define DUMP(...) #define test_case(...) #define cerr if(false)cerr #endif using namespace std; template bool has_bit(const T &x, int i) { return (x >> i) & 1; } template> int popcount(T x) { if constexpr (std::is_same_v) { return __builtin_popcount(static_cast(x)); } else if constexpr (std::is_same_v) { return __builtin_popcountl(static_cast(x)); } else if constexpr (std::is_same_v) { return __builtin_popcountll(static_cast(x)); } assert(false); // unsupported type } int countr_zero(unsigned x) { if (x == 0) return std::numeric_limits::digits; return __builtin_ctz(x); } int countr_one(unsigned x) { x = ~x; if (x == 0) return std::numeric_limits::digits; return __builtin_ctz(x); } auto solve() { const int n = in; const Real Pa = in, Pb = in; vector A = in(n), B = in(n); sort(ALL(A)); sort(ALL(B)); const int kFull = (1 << n) - 1; auto f = [&](Real P, vector &dp, vector> &H) { dp[0] = 1.0; REP(bits, kFull) { int pc = popcount(bits); Real cur = dp[bits]; if (cur == 0.0) continue; int smallest = countr_one(bits); if (pc + 1 == n) { dp[kFull] += cur; H[pc][smallest] += cur; continue; } dp[bits | (1 << smallest)] += cur * P; H[pc][smallest] += cur * P; if (n == pc + 1) continue; Real R = (1.0 - P) / Real(n - (pc + 1)); unsigned b = bits | (1 << smallest); for (int i = countr_one(b); i < n; i = countr_one(b)) { dp[bits | (1 << i)] += cur * R; H[pc][i] += cur * R; b |= 1 << i; } } }; auto dpa = vector(1 << n, Real(0.0)); auto dpb = vector(1 << n, Real(0.0)); auto Ha = vector(n + 1, vector(n, Real(0.0))); auto Hb = vector(n + 1, vector(n, Real(0.0))); f(Pa, dpa, Ha); f(Pb, dpb, Hb); Real ans = 0; REP(i, n) { REP(x, n) { REP(y, n) { if (A[x] > B[y]) { ans += (A[x] + B[y]) * Ha[i][x] * Hb[i][y]; } } } } out(ans); } int main() { init_(); const int T = 1;//in; REP(t, T) { test_case(t, T); (solve()); } exit_(); }