qs k xs = if ll == k then pivot else if ll > k then qs k ls else qs (k - ll - 1) (tail rs)
    where
        pivot = head xs
        (ls, rs) = partition (< pivot) xs
        ll = length ls
qs k xs = if ll == k then pivot else if ll > k then qs k ls else qs (k - ll - 1) (tail rs)
    where
        pivot = head xs
        (ls, rs) = partition (< pivot) xs
        ll = length ls
qs k xs = if ll == k then pivot else if ll > k then qs k ls else qs (k - ll - 1) (tail rs)
    where
        pivot = head xs
        (ls, rs) = partition (< pivot) xs
        ll = length ls