fn count(ones: &[usize], length: usize) -> usize
Counts the number of ones from the start to the index (inclusive).