This page is still under construction.

Parts of this page are still being built. What you see may change.

Billiards

Time limit1sMemory limit128 MB

Summary
A ball starts 13 from side R and 29 from side D and moves straight from a cue point on R, reflecting off the sides; find its distances from R and D after n centimeters.
Level

Medium6 of 10

Topics
Math, Geometry, Simulation, Implementation
Solved
No attempts yet

Problem

A rectangular billiard table measures 47×7347 \times 73 centimeters. Its four sides are labeled AA, RR, ZZ, DD; sides RR and DD are the two sides that meet at a corner, so they are perpendicular to each other. A small ball BB, whose size may be ignored, rests inside the table exactly 1313 centimeters from side RR and 2929 centimeters from side DD (see Pic. 3).

A player rests the cue on side RR at the point that is kk centimeters from side DD and strikes ball BB head-on. The ball then travels in a straight line, starting at BB and heading directly away from the point where the cue touched side RR. Whenever the ball reaches a side of the table it bounces off; the bounce is a perfect reflection, leaving and arriving at equal angles to the line perpendicular to that side. The first part of the ball's path is shown in Pic. 4.

Write a program that, given the integers kk (0≤k≤730 \le k \le 73) and nn (0≤n<1090 \le n < 10^9), reports the ball's distance from side RR (denoted BRBR) and from side DD (denoted BDBD) after it has travelled exactly nn centimeters. Output BRBR and BDBD as real numbers, each rounded to the nearest thousandth of a centimeter.

Pic. 3

Pic. 4

Input

A single line containing two integers kk and nn (0≤k≤730 \le k \le 73, 0≤n<1090 \le n < 10^9).

Output

Print BRBR and BDBD on one line, separated by a single space, each rounded to exactly three decimal places.

Examples2

  1. Example 1

    Input
    29 100
    
    Expected output
    19.000 29.000
    
  2. Example 2

    Input
    16 20
    
    Expected output
    27.142 43.142