luogu#P7887. 「MCOI-06」Existence of Truth

「MCOI-06」Existence of Truth

Problem Description

There may exist a sequence of non-negative integers a1,a2,,ana_1,a_2,\dots,a_n such that 0ai<109+70\le a_i<10^9+7.

Given x1,x2,,xnx_1,x_2,\dots,x_n, y1,y2,,yny_1,y_2,\dots,y_n, and z1,z2,,znz_1,z_2,\dots,z_n, it is known that for 1in1\le i\le n:

$$x_i\left(\sum_{j=1}^ia_j\right)+y_i\left(\sum_{j=i}^na_j\right)\equiv z_i\pmod{10^9+7}$$

Find a1,a2,,ana_1,a_2,\dots,a_n.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, representing the number of test cases. For each test case:

The first line contains a positive integer nn.

The next nn lines each contain three positive integers xi,yi,zix_i,y_i,z_i.

Output Format

For each test case, output in order:

The first line contains a non-negative integer kk, the number of valid solutions.

If k=1k=1, output nn non-negative integers on the second line, in order: a1,a2,,ana_1,a_2,\dots,a_n.

2
3
3 1 9
2 2 16
1 3 15
6
3 6 246
5 7 283
2 7 179
4 6 214
8 7 337
3 5 151
1
1 2 3
1
8 8 0 6 7 8

Hint

Constraints and Notes

This problem uses bundled testdata.

  • Subtask 1 (10 pts): n=1n=1.
  • Subtask 2 (19 pts): n100\sum n\le100.
  • Subtask 3 (19 pts): xi=yi=1x_i=y_i=1.
  • Subtask 4 (22 pts): It is guaranteed that there is a unique solution.
  • Subtask 5 (30 pts): No special restrictions.

For all testdata:

  • 1n,n2×1051\le n,\sum n\le 2\times10^5;
  • 1xi,yi<109+71\le x_i,y_i<10^9+7;
  • 0zi<109+70\le z_i<10^9+7.

Translated by ChatGPT 5