Bessie has big hands and finds a small touchscreen awkward, yet she still likes playing games on her phone.
One game has her attention right now. It starts with N integers between 1 and 40 (2≤N≤248). Bessie may replace two adjacent numbers of equal value with a single number that is 1 larger. For example, two adjacent 7s become one 8. The game ends once no adjacent pair of equal numbers is left. The goal is to make the largest number remaining in the sequence at that moment as large as possible. Find the highest score Bessie can reach.