Under construction

Still being built. Things may change

Drawing

Interview

Time limit2sMemory limit1024 MB

Summary
Given a chain of segments with fixed lengths anchored at A0, decide whether its end can reach point An, and output every hinge position if so.
Level

Medium5 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Fleeing another hostile creature from a parallel dimension, Gordon Freeman hid in a laboratory where crystals brought from the Xen dimension had once been studied. Once he realized he was in no danger, Freeman looked around and found interesting equipment built for ultra-precise drawing of complex diagrams. However, it was not designed for ordinary drawings, and its construction prevents it from drawing some of them.

On the lab computer, Freeman found blueprints of all rooms of the federal research center. Having them printed would greatly increase his chances of survival. It is not hard to guess what he decided to do!

The drawing device works as follows. An "arm" made of nn metal segments connected in series by hinges is fixed at a point A0A_0 on the drawing plane. Let l1l_1 be the length of the first segment (the one attached to A0A_0), l2l_2 the length of the next, and so on, up to lnl_n for the last one. Denote the hinge point between segments ii and i+1i+1 as AiA_i, and the end of the last segment as AnA_n. A tool that draws a point is attached at AnA_n. The control unit can place the hinge joints at points AiA_i on the drawing plane if ∣AiAi+1∣=li|A_i A_{i+1}| = l_i holds for all i<ni < n.

To draw the diagrams, Freeman needs to find out whether the device can draw all the required points. For each point he also needs the coordinates of every AiA_i. Help him with this.

Input

The first line contains four integers x0x_0, y0y_0, xnx_n, yny_n (−10000≤x0,y0,xn,yn≤10000-10000 \le x_0, y_0, x_n, y_n \le 10000): the coordinates of point A0A_0, where the first segment is attached, and the coordinates of point AnA_n, the point to be drawn.

The second line contains an integer nn (1≤n≤1031 \le n \le 10^3), the number of segments in the device. The third line contains nn integers lil_i (1≤li≤10001 \le l_i \le 1000), the lengths of the segments.

Output

The first line of the output must be YES if the point AnA_n can be drawn, and NO otherwise. If it can be drawn, print the coordinates of AiA_i for all ii from 00 to nn on the next n+1n + 1 lines. The answer is accepted if the distance between your points AiA_i and Ai+1A_{i+1} differs from lil_i by no more than 10−310^{-3}.

Examples1

  1. Example 1

    Input
    0 0 6 0
    2
    5 5
    
    Expected output
    YES
    0.000 0.000
    3.000 4.000
    6.000 0.000