fun readInt () = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn) fun quicksortNoDuplicate [] = [] | quicksortNoDuplicate (h::tl) = let val (s, b) = List.foldl (fn (x, (small, big)) => if x = h then (small, big) else if x < h then (x::small, big) else (small, x::big)) ([], []) tl in (quicksortNoDuplicate s) @ [h] @ (quicksortNoDuplicate b) end fun findAns l = let fun findAnsLoop [] min = min | findAnsLoop [_] min = min | findAnsLoop (h1 :: h2 :: tl) min = if h1 = h2 then findAnsLoop (h2 :: tl) min else if h2 - h1 < min then findAnsLoop (h2 :: tl) (h2 - h1) else findAnsLoop (h2 :: tl) min val limit = 9999999 val ans = findAnsLoop (quicksortNoDuplicate l) limit in if ans = limit then 0 else ans end val () = let val n = readInt () val x_s = List.tabulate (n, fn _ => readInt ()) val ans = findAns x_s in print (Int.toString ans ^ "\n") end