#B4227. Palindromic Deletion Game
Palindromic Deletion Game
Palindromic Deletion Game
In this game, two players, Y and H, take turns deleting one number from a sequence of 2n positive integers. The game starts with player Y and continues alternately until exactly 2 numbers remain. The twist is that player H wins if, after any move by H, the remaining sequence becomes a palindrome, or if the initial sequence is already a palindrome. Otherwise, player Y wins.
A palindrome sequence is one that reads the same forward and backward. For example, \(\{17,23,23,17\}\) is a palindrome sequence, while \(\{1,2,1,2\}\) is not.
Both players are extremely smart, meaning that on every turn they choose an optimal move with respect to their winning objective. Player Y wants to know whether he can force a win.
Your task is: given the initial sequence, determine if player Y has a winning strategy.
Note: Even if a move by player Y results in a palindromic sequence, it does not count as a win for H. H wins only if after one of his moves (or if the sequence is initially a palindrome) the sequence is palindromic.
inputFormat
The first line contains a single integer n (n ≥ 1). The next line contains \(2n\) positive integers, representing the sequence.
It is guaranteed that the sequence has a length of exactly \(2n\).
outputFormat
Output a single line containing YES
if player Y can force a win, or NO
otherwise.
sample
2
1 2 3 4
NO