Is it an arithmetico-geometric sequence? An arithmetico-geometric sequence is the elementwise product of an arithmetic sequence and a geometric sequence. For example, 1 -4 12 -32 is the product of the arithmetic sequence 1 2 3 4 and the geometric sequence 1 -2 4 -8. The nth term of an integer arithmetico-geometric sequence can be expressed as

$$a_n = r^n \cdot (a_0 + nd)$$

for some real number \$d\$, nonzero real \$r\$, and integer \$a_0\$. Note that \$r\$ and \$d\$ are not necessarily integers.

For example, the sequence 2 11 36 100 256 624 1472 3392 has \$a_0 = 2\$, \$r = 2\$, and \$d = 3.5\$.

Input

An ordered list of \$n \ge 2\$ integers as input in any reasonable format. Since some definitions of geometric sequence allow \$r=0\$ and define \$0^0 = 1\$, whether an input is an arithmetico-geometric sequence will not depend on whether \$r\$ is allowed to be 0. For example, 123 0 0 0 0 will not occur as input.

Output

Whether it is an arithmetico-geometric sequence. Output a truthy/falsy value, or two different consistent values.

Test cases

True:

1 -4 12 -32
0 0 0
-192 0 432 -1296 2916 -5832 10935 -19683
2 11 36 100 256 624 1472 3392
-4374 729 972 567 270 117 48 19
24601 1337 42
0 -2718
-1 -1 0 4 16
2 4 8 16 32 64
2 3 4 5 6 7
0 2 8 24


False:

4 8 15 16 23 42
3 1 4 1
24601 42 1337
0 0 0 1
0 0 1 0 0
1 -1 0 4 16
Wolfram Language (Mathematica), 55 bytes

{}!=Solve[i=Range@Tr[1^#];(a+i*d)r^i==#,{r,a,d},Reals]&amp;


Try it online!

Solve return all solution forms. The result is compared with {} to check if there is any solution.