beads[i] is 0 or 1. Bead n - 1 sits next to bead 0.
Call a stretch of length consecutive beads (going round the ring) striped if every two neighbouring beads in it have different colours. Count the striped stretches of length length. Stretches that start at different beads count as different.beads=[1, 0, 1, 1, 0, 1], length=3 → 2
Only the stretches starting at positions 0 and 3 (both 1, 0, 1) alternate; every other stretch of three has two equal neighbours.
beads=[0, 1, 0, 1], length=4 → 4
The beads alternate all the way round, including across the seam between the last and first bead, so a stretch from each of the 4 positions works.
beads=[1, 1, 1], length=3 → 0
beads[i] is 0 or 1beads=[1, 0, 1, 1, 0, 1], length=3
2
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.