P16331 After All ~綴る想い~

Background

![](https://cdn.luogu.com.cn/upload/image_hosting/jd8st2ou.png) 「先从我眼前消失的是你吧!?擅自跑到我无法触及的地方去的人是你吧!」 「明明让我难以企及……却还要我一直待在你的身边…想出这种酷刑的人也是你吧…」 「明明是这样,为什么我还非得被你责备不可啊…?」 「像那样…每天、每天,在我的眼前,着我的心!…还说这全都是我的错…太残忍了啊…」 ...... 「北原和我,就在刚才,终于成为朋友了啊」 「把想说的话,全都说出来了呢。终于变成了,知根知底的关系了呢」 「只是,在成为朋友的瞬间,就绝交了」 「别追哦…这次你不要追我哦?以后,不要再出现在我面前了哦?」 所以,我… 一步、又一步地,拉近与她之间的距离。将冬马,逼得走投无路。被我吸引了注意力的冬马被护栏挡住,再也无法后退。 我终于,用自己的手,抓住了冬马。我抓住她的肩膀,让她正面对着我,发现她那红肿的眼晴,以及湿润的脸颊酝酿出了和平时的冬马完全不一样的感觉。 即使是这样一幅惨状,冬马也依然十分美丽,这份无可动摇的事实已经在我心中根深蒂固了… 那个瞬间… 存在于我心中的女孩,这个世界上仅此一人。

Description

You are given a cycle of length $n$. Initially, each position has value $0$, and the positions are numbered from $1$ to $n$. You are also given two sequences $a_i$ and $b_i$, both of length $n$. You may perform the following operation any number of times: - Choose a point $i$, and add or subtract $b_i$ to the consecutive segment of length $i$ starting from position $i$ and going forward along the cycle. Determine whether there exists a sequence of operations such that the value at every position on the cycle is **exactly** equal to $a_i$. If so, construct one. For each position, output the number of times you add $b_i$ minus the number of times you subtract $b_i$. It is guaranteed that $\operatorname{lcm}(b_i)\le 10^9$. If for some test case you can only determine whether a solution exists but cannot construct one, you may still obtain partial score for that test case. See **Scoring** for details.

Input Format

The first line contains a positive integer $T$, the number of test cases. For each test case: - The first line contains a positive integer $n$, the length of the cycle. - The second line contains $n$ integers $a_i$, the target values. - The third line contains $n$ positive integers $b_i$.

Output Format

For each test case: - Output `YES` or `NO` on the first line, indicating your verdict. - If a solution exists, output $n$ integers on the second line, representing your construction. You must ensure that every integer lies between $-10^{32}$ and $10^{32}$.

Explanation/Hint

**Constraints** For all test cases, $1\le n,T,\sum n\le 10^6$, $0\le |a_i|\le 10^9$, $1\le b_i,\operatorname{lcm}(b_i)\le 10^9$. | Subtask | $n\le$ | Special Property | Score | | :-----: | :----: | :--------------: | :---: | | $1$ | $5$ | A | $10$ | | $2$ | $10^6$ | B | $10$ | | $3$ | $10^6$ | C | $20$ | | $4$ | $10^6$ | D | $20$ | | $5$ | $10^6$ | None | $40$ | - Special Property A: It is guaranteed that $T\le 10$, and if a solution exists, then there is always one where the number of additions or subtractions for every $b_i$ does not exceed $5$. - Special Property B: It is guaranteed that there exists a nonnegative integer $k$ such that $n=2^k$. - Special Property C: It is guaranteed that all $a_i$ are equal. - Special Property D: It is guaranteed that $2\nmid n$. **Scoring** - If you correctly determine the existence of a solution for all test cases, you can obtain $40%$ of the score for that test point. Note that if you can only determine existence, then for the test cases where a solution exists, you should still output a second line consisting of $n$ integers within the required range. - If you correctly determine the existence of a solution for all test cases, and for every test case with a solution you also construct a valid one, you can obtain $60%$ of the score for that test point.