import Data.List
main = interact $ show . minimum . map (snd . foldl (\(x', y) x -> (x, y + abs (x - x'))) (0, 0)) .
                  map (take 3) . filter ((>= 3) . length) . tails . sort . map read . words . head .
                  tail . lines
