#P8925. Infinite Corridor Reflections

    ID: 22089 Type: Default 1000ms 256MiB

Infinite Corridor Reflections

Infinite Corridor Reflections

Consider an infinitely long corridor represented as a coordinate line. A lamp is located at the origin \(O\). Two mirrors are placed at positions \(-L\) and \(R\) respectively, forming an infinite mirror corridor. Theoretically, these two mirrors produce infinitely many images of the lamp.

Your task is to calculate the coordinate of the \(x\)-th image on a specified side of the lamp.

The images are formed as follows:

  • If the specified side is Right (denoted by the character R), the coordinate of the \(x\)-th image is given by: \(2R + 2(R+L)(x-1)\).
  • If the specified side is Left (denoted by the character L), the coordinate of the \(x\)-th image is given by: \(-2L - 2(R+L)(x-1)\).

Please note that \(L\), \(R\), and \(x\) are positive integers, and the side is provided as a single character either L or R.

inputFormat

The input consists of a single line containing three integers and a character separated by spaces: \(L\) \(R\) \(x\) \(d\).

  • \(L\): a positive integer representing the absolute distance from the origin to the left mirror (located at \(-L\)).
  • \(R\): a positive integer representing the distance from the origin to the right mirror (located at \(R\)).
  • \(x\): a positive integer indicating which image to consider on the specified side.
  • \(d\): a character ('L' or 'R') specifying whether to consider the left side or the right side.

outputFormat

Output a single integer representing the coordinate of the \(x\)-th image on the specified side.

sample

1 2 1 R
4