#TP0000010. Dãy Kalindrome (Kalindrome Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy Kalindrome (Kalindrome Array)
Kalindrome Array
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An integer array is a palindrome if its elements read the same forward and backward; an empty array is also a palindrome. An array is a kalindrome if it is possible to choose one integer value and remove any number of elements equal to so that the remaining array becomes a palindrome.
Deleting zero occurrences is allowed, and deleting all occurrences is not required. Elements different from the chosen value cannot be deleted. Determine whether the given array of length is a kalindrome.
Input
- The first line contains an integer , the number of elements.
- The second line contains exactly integers .
Output
Print YES if choosing one value and deleting only its occurrences can produce a palindrome; otherwise print NO. Letter case is not significant.
Subtasks
- Subtask 1 (20 points): ; for every ; values may repeat.
- Subtask 2 (30 points): ; for every ; values may repeat.
- Subtask 3 (50 points): ; for every ; values may repeat.
Examples
Input
5
1 4 4 1 4
Output
YES
Explanation
Choose value 4 and delete its last occurrence. The resulting array 1,4,4,1 is a palindrome.