Alphonse has N riceballs of various sizes lined up in a row. He wants to make the largest riceball he can for his friend. Alphonse can use the following two operations.
- If two riceballs of the same size are next to each other, he can combine those two into one new riceball. The new riceball's size is the sum of the two sizes, and it takes the place the two old riceballs occupied.
- If two riceballs of the same size have exactly one riceball between them, he can combine all three into one new riceball. The middle riceball does not have to match the other two in size. The new riceball's size is the sum of the three sizes, and it takes the place the three old riceballs occupied.
He can use each operation as many times as he wants.
Find the size of the largest riceball left in the row after 0 or more operations.