#P2552. Determine the Athlete's Position in the Formation

    ID: 15822 Type: Default 1000ms 256MiB

Determine the Athlete's Position in the Formation

Determine the Athlete's Position in the Formation

There are (n) athletes numbered from (1) to (n). They are arranged in one of two formation types: the continuous formation and the plum formation (梅花桩队形). Furthermore, the arrangement can be done by rows or by columns. When arranged by rows, each row has exactly (r) positions; when arranged by columns, each column has exactly (r) positions.

In the continuous formation the athletes are filled sequentially:

  • Row arrangement: fill the formation row by row (left to right).
  • Column arrangement: fill the formation column by column (top to bottom).
In the plum formation, the positions that can be used in each row (or column) depend on the parity of the row (or column):
  • For row arrangement: In odd-numbered rows the athletes are placed in the odd-numbered columns (i.e. columns \(1,3,5,\dots\)) while in even-numbered rows they are placed in the even-numbered columns (i.e. columns \(2,4,6,\dots\)). The number of available positions in an odd row is \(\lceil r/2 \rceil\) and in an even row is \(\lfloor r/2 \rfloor\).
  • For column arrangement: In odd-numbered columns the athletes are placed in the odd-numbered rows and in even-numbered columns they are placed in the even-numbered rows. The number of available positions in an odd column is \(\lceil r/2 \rceil\) and in an even column is \(\lfloor r/2 \rfloor\).
The input includes two parts. The first line consists of two tokens:
  1. An integer indicating the formation type: 1 for continuous formation and 2 for plum formation.
  2. A character indicating the arrangement order: R if arranged by rows and C if arranged by columns.
The second line contains three integers \(n\), \(r\) and \(m\) where \(m\) is the athlete's number. Your task is to compute the row and column where athlete \(m\) is positioned. All positions and indices start from 1.

inputFormat

The input consists of two lines:

The first line contains two tokens separated by space:

  • An integer (1 for continuous formation, 2 for plum formation).
  • A character (R for row arrangement, C for column arrangement).

The second line contains three space-separated integers:

  • (n): total number of athletes.
  • (r): number of positions in each row (or column).
  • (m): the athlete number whose position is to be determined. It is guaranteed that (1 \le m \le n).

outputFormat

Output two integers separated by a space: the row number and the column number where athlete (m) is located.

sample

1 R
16 6 16
3 4