package main import ( "bufio" "fmt" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := make([]int, n) bb := make([]int, n) for i := 0; i < n; i++ { aa[i] = getNextInt(scanner) } for i := 0; i < n; i++ { bb[i] = getNextInt(scanner) } p := 1 for i := 0; i < n; i++ { p *= i + 1 } pm := newPermutation(n) var ans int for i := 0; i < p; i++ { a := pm.get(i) for j := 0; j < p; j++ { w := 0 b := pm.get(j) for k := 0; k < n; k++ { if aa[a[k]-1] > bb[b[k]-1] { w++ } } if w > n-w { ans++ } } } one := float64(ans) / float64(p*p) fmt.Fprintln(writer, one) } type permutation []int func newPermutation(n int) permutation { p := make(permutation, n) p[0] = 1 for i := 1; i < n; i++ { p[i] = p[i-1] * i } return p } func (p permutation) index(a []int) int { n := len(p) ans := 0 used := make([]bool, n) for i := 0; i < n; i++ { sum := 0 used[a[i]-1] = true for j := a[i] - 1; j >= 0; j-- { if used[j] { continue } sum++ } ans += sum * p[n-1-i] } return ans } func (p permutation) get(index int) []int { n := len(p) ans := make([]int, n) used := make([]bool, n) for i := 0; i < n; i++ { ans[i] = index / p[n-1-i] index %= p[n-1-i] } for i := 0; i < n; i++ { for j := 0; j < n; j++ { if used[j] { continue } if ans[i] == 0 { ans[i] = j + 1 used[j] = true break } ans[i]-- } } return ans }