CF BUDDY
← Problems·

1166D · Cute Sequences

2200 · binary search, brute force, greedy

Problem: Given a positive integer mm, we say that a sequence x1,x2,,xnx_1, x_2, \dots, x_n of positive integers is mm-cute if for every index ii such that 2in2 \le i \le n it holds that xi=xi1+xi2++x1+rix_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i for some positive integer rir_i satisfying 1rim1 \le r_i \le m.

You will be given qq queries consisting of three positive integers aa, bb and mm. For each query you must determine whether or not there exists an mm-cute sequence whose first term is aa and whose last term is bb. If such a sequence exists, you must additionally find an example of it.

Input Format: The first line contains an integer number qq (1q1031 \le q \le 10^3) — the number of queries.

Each of the following qq lines contains three integers aa, bb, and mm (1a,b,m10141 \le a, b, m \le 10^{14}, aba \leq b), describing a single query.

Output Format: For each query, if no mm-cute sequence whose first term is aa and whose last term is bb exists, print 1-1.

Otherwise print an integer kk (1k501 \le k \leq 50), followed by kk integers x1,x2,,xkx_1, x_2, \dots, x_k (1xi10141 \le x_i \le 10^{14}). These integers must satisfy x1=ax_1 = a, xk=bx_k = b, and that the sequence x1,x2,,xkx_1, x_2, \dots, x_k is mm-cute.

It can be shown that under the problem constraints, for each query either no mm-cute sequence exists, or there exists one with at most 5050 terms.

If there are multiple possible sequences, you may print any of them.

Note: Consider the sample. In the first query, the sequence 5,6,13,265, 6, 13, 26 is valid since 6=5+16 = 5 + \bf{\color{blue} 1}, 13=6+5+213 = 6 + 5 + {\bf\color{blue} 2} and 26=13+6+5+226 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 11 and 22, so the sequence is 22-cute. Other valid sequences, such as 5,7,13,265, 7, 13, 26 are also accepted.

In the second query, the only possible 11-cute sequence starting at 33 is 3,4,8,16,3, 4, 8, 16, \dots, which does not contain 99.

Sample Cases

Case 1

Input

2
5 26 2
3 9 1

Output

4 5 6 13 26
-1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback