Sum of Arithmetic Sequences
InterviewTime limit3sMemory limit1024 MB
Given sequence A, decide whether it splits into two arithmetic sequences B and C with A_i = B_i + C_i, and print B and C if it does.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Jeonghwi is taking a combinatorics course as a math major and is learning the formula for the sum of an arithmetic sequence. The 2023 SCON contest is one week away, but he has not finished even half of the problems. Pretending to go to the restroom, he ran to the Information Science Building and wrote a problem about arithmetic sequences.
Given a sequence of length , find two arithmetic sequences and of length such that holds for every .
A sequence is an arithmetic sequence if is the same value for every with . By this definition, any sequence of length or less is always an arithmetic sequence.
Input
The first line contains the length of sequence .
The second line contains the elements of sequence in order, separated by spaces.
Output
If there are no two arithmetic sequences and of length that satisfy for every , print NO on the first line.
Otherwise, print YES on the first line. On the second line, print the elements of , and on the third line, print the elements of , each separated by spaces. If several pairs are possible, print any one of them. If such sequences exist, it can be proven that an output satisfying the constraints exists.
Constraints
- , , are all integers