almost sorted (N^2)