Grammy has a circular array

. You can do the following operations several (possibly, zero) times:
1. Choose two adjacent positions with the same number, and erase them.
2. Choose two adjacent positions such that the numbers on these positions add up to a special number

, and erase them.
After each time you do an operation successfully, Grammy will give you a candy. Meanwhile, the remaining part of the array will be concatenated. For example, after deleting the third and fourth element of the array, the second element and the fifth element will become adjacent.
Find the maximum number of candies you can get.
Two positions

(

) are adjacent if and only if

or

, where

is the length of the remaining array.