5.2 Dr. Pratham’s Space Endeavours
Dr. Pratham runs a small aeronautics lab where he invented a powerful device called the Aether Compass. This Aether Compass is no ordinary instrument - it precisely locates positions in three-dimensional space and orchestrates the scout drone's sequence of exact vector hops. Each hop must be exactly a given length, but the drone may point in any direction in 3D space when it takes that hop.
One evening, a jealous rival professor, Devansh, challenges Pratham. Devansh places two beacons in the air, a launch beacon at point P=(px,py,pz) and a target beacon at point Q=(qx,qy,qz). Pratham must program the Aether Compass to instruct the drone to start at P and perform exactly n hops. For the i-th hop the drone must fly exactly ai units in 3D (in any direction), landing at the next position. After all n hops, the drone should arrive exactly at Q.
Can Pratham devise a sequence of directions so the drone, using the given hop lengths in order, reaches the target beacon?
Constraints
For each test case print "Yes" if it is possible for the drone to end at Q after exactly n moves, otherwise print "No"
Input Format
The first line contains a single integer t - the number of test cases
Each test case contains three lines:
The first line contains an integer n (the number of hops).
The second line contains six integers px, py, pz, qx, qy, qz - launch beacon coordinates (px, py, pz) and the target beacon coordinates (qx, qy, qz)
The 3rd line contains n integers a1 a2 … an - the hop lengths
Output Format
1 ≤ t ≤ 10^4
0 ≤ px, py, pz, qx, qy, qz ≤ 10^7
1 ≤ ai ≤ 10^4
It is guaranteed that the sum of n over all test cases does not exceed 2⋅10^5
Example 1
Input:
5
2
1 1 0 5 1 0
3 3
3
1 1 1 3 3 3
2 3 4
2
100 100 100 100 100 100
4 5
1
5 1 1 1 4 2
5
2
10000000 10000000 10000000 10000000 10000000 10000000
10000 10000
Output:
Yes
Yes
No
No
Yes
Explanation:
Self explanatory
Log In to solve the Question