Trick Shot

Decide whether one cue shot from a fixed line can chain three collisions to sink two balls in opposite corner holes.

Medium7GeometryMathNo attempts yetTime limit1sMemory limit256 MB

Problem

You are building a billiards puzzle game. The player places the cue ball at one exact spot, shoots it at one exact angle, and sinks several balls with that single shot.

The collision rule in this game is not real physics. Let ball BB be moving and ball AA be at rest. At the moment they touch, let nn be the unit vector from the center of BB to the center of AA, and let vv be the unit vector of BB's direction of travel. Ball AA starts moving along nn, and ball BB keeps moving along v2(vn)nv - 2(v \cdot n)n. Only AA's direction matches real physics. Ball BB bounces the way it would if AA were glued to the table. The speed of a ball does not matter in this problem.

Figure 1

The table is a rectangle of width ww and length ll. With the bottom left corner at the origin, the left hole is at (0,l)(0, l) and the right hole is at (w,l)(w, l). Sinking a ball requires the center of the ball to pass directly over the center of the hole. The table has no cushions, so a ball that leaves the w×lw \times l region simply falls off. You do not have to consider collisions with the table itself.

Figure 2

Balls 1, 2 and 3 sit on the table. The player places the cue ball on the dashed line that lies hh units above the bottom edge of the table, picks a distance dd from the left edge and an angle θ\theta, and shoots. Both of these must happen.

  • The cue ball strikes ball 1, ricochets into ball 2, and sinks ball 2 in the left hole.
  • Ball 1, struck by the cue ball, hits ball 3 and sinks ball 3 in the right hole.

All three collisions must be real. At the moment a moving ball touches a ball at rest, its direction vv and the direction nn between the two centers satisfy vn>0v \cdot n > 0.

Given ww, ll, hh, the positions of the three balls and the radius rr, decide whether this shot is possible. At most one pair (d,θ)(d, \theta) satisfies the conditions. In every input where such a shot exists, no two balls touch other than in the three collisions listed above.

Input

The first line contains the width ww and the length ll of the table (1w1201 \le w \le 120, 1l1201 \le l \le 120).

The second line contains eight positive integers rr, x1x_1, y1y_1, x2x_2, y2y_2, x3x_3, y3y_3, hh. Here rr is the radius of every ball including the cue ball (r5r \le 5), (xi,yi)(x_i, y_i) is the center of ball ii, and hh is the distance from the dashed line to the bottom edge of the table (rhl/2r \le h \le l/2).

No two balls overlap, although they may touch at a point. All three balls lie between the dashed line and the top edge of the table, and each of them lies completely on the table.

Output

If the shot is possible, print on one line the distance dd at which to place the cue ball on the dashed line and the angle θ\theta at which to shoot it, separated by a space. Report θ\theta in degrees, measured counterclockwise from the positive xx direction, with 0θ<3600 \le \theta < 360. Round both values to the nearest hundredth and always print two digits after the decimal point, even when those digits are zero.

The cue ball must also lie completely on the table, so rdwrr \le d \le w - r is required. If no dd and θ\theta meet every condition, print impossible.