#K15521. Return to Original Sequence After Exactly k Flips
Return to Original Sequence After Exactly k Flips
Return to Original Sequence After Exactly k Flips
You are given a sequence of n integers and an integer k representing the number of flips. A flip reverses the entire sequence. Your task is to determine whether it is possible to return the sequence to its original order after exactly k flips.
The outcome depends on the parity of k and the structure of the sequence. It can be proven that:
- If k is even, then performing an even number of full-sequence reversals will always return the sequence to the original order.
- If k is odd, then the sequence will be in the reversed order. In order for the reversed sequence to be identical to the original sequence, the sequence must be palindromic. In mathematical terms, a sequence a is palindromic if \(a_i = a_{n+1-i}\) for all \(1 \leq i \leq n\).
You need to implement a program that reads input from stdin and outputs the result to stdout. The answer should be "YES" if it is possible to return the sequence to its original order after exactly k flips, or "NO" otherwise.
Note: n is the length of the sequence, and the entire sequence is given as a list of space-separated integers in one line.
inputFormat
The input consists of two lines:
- The first line contains two integers n (the length of the sequence) and k (the number of flips), separated by a space.
- The second line contains n space-separated integers representing the sequence.
outputFormat
Output a single line containing either "YES" or "NO". Output "YES" if it is possible to return the sequence to its original order after exactly k flips, otherwise output "NO".
## sample5 2
1 2 3 4 5
YES
</p>