private int countNotes(int[] notes, int offset, int length) { int count = 0; for (int i = 0; i < notes.Length; i += 3) { if (notes[i] > offset + length) break; else if (notes[i] >= offset) count++; } return count; }