// yukicoder: 133 カードゲーム // 2019.5.20 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 非負整数の入力 { int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int A[5], B[5]; int ord[30][5], sz; void genperm(int K) { int i, k, t; char c[12], *pc, *q; static char p[12] = { 1,1,1,1 }; q = p, pc = c; for (k = 1; k <= K; ) *q++ = *pc++ = k++; // 1 2 3 のように1から k = 1, pc = c; do { t = *(p + k); *(p + k) = *(q = p + ((k & 1) ? *pc : 0)); *q = t; for (i = 0; i < K; i++) ord[sz][i] = p[i]; sz++; k = 1, pc = c; while (*pc == 0) *pc++ = k++; (*pc)--; } while (k < K); } int main() { int i, j, k, N, a, b, s; N = in(); for (i = 1; i <= N; i++) A[i] = in(); for (j = 1; j <= N; j++) B[j] = in(); genperm(N); s = 0; for (i = 0; i < sz; i++) for (j = 0; j < sz; j++) { a = b = 0; for (k = 0; k < N; k++) { if (A[ord[i][k]] > B[ord[j][k]]) a++; else if (A[ord[i][k]] < B[ord[j][k]]) b++; } if (a > b) s++; } printf("%lf\n", (double)s / (sz*sz)); return 0; }