Under construction

Still being built. Things may change

Arithmetic Sequence

Interview

Time limit1sMemory limit128 MB

Summary
Given a sequence, decide whether consecutive differences are equal and, if so, print the next five terms in the exact required format.
Level

Easy3 of 10

Topics
Implementation, Math, Array
Solved
No attempts yet

Problem

To pass the time during their long trek through the misty mountains and to prepare for the trials ahead, Gandalf begins teaching mathematics to Bilbo and the thirteen dwarves. One of the ideas he covers is the arithmetic sequence.

A sequence of numbers x1,x2,…,xnx_1, x_2, \ldots, x_n is an arithmetic sequence if the difference between every pair of successive terms is the same, that is:

x2−x1=x3−x2=⋯=xn−xn−1.x_2 - x_1 = x_3 - x_2 = \cdots = x_n - x_{n-1}.

Bilbo and Ori, one of the dwarves, play a game to sharpen their skills. One of them proposes a sequence of numbers, and the other must quickly decide whether it is an arithmetic sequence and, if it is, list the next 5 numbers in the sequence. Write a program that verifies their answers.

Input

The first line contains the number of test cases TT (T<100T < 100).

Each of the following lines describes one test case. The line begins with an integer nn, the number of terms in the sequence, followed by the nn integers that make up the sequence.

Output

For each test case, print exactly one line.

If the sequence is an arithmetic sequence, print it in this form:

The next 5 numbers after [a1, a2, ...] are: [b1, b2, b3, b4, b5]

where the first list repeats the given sequence and the second list contains the next 5 terms.

If the sequence is not an arithmetic sequence, print:

The sequence [a1, a2, ...] is not an arithmetic sequence.

Reproduce the format exactly, including the square brackets, the commas, and the spacing.

Examples1

  1. Example 1

    Input
    3
    3 1 2 3
    5 4 8 12 16 20
    4 1 2 3 5
    
    Expected output
    The next 5 numbers after [1, 2, 3] are: [4, 5, 6, 7, 8]
    The next 5 numbers after [4, 8, 12, 16, 20] are: [24, 28, 32, 36, 40]
    The sequence [1, 2, 3, 5] is not an arithmetic sequence.