Under construction

Still being built. Things may change

Sum of Arithmetic Sequences

Interview

Time limit3sMemory limit1024 MB

Summary
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 AA of length NN, find two arithmetic sequences BB and CC of length NN such that Ai=Bi+CiA_i=B_i+C_i holds for every 1≤i≤N1\le i\le N.

A sequence A={A1,A2,⋯ ,AN}A=\{ A_1,A_2,\cdots ,A_N \} is an arithmetic sequence if Ai−Ai−1A_i-A_{i-1} is the same value for every ii with 2≤i≤N2\leq i\leq N. By this definition, any sequence of length 22 or less is always an arithmetic sequence.

Input

The first line contains the length NN of sequence AA.

The second line contains the elements A1,A2,⋯ ,ANA_1,A_2,\cdots ,A_N of sequence AA in order, separated by spaces.

Output

If there are no two arithmetic sequences BB and CC of length NN that satisfy Ai=Bi+CiA_i=B_i+C_i for every 1≤i≤N1\leq i\leq N, print NO on the first line.

Otherwise, print YES on the first line. On the second line, print the elements of BB, and on the third line, print the elements of CC, each separated by spaces. If several pairs B,CB,C are possible, print any one of them. If such sequences exist, it can be proven that an output satisfying the constraints exists.

Constraints

  • 1≤N≤1051\leq N\leq 10^5
  • −109≤Ai≤109-10^9\leq A_i\leq 10^9 (1≤i≤N)(1\le i\le N)
  • −1018≤Bi,Ci≤1018-10^{18}\leq B_i,C_i\leq 10^{18} (1≤i≤N)(1\le i\le N)
  • AiA_i, BiB_i, CiC_i are all integers (1≤i≤N)(1\le i\le N)

Examples3

  1. Example 1

    Input
    4
    1 2 3 4
    
    Expected output
    YES
    2 4 6 8
    -1 -2 -3 -4
    
  2. Example 2

    Input
    3
    1 2 1
    
    Expected output
    NO
    
  3. Example 3

    Input
    1
    0
    
    Expected output
    YES
    -3
    3