Nested loop works in sorting, support small N