The choir conductor is planning a new song for the Brazilian Choir Week show. The song works like this.
- Each singer starts on one assigned note and changes note only when the conductor says so.
- At the end of every measure the conductor tells exactly two singers to change note. One of them moves to the note immediately above the note they were singing, and the other moves to the note immediately below.
- The song ends at the end of the first measure in which every singer sings the same note.
The length of the song is the number of measures that passed before it ended. If every singer already sings the same note at the start, the song ends at the end of the first measure, so its length is 1.
The conductor already has several plans for handing out the starting notes. What she still wants to know is whether a given assignment can end the way she wants, with every singer on the same note, and if it can, the smallest possible number of measures. Help her out.