Bowing to Parents
Time limit2sMemory limit1024 MB
Given N shuffled integers, decide whether they can be rearranged into a sequence that decreases by a constant step and then increases by a constant step.
- Level
Medium6 of 10
- Topics
- Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
Wookje bowed deeply to his parents before leaving for military training. When he was young, his parents used to tell him:
"Wookje, remember this. Agent's bow must be artistic."
Today, however, his parents were very disappointed in him, because they did not think his bow was artistic. A bow is artistic when the following conditions hold.
- The bow is represented by a sequence of integers of length .
- The sequence must first decrease by a constant amount and then increase by a constant amount. That is, there is an index with such that is an arithmetic sequence with common difference , and is an arithmetic sequence with common difference .
You must judge whether the sequence representing Wookje's bow is artistic.
Alas! The soccer player Messi shuffled the sequence. Given the shuffled sequence in no particular order, determine whether the original bow could have been artistic.
Input
The first line contains the length of the sequence.
The second line contains the sequence representing Wookje's bow, shuffled into arbitrary order, with the numbers separated by spaces.
Output
If the sequence can be rearranged into a sequence representing an artistic bow, print Yes. Otherwise, print No.