se acc)
        go (x:xs) b acc = let acc' = (b ! n \\ b ! x) : acc
                              b' = inc' x [x] b
                          in go xs b' acc'

{- | 転倒対象インデックスリスト
1-9 までの数だけでできたリストの転倒している対象要素をインデックス指定でリストアップ.

>>> inverse9'i [4,1,5,2,6,3]
[(4,[]),(1,[0]),(5,[]),(2,[0,2]),(6,[]),(3,[0,2,4])]
-}
inverse9'i :: [Int] -> [(Int, [Int])]
inverse9'i xs = go (zip [0..] xs) b []
  where n = maximum xs
        b = new n :: BIT [Int]
        go []             b acc = zip xs (reverse acc)
        go (ix@(i, x):xs) b acc = let acc' = (b ! n \\ b ! x) : acc
       
inverse9' :: [Int] -> [(Int, [Int])]
inverse9' xs = go xs b []
  where n = maximum xs
        b = new n :: BIT [Int]
        go []     b acc = zip xs (reverse acc)
        go (x:xs) b acc = let acc' = (b ! n \\ b ! x) : acc
                              b' = inc' x [x] b
                          in go xs b' acc'

{- | 転倒対象インデックスリスト
1-9 までの数だけでできたリストの転倒している対象要素をインデックス指定でリストアップ.

>>> inverse9'i [4,1,5,2,6,3]
[(4,[]),(1,[0]),(5,[]),(2,[0,2]),(6,[]),(3,[0,2,4])]
-}
inverse9' xs = go xs b []
  where n = maximum xs
        b = new n :: BIT [Int]
        go []     b acc = zip xs (reverse acc)
        go (x:xs) b acc = let acc' = (b ! n \\ b ! x) : acc
                              b' = inc' x [x] b
                          in go xs b' acc'

{- | 転倒対象インデックスリスト
1-9 までの数だけでできたリストの転倒している対象要素をインデックス指定でリストアップ.

>>> inverse9'i [4,1,5,2,6,3]
[(4,[]),(1,[0]),(5,[]),(2,[0,2]),(6,[]),(3,[0,2,4])]
-}