DMOPC '18 Contest 5 P0 - A Digital Art Problem

The Multiply, Screen, and Overlay blend modes in image manipulation programs such as Photoshop are very useful when making digital art. If you apply one of these modes to a base colour and a top colour, a resulting colour is produced. Colours have three components: ~R~, ~G~, and ~B~, which can have any real value from ~0~ to ~1~ (completely dark to completely light) inclusive, and modes operate on each component separately. Let's call a component of the base colour ~X_a~ and the same component of the top colour ~X_b~.

If you apply the Multiply mode, the resulting component will be ~X_aX_b~. As this produces a darker colour, it is good for drawing shadows.

If you apply the Screen mode, the resulting component will be ~1 - (1 - X_a)(1 - X_b)~. As this produces a lighter colour, it is good for drawing highlights.

The Overlay mode produces different results depending on the base component. If this component is less than ~0.5~, the resulting value is ~2X_aX_b~. Otherwise, the resulting value is ~1 - 2(1 - X_a)(1 - X_b)~. As this makes dark colours darker and light colours lighter, it is good for adding contrast.

Given a blend mode and each component of the base and top colours, please find the resulting colour.

Input Specification

The first line will contain one of the following strings: Multiply, Screen, or Overlay, the blend mode.
The second line will contain 3 space-separated real numbers: ~R_a~, ~G_a~, and ~B_a~ representing each component of the base colour.
The third and final line will contain 3 space-separated real numbers: ~R_b~, ~G_b~, and ~B_b~ representing each component of the top colour.

Output Specification

Output 3 space-separated real numbers on one line: the ~R~, ~G~, and ~B~ of the resulting colour.
Your answer will be judged correct if it has an absolute or relative error less than or equal to ~10^{-6}~.